Author: ur4t Date: 2025-02-22T09:52:53-08:00 New Revision: 62c78919c678915936fcc08212b02db23738dd4d
URL: https://github.com/llvm/llvm-project/commit/62c78919c678915936fcc08212b02db23738dd4d DIFF: https://github.com/llvm/llvm-project/commit/62c78919c678915936fcc08212b02db23738dd4d.diff LOG: [CMake] Fix some breakages when using ninja multi config (#65451) When using multi-config generator to build `libLLVM.so` like `cmake -G 'Ninja Multi-Config' -Sllvm -B/tmp/out/ninja-multi -DCMAKE_CONFIGURATION_TYPES='Debug;Release' -DLLVM_LINK_LLVM_DYLIB=on -DLLVM_TARGETS_TO_BUILD=host && cmake --build /tmp/out/ninja-multi --config Debug`, `lld` complains `error: cannot find version script /tmp/out/ninja-multi/Debug/lib/tools/llvm-shlib/simple_version_script.map`. This patch adds multi-config compatibility when configuring `simple_version_script.map`. Fixes #63800. When using multi-config generator, clang's headers is not copied to proper directories, which is fixed as well. Added: Modified: clang/lib/Headers/CMakeLists.txt llvm/tools/llvm-shlib/CMakeLists.txt Removed: ################################################################################ diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt index 43124111b7ba5..a3a505bcb7f88 100644 --- a/clang/lib/Headers/CMakeLists.txt +++ b/clang/lib/Headers/CMakeLists.txt @@ -395,12 +395,25 @@ set(riscv_generated_files) function(copy_header_to_output_dir src_dir file) set(src ${src_dir}/${file}) - set(dst ${output_dir}/${file}) - add_custom_command(OUTPUT ${dst} - DEPENDS ${src} - COMMAND ${CMAKE_COMMAND} -E copy_if_ diff erent ${src} ${dst} - COMMENT "Copying clang's ${file}...") - list(APPEND out_files ${dst}) + if("${CMAKE_CFG_INTDIR}" STREQUAL ".") + set(dst ${output_dir}/${file}) + add_custom_command(OUTPUT ${dst} + DEPENDS ${src} + COMMAND ${CMAKE_COMMAND} -E copy_if_ diff erent ${src} ${dst} + COMMENT "Copying clang's ${file}...") + list(APPEND out_files ${dst}) + else() + foreach(BUILD_MODE ${CMAKE_CONFIGURATION_TYPES}) + # Replace the special string with a per config directory. + string(REPLACE ${CMAKE_CFG_INTDIR} ${BUILD_MODE} per_conf_output_dir ${output_dir}) + set(dst ${per_conf_output_dir}/${file}) + add_custom_command(OUTPUT ${dst} + DEPENDS ${src} + COMMAND ${CMAKE_COMMAND} -E copy_if_ diff erent ${src} ${dst} + COMMENT "Copying clang's ${file}...") + list(APPEND out_files ${dst}) + endforeach() + endif() set(out_files ${out_files} PARENT_SCOPE) endfunction(copy_header_to_output_dir) diff --git a/llvm/tools/llvm-shlib/CMakeLists.txt b/llvm/tools/llvm-shlib/CMakeLists.txt index ede3c5034e045..a5b0cab0f1ce5 100644 --- a/llvm/tools/llvm-shlib/CMakeLists.txt +++ b/llvm/tools/llvm-shlib/CMakeLists.txt @@ -45,10 +45,19 @@ if(LLVM_BUILD_LLVM_DYLIB) if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin") set(LIB_NAMES -Wl,-all_load ${LIB_NAMES}) else() - configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in - ${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map) - + if("${CMAKE_CFG_INTDIR}" STREQUAL ".") + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in + ${LLVM_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map) + else() + foreach(BUILD_MODE ${CMAKE_CONFIGURATION_TYPES}) + # Replace the special string with a per config directory. + string(REPLACE ${CMAKE_CFG_INTDIR} ${BUILD_MODE} PER_CONF_LIBRARY_DIR ${LLVM_LIBRARY_DIR}) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/simple_version_script.map.in + ${PER_CONF_LIBRARY_DIR}/tools/llvm-shlib/simple_version_script.map) + endforeach() + endif() if(MSVC) target_link_directories(LLVM PRIVATE ${LLVM_LIBRARY_DIR}) foreach(library ${LIB_NAMES}) @@ -156,7 +165,10 @@ if(LLVM_BUILD_LLVM_C_DYLIB AND MSVC) # Need to separate lib names with newlines. string(REPLACE ";" "\n" FILE_CONTENT "${FULL_LIB_NAMES}") - if(NOT "${CMAKE_CFG_INTDIR}" STREQUAL ".") + if("${CMAKE_CFG_INTDIR}" STREQUAL ".") + # Write out the full lib names into file to be read by the python script. + file(WRITE ${LIBSFILE} "${FILE_CONTENT}") + else() foreach(BUILD_MODE ${CMAKE_CONFIGURATION_TYPES}) # Replace the special string with a per config directory. string(REPLACE ${CMAKE_CFG_INTDIR} ${BUILD_MODE} PER_CONF_CONTENT "${FILE_CONTENT}") @@ -166,9 +178,6 @@ if(LLVM_BUILD_LLVM_C_DYLIB AND MSVC) # ${CMAKE_CFG_INTDIR} correctly and select the right one. file(WRITE ${LLVM_BINARY_DIR}/${BUILD_MODE}/libllvm-c.args "${PER_CONF_CONTENT}") endforeach() - else() - # Write out the full lib names into file to be read by the python script. - file(WRITE ${LIBSFILE} "${FILE_CONTENT}") endif() # Generate the exports file dynamically. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits