-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[llvm] Fix cmake string expansion in CrossCompile.cmake #138901
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
base: main
Are you sure you want to change the base?
Conversation
This fixes an issue where builds on Windows with LLVM_OPTIMIZED_TABLEGEN will fail if CMAKE_MAKE_PROGRAM, CMAKE_C_COMPILER_LAUNCHER or CMAKE_CXX_COMPILER_LAUNCHER are lists rather than paths to a binary; this occurs when one of these programs is passed with arguments instead of just as a path. On non-Windows this works regardless as the sub-cmake command runs in a proper shell, but on Windows it runs differently and so these strings need to be expanded correctly by cmake.
This is necessary because CMake won't expand a list into string if the quoted string isn't surrounded by whitespace. If it is, it will correctly expand and add quotes around the resulting string, so moving the string to cover the whole "-D..." option will make cmake do the right thing here. |
-DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}" | ||
-DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}" | ||
-DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}" | ||
"-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an example where you'd want to pass flags to the native build system?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't have one specifically for the CMAKE_MAKE_PROGRAM, I just thought I'd fx it as well while I was here as the same reasoning would apply there.
We want this for CMAKE_C/CXX_COMPILER_LAUNCHER, where we want to add flags to ccache
when using LLVM_CCACHE_BUILD to control certain behaviour especially when building flang. When we tried to make that change it worked on non-Windows but didn't work on Windows, this fixes at least that case. So that's the specific motivation for the change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose I can imagine a case where you might want to enable some debug modes in ninja
with -d ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, we have other places in LLVM where we set these variables and ideally we would make the same change consistently everywhere.
-DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}" | ||
"-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}" | ||
"-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}" | ||
"-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LLVM_TABLEGEN_FLAGS below should also be fixed (added recently, #138086).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the difference is that the surrounding quotes are handled by CMake itself, so they are never seen when passing them as a command line string.
CMake indeed does not use always use cmd.exe to launch programs, but usually it normalizes paths to absolute paths and using forward slashes instead of backslashes, at least for CMAKE_*_COMPILER
. Might be different for others.
This fixes an issue where builds on Windows with LLVM_OPTIMIZED_TABLEGEN
will fail if CMAKE_MAKE_PROGRAM, CMAKE_C_COMPILER_LAUNCHER or
CMAKE_CXX_COMPILER_LAUNCHER are lists rather than paths to a binary;
this occurs when one of these programs is passed with arguments instead
of just as a path.
On non-Windows this works regardless as the sub-cmake command runs in a
proper shell, but on Windows it runs differently and so these strings
need to be expanded correctly by cmake.