1313# - All the object files of the libraries registered via register_cudaq_mlir_lib
1414# - All the MLIR libraries listed in mlir-libs-allowlist.txt
1515#
16- # We mark the MLIR libraries as WHOLE_ARCHIVE dependencies so their full symbol set is
16+ # MLIR libraries are linked as WHOLE_ARCHIVE so their full symbol set is
1717# exported for downstream plugins.
1818################################################################################
1919
@@ -57,10 +57,13 @@ add_library(${LIBRARY_NAME} SHARED ${_cudaq_bundle_objs})
5757# 2. Pull in the dependencies
5858target_link_libraries (${LIBRARY_NAME} PRIVATE ${_cudaq_bundle_libs} )
5959
60- # 3. WHOLE_ARCHIVE the allowlisted MLIR libraries so their full symbol set is
61- # exported for downstream plugins.
60+ # 3. WHOLE_ARCHIVE the allowlisted MLIR libraries and C-API dependencies so their
61+ # full symbol set is exported for downstream plugins.
6262cudaq_read_symbol_list (
6363 "${CMAKE_CURRENT_SOURCE_DIR } /mlir-libs-allowlist.txt" _cudaq_mlir_whole_archive )
64+ get_property (_cudaq_required_mlir_libs GLOBAL PROPERTY CUDAQ_MLIR_REQUIRED_LIBS)
65+ list (APPEND _cudaq_mlir_whole_archive ${_cudaq_required_mlir_libs} )
66+ list (REMOVE_DUPLICATES _cudaq_mlir_whole_archive)
6467foreach (_lib IN LISTS _cudaq_mlir_whole_archive)
6568 if (TARGET ${_lib} )
6669 target_link_libraries (${LIBRARY_NAME} PRIVATE "$<LINK_LIBRARY :WHOLE_ARCHIVE ,${_lib} >" )
@@ -70,31 +73,13 @@ foreach(_lib IN LISTS _cudaq_mlir_whole_archive)
7073 endif ()
7174endforeach ()
7275
73- # 4. Hide all symbols from the blocklist.
74- cudaq_read_symbol_list (
75- "${CMAKE_CURRENT_SOURCE_DIR } /mlir-symbols-blocklist.txt" _cudaq_blocklist_patterns )
76- if (APPLE )
77- # ld64: one glob per line; localize via -unexported_symbols_list.
78- set (_cudaq_symbol_list "${CMAKE_CURRENT_BINARY_DIR } /cudaqMLIR-unexported.txt" )
79- # relink if the symbol list changes
80- set_property (TARGET ${LIBRARY_NAME} APPEND PROPERTY LINK_DEPENDS "${_cudaq_symbol_list} " )
81- string (REPLACE ";" "\n " _cudaq_unexported "${_cudaq_blocklist_patterns} " )
82- file (WRITE "${_cudaq_symbol_list} " "${_cudaq_unexported} \n " )
83- target_link_options (${LIBRARY_NAME} PRIVATE
84- "LINKER:-unexported_symbols_list,${_cudaq_symbol_list} " )
85- else ()
86- # GNU ld / lld: a version script with a local: block leaves the rest exported.
87- set (_cudaq_version_script "${CMAKE_CURRENT_BINARY_DIR } /cudaqMLIR-hidden.map" )
88- # relink if the version script changes
89- set_property (TARGET ${LIBRARY_NAME} APPEND PROPERTY LINK_DEPENDS "${_cudaq_version_script} " )
90- set (_cudaq_blocklist_body "" )
91- foreach (_pat IN LISTS _cudaq_blocklist_patterns)
92- string (APPEND _cudaq_blocklist_body " ${_pat} ;\n " )
93- endforeach ()
94- file (WRITE "${_cudaq_version_script} " "{\n local:\n ${_cudaq_blocklist_body} };\n " )
95- target_link_options (${LIBRARY_NAME} PRIVATE
96- "LINKER:--version-script=${_cudaq_version_script} " )
97- endif ()
76+ # 4. Bundle the LLVM native target for JITing.
77+ llvm_map_components_to_libnames (_cudaq_llvm_native_libs native nativecodegen )
78+ foreach (_lib IN LISTS _cudaq_llvm_native_libs)
79+ if (TARGET ${_lib} )
80+ target_link_libraries (${LIBRARY_NAME} PRIVATE "$<LINK_LIBRARY :WHOLE_ARCHIVE ,${_lib} >" )
81+ endif ()
82+ endforeach ()
9883
9984# We are using the following linker flags:
10085# - -Bsymbolic-functions: ELF treats symbols as preemptible by default. This adds a
@@ -112,5 +97,5 @@ else()
11297 target_link_options (${LIBRARY_NAME} PRIVATE "LINKER:--gc-sections" )
11398endif ()
11499
115- install (TARGETS ${LIBRARY_NAME} EXPORT CUDAQTargets DESTINATION lib)
100+ install (TARGETS ${LIBRARY_NAME} EXPORT cudaq- targets DESTINATION lib)
116101set_target_properties (${LIBRARY_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR } /lib)
0 commit comments