summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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.cmake10
6 files changed, 23 insertions, 3 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 5e8b39b..62294cd 100644
--- a/Tests/RunCMake/CompilerArgs/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CompilerArgs/RunCMakeTest.cmake
@@ -31,6 +31,11 @@ function(run_compiler_env lang)
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)
@@ -42,6 +47,11 @@ function(run_compiler_tc lang)
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 "-tc-cached")
+ run_cmake(${lang})
+ run_cmake_command(${lang}-Build ${CMAKE_COMMAND} --build . ${verbose_args})
endfunction()
set(langs C CXX)