From 6f1af899db4e93c960145dae12ebaacb308ea1f0 Mon Sep 17 00:00:00 2001 From: Fred Baksik Date: Wed, 15 Jul 2020 15:03:45 -0400 Subject: Toolchain: Capture all arguments from CMAKE__COMPILER Capture CMAKE__COMPILER_ARG1 from CMAKE__COMPILER in the same fashion that it is from $ENV{}. Since get_filename_component() returns a single string of all the arguments from $ENV{}, a single string of arguments will be constructed from the items contained in CMAKE__COMPILER. Fixes #20089 --- Modules/CMakeDetermineCompiler.cmake | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'Modules/CMakeDetermineCompiler.cmake') diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake index 7cd7c47b8a..142e61e71d 100644 --- a/Modules/CMakeDetermineCompiler.cmake +++ b/Modules/CMakeDetermineCompiler.cmake @@ -107,14 +107,11 @@ macro(_cmake_find_compiler_path lang) if(CMAKE_${lang}_COMPILER) # we only get here if CMAKE_${lang}_COMPILER was specified using -D or a pre-made CMakeCache.txt # (e.g. via ctest) or set in CMAKE_TOOLCHAIN_FILE - # if CMAKE_${lang}_COMPILER is a list of length 2, use the first item as - # CMAKE_${lang}_COMPILER and the 2nd one as CMAKE_${lang}_COMPILER_ARG1 - list(LENGTH CMAKE_${lang}_COMPILER _CMAKE_${lang}_COMPILER_LIST_LENGTH) - if("${_CMAKE_${lang}_COMPILER_LIST_LENGTH}" EQUAL 2) - list(GET CMAKE_${lang}_COMPILER 1 CMAKE_${lang}_COMPILER_ARG1) - list(GET CMAKE_${lang}_COMPILER 0 CMAKE_${lang}_COMPILER) - endif() - unset(_CMAKE_${lang}_COMPILER_LIST_LENGTH) + # 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) # find the compiler in the PATH if necessary get_filename_component(_CMAKE_USER_${lang}_COMPILER_PATH "${CMAKE_${lang}_COMPILER}" PATH) -- cgit v1.2.1 From 12ba89e142c3db629e6e201a409b4c08bb169bdc Mon Sep 17 00:00:00 2001 From: Fred Baksik Date: Wed, 15 Jul 2020 15:03:45 -0400 Subject: Toolchain: Make `/path/comp;-argn' behave the same as 'comp;-argn' When using `cmake ... -DCMAKE_C_COMPILER=gcc;-pipe` first invocation of CMake worked correctly. When using `cmake ... -DCMAKE_C_COMPILER=/path/to/gcc;-pipe` first invocation of CMake detected a change to CMAKE_C_COMPILER, printed "You have changed variables" message, and re-ran the initial compiler tests after configuration was complete and before generation of the project files. The difference was due to the cache being forced updated with the new value of CMAKE_C_COMPILER so that the comparison check passes. --- Modules/CMakeDetermineCompiler.cmake | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'Modules/CMakeDetermineCompiler.cmake') diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake index 142e61e71d..a1da441b2f 100644 --- a/Modules/CMakeDetermineCompiler.cmake +++ b/Modules/CMakeDetermineCompiler.cmake @@ -114,6 +114,7 @@ macro(_cmake_find_compiler_path lang) list(JOIN CMAKE_${lang}_COMPILER_ARG1 " " CMAKE_${lang}_COMPILER_ARG1) # find the compiler in the PATH if necessary + # if compiler (and arguments) comes from cache then synchronize cache with updated CMAKE__COMPILER get_filename_component(_CMAKE_USER_${lang}_COMPILER_PATH "${CMAKE_${lang}_COMPILER}" PATH) if(NOT _CMAKE_USER_${lang}_COMPILER_PATH) find_program(CMAKE_${lang}_COMPILER_WITH_PATH NAMES ${CMAKE_${lang}_COMPILER}) @@ -126,6 +127,12 @@ macro(_cmake_find_compiler_path lang) unset(_CMAKE_${lang}_COMPILER_CACHED) endif() unset(CMAKE_${lang}_COMPILER_WITH_PATH CACHE) + elseif (EXISTS ${CMAKE_${lang}_COMPILER}) + get_property(_CMAKE_${lang}_COMPILER_CACHED CACHE CMAKE_${lang}_COMPILER PROPERTY TYPE) + if(_CMAKE_${lang}_COMPILER_CACHED) + set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER}" CACHE STRING "${lang} compiler" FORCE) + endif() + unset(_CMAKE_${lang}_COMPILER_CACHED) endif() endif() endmacro() -- cgit v1.2.1