summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-03-30 13:03:08 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-03-30 13:03:16 (GMT)
commit3d11097ccf53bf541f228d5f37e430ab0d8de7fa (patch)
tree0cc7c4b7bbe8c385eefa0bd9bd1f7a4d84afe3e9
parent70ee9a313afa1882d1b1ceb9c21fbf8ad8acf8bc (diff)
parent211a9deac1d4144c7d7ce18ecb6c5d21c4854eaa (diff)
downloadCMake-3d11097ccf53bf541f228d5f37e430ab0d8de7fa.zip
CMake-3d11097ccf53bf541f228d5f37e430ab0d8de7fa.tar.gz
CMake-3d11097ccf53bf541f228d5f37e430ab0d8de7fa.tar.bz2
Merge topic 'preserve-compiler-arg1'
211a9deac1 Preserve CMAKE_${lang}_COMPILER_ARG1 from existing CMakeCache.txt b4de4217ae Tests: Simplify RunCMake.CompilerArgs no-clean cases Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: buildbot <buildbot@kitware.com> Merge-request: !7122
-rw-r--r--Modules/CMakeDetermineCompiler.cmake12
-rw-r--r--Tests/RunCMake/CompilerArgs/C-stdout.txt1
-rw-r--r--Tests/RunCMake/CompilerArgs/C.cmake1
-rw-r--r--Tests/RunCMake/CompilerArgs/CXX-stdout.txt1
-rw-r--r--Tests/RunCMake/CompilerArgs/CXX.cmake1
-rw-r--r--Tests/RunCMake/CompilerArgs/RunCMakeTest.cmake27
6 files changed, 29 insertions, 14 deletions
diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake
index aec86d9..ec2a865 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
diff --git a/Tests/RunCMake/CompilerArgs/C-stdout.txt b/Tests/RunCMake/CompilerArgs/C-stdout.txt
new file mode 100644
index 0000000..e553cbb
--- /dev/null
+++ b/Tests/RunCMake/CompilerArgs/C-stdout.txt
@@ -0,0 +1 @@
+-- CMAKE_C_COMPILER_ARG1=' ?-DFOO1 -DFOO2'
diff --git a/Tests/RunCMake/CompilerArgs/C.cmake b/Tests/RunCMake/CompilerArgs/C.cmake
index 96b004b..0fbfdd2 100644
--- a/Tests/RunCMake/CompilerArgs/C.cmake
+++ b/Tests/RunCMake/CompilerArgs/C.cmake
@@ -1,3 +1,4 @@
enable_language(C)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
+message(STATUS "CMAKE_C_COMPILER_ARG1='${CMAKE_C_COMPILER_ARG1}'")
add_executable(main main.c)
diff --git a/Tests/RunCMake/CompilerArgs/CXX-stdout.txt b/Tests/RunCMake/CompilerArgs/CXX-stdout.txt
new file mode 100644
index 0000000..c543d3b
--- /dev/null
+++ b/Tests/RunCMake/CompilerArgs/CXX-stdout.txt
@@ -0,0 +1 @@
+-- CMAKE_CXX_COMPILER_ARG1=' ?-DFOO1 -DFOO2'
diff --git a/Tests/RunCMake/CompilerArgs/CXX.cmake b/Tests/RunCMake/CompilerArgs/CXX.cmake
index 3d2ee00..b6cf87e 100644
--- a/Tests/RunCMake/CompilerArgs/CXX.cmake
+++ b/Tests/RunCMake/CompilerArgs/CXX.cmake
@@ -1,3 +1,4 @@
enable_language(CXX)
set(CMAKE_VERBOSE_MAKEFILE TRUE)
+message(STATUS "CMAKE_CXX_COMPILER_ARG1='${CMAKE_CXX_COMPILER_ARG1}'")
add_executable(main main.cxx)
diff --git a/Tests/RunCMake/CompilerArgs/RunCMakeTest.cmake b/Tests/RunCMake/CompilerArgs/RunCMakeTest.cmake
index 9e5a18a..62294cd 100644
--- a/Tests/RunCMake/CompilerArgs/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CompilerArgs/RunCMakeTest.cmake
@@ -19,12 +19,6 @@ function(run_compiler_env lang)
# Use the correct compiler
include(${RunCMake_BINARY_DIR}/Find${lang}Compiler-build/${lang}_comp.cmake)
- # Use a single build tree for tests without cleaning.
- set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${lang}-env-build)
- set(RunCMake_TEST_NO_CLEAN 1)
- file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
- file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
-
# Set the compiler
if(lang STREQUAL "C")
set(ENV{CC} "'${temp_CMAKE_${lang}_COMPILER}' -DFOO1 -DFOO2")
@@ -32,19 +26,30 @@ function(run_compiler_env lang)
set(ENV{${lang}} "'${temp_CMAKE_${lang}_COMPILER}' -DFOO1 -DFOO2")
endif()
+ set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${lang}-env-build)
+ set(RunCMake_TEST_VARIANT_DESCRIPTION "-env")
+ run_cmake(${lang})
+ set(RunCMake_TEST_NO_CLEAN 1)
+ run_cmake_command(${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
+
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}/CMakeFiles")
+ set(RunCMake_TEST_VARIANT_DESCRIPTION "-env-cached")
run_cmake(${lang})
run_cmake_command(${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
endfunction()
function(run_compiler_tc lang)
- # Use a single build tree for tests without cleaning.
+ set(RunCMake_TEST_OPTIONS
+ -DCMAKE_TOOLCHAIN_FILE=${RunCMake_BINARY_DIR}/Find${lang}Compiler-build/toolchain_${lang}_comp.cmake)
+
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${lang}-tc-build)
+ set(RunCMake_TEST_VARIANT_DESCRIPTION "-tc")
+ run_cmake(${lang})
set(RunCMake_TEST_NO_CLEAN 1)
- file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
- file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ run_cmake_command(${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
- set(RunCMake_TEST_OPTIONS
- -DCMAKE_TOOLCHAIN_FILE=${RunCMake_BINARY_DIR}/Find${lang}Compiler-build/toolchain_${lang}_comp.cmake)
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}/CMakeFiles")
+ set(RunCMake_TEST_VARIANT_DESCRIPTION "-tc-cached")
run_cmake(${lang})
run_cmake_command(${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
endfunction()