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
This commit is contained in:
Brad King
2022-03-30 13:03:08 +00:00
committed by Kitware Robot
6 changed files with 30 additions and 15 deletions
+9 -3
View File
@@ -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
+1
View File
@@ -0,0 +1 @@
-- CMAKE_C_COMPILER_ARG1=' ?-DFOO1 -DFOO2'
+1
View File
@@ -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)
@@ -0,0 +1 @@
-- CMAKE_CXX_COMPILER_ARG1=' ?-DFOO1 -DFOO2'
+1
View File
@@ -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)
+17 -12
View File
@@ -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_BINARY_DIR ${RunCMake_BINARY_DIR}/${lang}-tc-build)
set(RunCMake_TEST_NO_CLEAN 1)
file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
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)
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()