Skip to content

[CMake] Passthrough variables for packages to subbuilds #107611

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
Sep 9, 2024
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
27 changes: 27 additions & 0 deletions llvm/cmake/modules/LLVMExternalProjectUtils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,32 @@ function(llvm_ExternalProject_Add name source_dir)
set_target_properties(${name}-clear PROPERTIES FOLDER "${ARG_FOLDER}")
endif ()

set(DEFAULT_PASSTHROUGH_VARIABLES
LibEdit_INCLUDE_DIRS
LibEdit_LIBRARIES
ZLIB_INCLUDE_DIR
ZLIB_LIBRARY
zstd_INCLUDE_DIR
zstd_LIBRARY
LIBXML2_LIBRARY
LIBXML2_INCLUDE_DIR
CURL_INCLUDE_DIR
CURL_LIBRARY
HTTPLIB_INCLUDE_DIR
HTTPLIB_HEADER_PATH
Python3_EXECUTABLE
Python3_LIBRARIES
Python3_INCLUDE_DIRS
Python3_RPATH
)
foreach(variable ${DEFAULT_PASSTHROUGH_VARIABLES})
get_property(is_value_set CACHE ${variable} PROPERTY VALUE SET)
if(${is_value_set})
get_property(value CACHE ${variable} PROPERTY VALUE)
list(APPEND CMAKE_CACHE_DEFAULT_ARGS "-D${variable}:STRING=${value}")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we not need to replace ; with | to have list variables be passed through correctly? The documentation isn't clear on whether LIST_SEPARATOR applies to CMAKE_CACHE_DEFAULT_ARGS.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's what I read as well but I wasn't sure if it's needed or not so I tested and it looks like it's not required.

The following example:

ExternalProject_Add(test
  SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test
  CMAKE_ARGS -Done=a|b|c
  CMAKE_CACHE_ARGS -Dtwo:STRING=a;b;c
  CMAKE_CACHE_DEFAULT_ARGS -Dthree:STRING=a|b|c
  LIST_SEPARATOR |
)

produces the following cache file:

set(two "a;b;c" CACHE STRING "Initial cache" FORCE)
set(three "a;b;c" CACHE STRING "Initial cache" )

endif()
endforeach()

# Find all variables that start with a prefix and propagate them through
get_cmake_property(variableNames VARIABLES)

Expand Down Expand Up @@ -363,6 +389,7 @@ function(llvm_ExternalProject_Add name source_dir)
-DCMAKE_EXPORT_COMPILE_COMMANDS=1
${cmake_args}
${PASSTHROUGH_VARIABLES}
CMAKE_CACHE_DEFAULT_ARGS ${CMAKE_CACHE_DEFAULT_ARGS}
INSTALL_COMMAND ""
STEP_TARGETS configure build
BUILD_ALWAYS 1
Expand Down
Loading