diff options
-rw-r--r-- | CMakeLists.txt | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c4cdfc..f04ac1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,22 @@ else() message(FATAL_ERROR "LLVM not found; it is derived from MLIR_INSTALL_PREFIX which has value of ${MLIR_INSTALL_PREFIX}") endif() +function(whole_archive_link target) + if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") + set(link_flags "-L${CMAKE_BINARY_DIR}/lib ") + FOREACH(LIB ${ARGN}) + string(CONCAT link_flags ${link_flags} "-Wl,-force_load ${CMAKE_BINARY_DIR}/lib/lib${LIB}.a ") + ENDFOREACH(LIB) + else() + set(link_flags "-L${CMAKE_BINARY_DIR}/lib -Wl,--whole-archive,") + FOREACH(LIB ${ARGN}) + string(CONCAT link_flags ${link_flags} "-l${LIB},") + ENDFOREACH(LIB) + string(CONCAT link_flags ${link_flags} "--no-whole-archive") + endif() + set_target_properties(${target} PROPERTIES LINK_FLAGS ${link_flags}) +endfunction(whole_archive_link) + llvm_map_components_to_libnames(llvm_libs support) if (NOT ${LLVM_ENABLE_RTTI}) @@ -36,7 +52,6 @@ add_executable(toyc mlir/ToyCombine.cpp ) -SET(WHOLE_ARCHIEVE -Wl,--whole-archive MLIRStandardOps MLIRAffineOps -Wl,--no-whole-archive) target_link_libraries(toyc PRIVATE ${llvm_libs} @@ -44,7 +59,6 @@ target_link_libraries(toyc Linalg3 Linalg2 Linalg1 - ${WHOLE_ARCHIEVE} MLIRAnalysis MLIREDSC MLIRExecutionEngine @@ -56,3 +70,5 @@ target_link_libraries(toyc MLIRTransforms MLIRSupport ) + +whole_archive_link(toyc MLIRStandardOps MLIRAffineOps) |