diff options
author | Klein, Thorsten (BSH) <thorsten.klein@bshg.com> | 2022-03-28 13:01:08 +0200 |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-03-29 10:36:28 -0400 |
commit | 211a9deac1d4144c7d7ce18ecb6c5d21c4854eaa (patch) | |
tree | a2d1fc22e1fb674146983bf29a486c273638bc7f /Modules/CMakeDetermineCompiler.cmake | |
parent | b4de4217aefedaf46cbb1d700cbd463c3d2d8914 (diff) | |
download | cmake-211a9deac1d4144c7d7ce18ecb6c5d21c4854eaa.tar.gz |
Preserve CMAKE_${lang}_COMPILER_ARG1 from existing CMakeCache.txt
`CMAKE_<LANG>_COMPILER` may be a list if it was defined by a toolchain
file. In this case we move the args to `CMAKE_<LANG>_COMPILER_ARG1`.
If `CMAKE_<LANG>_COMPILER` is not a list, then it might have been cached
by a previous run that split the `CC` or `CXX` environment variable into
`CMAKE_<LANG>_COMPILER` and `CMAKE_<LANG>_COMPILER_ARG1`. In this
latter case, avoid clobbering `CMAKE_<LANG>_COMPILER_ARG1`.
Fixes: #23358
Diffstat (limited to 'Modules/CMakeDetermineCompiler.cmake')
-rw-r--r-- | Modules/CMakeDetermineCompiler.cmake | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake index aec86d92c7..ec2a86515f 100644 --- a/Modules/CMakeDetermineCompiler.cmake +++ b/Modules/CMakeDetermineCompiler.cmake @@ -119,9 +119,15 @@ macro(_cmake_find_compiler_path lang) # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE # if CMAKE_${lang}_COMPILER is a list, use the first item as # CMAKE_${lang}_COMPILER and the rest as CMAKE_${lang}_COMPILER_ARG1 - set(CMAKE_${lang}_COMPILER_ARG1 "${CMAKE_${lang}_COMPILER}") - list(POP_FRONT CMAKE_${lang}_COMPILER_ARG1 CMAKE_${lang}_COMPILER) - list(JOIN CMAKE_${lang}_COMPILER_ARG1 " " CMAKE_${lang}_COMPILER_ARG1) + # Otherwise, preserve any existing CMAKE_${lang}_COMPILER_ARG1 that might + # have been saved by CMakeDetermine${lang}Compiler in a previous run. + list(LENGTH CMAKE_${lang}_COMPILER _CMAKE_${lang}_COMPILER_LENGTH) + if(_CMAKE_${lang}_COMPILER_LENGTH GREATER 1) + set(CMAKE_${lang}_COMPILER_ARG1 "${CMAKE_${lang}_COMPILER}") + list(POP_FRONT CMAKE_${lang}_COMPILER_ARG1 CMAKE_${lang}_COMPILER) + list(JOIN CMAKE_${lang}_COMPILER_ARG1 " " CMAKE_${lang}_COMPILER_ARG1) + endif() + unset(_CMAKE_${lang}_COMPILER_LENGTH) # find the compiler in the PATH if necessary # if compiler (and arguments) comes from cache then synchronize cache with updated CMAKE_<LANG>_COMPILER |