Skip to content

[CMake] Correctly handle LLVM_ENABLE_RUNTIMES in targets #69869

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 1 commit into from
Oct 25, 2023
Merged
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
87 changes: 44 additions & 43 deletions llvm/runtimes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,20 @@ if(compiler_rt_path)
endif()
endif()

function(_get_runtime_name name out_var)
string(FIND ${name} "lib" idx)
if(idx EQUAL 0 AND NOT ${name} STREQUAL "libc")
string(SUBSTRING ${name} 3 -1 entry)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In response to the issue seen by @JDevlieghere where the cxx and cxxabi targets are not present:

I believe entry needs changed to name for the SUBSTRING on line 177.

When using -DLLVM_ENABLE_RUNTIMES='libcxx;libcxxabi', ${name} is being returned from the function instead of the SUBSTRING ${entry}.

With your original patch the targets remain libcxx and libcxxabi.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that, I fixed it in fb619b3.

endif()
set(${out_var} ${name} PARENT_SCOPE)
endfunction()

# Create a list with the names of all the runtime projects in all uppercase and
# with dashes turned to underscores. This gives us the CMake variable `prefixes`
# for all variables that will apply to runtimes.
foreach(entry ${runtimes})
get_filename_component(projName ${entry} NAME)
string(REPLACE "-" "_" canon_name ${projName})
get_filename_component(name ${entry} NAME)
string(REPLACE "-" "_" canon_name ${name})
string(TOUPPER ${canon_name} canon_name)
list(APPEND prefixes ${canon_name})
if (${canon_name} STREQUAL "OPENMP")
Expand All @@ -196,11 +204,8 @@ foreach(entry ${runtimes})
endif()
endif()

string(FIND ${projName} "lib" LIB_IDX)
if(LIB_IDX EQUAL 0 AND NOT projName STREQUAL "libc")
string(SUBSTRING ${projName} 3 -1 projName)
endif()
list(APPEND runtime_names ${projName})
_get_runtime_name(${name} name)
list(APPEND RUNTIME_NAMES ${name})
endforeach()

function(runtime_default_target)
Expand All @@ -210,7 +215,7 @@ function(runtime_default_target)
set(SUB_CHECK_TARGETS ${SUB_CHECK_TARGETS} PARENT_SCOPE)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/Components.cmake)

foreach(runtime_name ${runtime_names})
foreach(runtime_name ${RUNTIME_NAMES})
list(APPEND extra_targets
${runtime_name}
install-${runtime_name}
Expand Down Expand Up @@ -268,6 +273,17 @@ function(runtime_register_target name)
include(${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake OPTIONAL)
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${LLVM_BINARY_DIR}/runtimes/${name}/Components.cmake)

set(runtime_names ${RUNTIME_NAMES})
foreach(_name IN ITEMS ${ARG_BASE_NAME} ${name})
if(RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES)
set(runtime_names)
foreach(entry ${RUNTIMES_${_name}_LLVM_ENABLE_RUNTIMES})
_get_runtime_name(${entry} runtime_name)
list(APPEND runtime_names ${runtime_name})
endforeach()
endif()
endforeach()

foreach(runtime_name ${runtime_names})
set(${runtime_name}-${name} ${runtime_name})
set(install-${runtime_name}-${name} install-${runtime_name})
Expand Down Expand Up @@ -365,6 +381,25 @@ function(runtime_register_target name)
${${name}_test_targets}
USE_TOOLCHAIN
${EXTRA_ARGS} ${ARG_EXTRA_ARGS})

add_dependencies(runtimes runtimes-${name})
add_dependencies(runtimes-configure runtimes-${name}-configure)
add_dependencies(install-runtimes install-runtimes-${name})
add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)
if(LLVM_INCLUDE_TESTS)
add_dependencies(check-runtimes check-runtimes-${name})
add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
endif()
foreach(runtime_name ${runtime_names})
add_dependencies(${runtime_name} ${runtime_name}-${name})
add_dependencies(install-${runtime_name} install-${runtime_name}-${name})
add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}-stripped)
endforeach()
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
add_dependencies(${component} ${component}-${name})
add_dependencies(install-${component} install-${component}-${name})
add_dependencies(install-${component}-stripped install-${component}-${name}-stripped)
endforeach()
endfunction()

if(runtimes)
Expand Down Expand Up @@ -424,7 +459,7 @@ if(runtimes)
add_custom_target(runtimes-test-depends)
set(test_targets "")
endif()
foreach(runtime_name ${runtime_names})
foreach(runtime_name ${RUNTIME_NAMES})
add_custom_target(${runtime_name})
add_custom_target(install-${runtime_name})
add_custom_target(install-${runtime_name}-stripped)
Expand Down Expand Up @@ -453,25 +488,6 @@ if(runtimes)
DEPENDS ${builtins_dep_name} ${libc_tools}
CMAKE_ARGS -DLLVM_DEFAULT_TARGET_TRIPLE=${name} ${libc_cmake_args}
EXTRA_ARGS TARGET_TRIPLE ${name})

add_dependencies(runtimes runtimes-${name})
add_dependencies(runtimes-configure runtimes-${name}-configure)
add_dependencies(install-runtimes install-runtimes-${name})
add_dependencies(install-runtimes-stripped install-runtimes-${name}-stripped)
if(LLVM_INCLUDE_TESTS)
add_dependencies(check-runtimes check-runtimes-${name})
add_dependencies(runtimes-test-depends runtimes-test-depends-${name})
endif()
foreach(runtime_name ${runtime_names})
add_dependencies(${runtime_name} ${runtime_name}-${name})
add_dependencies(install-${runtime_name} install-${runtime_name}-${name})
add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}-stripped)
endforeach()
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
add_dependencies(${component} ${component}-${name})
add_dependencies(install-${component} install-${component}-${name})
add_dependencies(install-${component}-stripped install-${component}-${name}-stripped)
endforeach()
endforeach()

foreach(multilib ${LLVM_RUNTIME_MULTILIBS})
Expand All @@ -483,21 +499,6 @@ if(runtimes)
-DLLVM_RUNTIMES_LIBDIR_SUBDIR=${multilib}
BASE_NAME ${name}
EXTRA_ARGS TARGET_TRIPLE ${name})

add_dependencies(runtimes runtimes-${name}+${multilib})
add_dependencies(runtimes-configure runtimes-${name}+${multilib}-configure)
add_dependencies(install-runtimes install-runtimes-${name}+${multilib})
add_dependencies(install-runtimes-stripped install-runtimes-${name}+${multilib}-stripped)
foreach(runtime_name ${runtime_names})
add_dependencies(${runtime_name} ${runtime_name}-${name}+${multilib})
add_dependencies(install-${runtime_name} install-${runtime_name}-${name}+${multilib})
add_dependencies(install-${runtime_name}-stripped install-${runtime_name}-${name}+${multilib}-stripped)
endforeach()
foreach(component ${LLVM_RUNTIME_DISTRIBUTION_COMPONENTS})
add_dependencies(${component} ${component}-${name}+${multilib})
add_dependencies(install-${component} install-${component}-${name}+${multilib})
add_dependencies(install-${component}-stripped install-${component}-${name}+${multilib}-stripped)
endforeach()
endforeach()
endforeach()
endif()
Expand Down