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

Conversation

petrhosek
Copy link
Member

These packaged are imported by LLVMConfig.cmake and so we should be passing through the necessary variables from the parent build into the subbuilds.

We use CMAKE_CACHE_DEFAULT_ARGS so subbuilds can override these variables if needed.

These packaged are imported by LLVMConfig.cmake and so we should be
passing through the necessary variables from the parent build into
the subbuilds.

We use `CMAKE_CACHE_DEFAULT_ARGS` so subbuilds can override these
variables if needed.
@llvmbot llvmbot added the cmake Build system in general and CMake in particular label Sep 6, 2024
Copy link
Collaborator

@smeenai smeenai left a comment

Choose a reason for hiding this comment

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

Do you happen to know which order CMake passes in the -C arg for CMAKE_CACHE_DEFAULT_ARGS vs. the arguments inside CMAKE_ARGS? If the -C goes before CMAKE_ARGS (which I suspect), there's a potential interaction with https://reviews.llvm.org/D158791; if you want to use that mechanism to override any of these variables, you'll have to specify FORCE. That's fine, just something that came to mind.

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" )

@petrhosek
Copy link
Member Author

Do you happen to know which order CMake passes in the -C arg for CMAKE_CACHE_DEFAULT_ARGS vs. the arguments inside CMAKE_ARGS? If the -C goes before CMAKE_ARGS (which I suspect), there's a potential interaction with https://reviews.llvm.org/D158791; if you want to use that mechanism to override any of these variables, you'll have to specify FORCE. That's fine, just something that came to mind.

It looks like the -C for CMAKE_CACHE_DEFAULT_ARGS comes after the CMAKE_ARGS so this shouldn't be an issue. I'd also like to move more of CMAKE_ARGS to CMAKE_CACHE_ARGS and CMAKE_CACHE_DEFAULT_ARGS in follow up changes since I think it's cleaner and avoid the possibility of hitting command line length limit on Windows.

Copy link
Collaborator

@smeenai smeenai left a comment

Choose a reason for hiding this comment

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

Yup, that sounds like a good direction then.

@petrhosek petrhosek merged commit 60f052e into llvm:main Sep 9, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Build system in general and CMake in particular
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants