Skip to content

[CMake] Fix some breakages when using ninja multi config #65451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions clang/lib/Headers/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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_different ${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_different ${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_different ${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)

Expand Down
25 changes: 17 additions & 8 deletions llvm/tools/llvm-shlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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}")
Expand All @@ -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.
Expand Down