diff --git a/Help/envvar/OBJC.rst b/Help/envvar/OBJC.rst index dda809c8e65429c8b0739b56d74a80decd4cccec..30c0d133b9d153eec79700a101c483d140088f30 100644 --- a/Help/envvar/OBJC.rst +++ b/Help/envvar/OBJC.rst @@ -9,3 +9,6 @@ which the value for ``OBJC`` is stored in the cache as :variable:`CMAKE_OBJC_COMPILER <CMAKE_<LANG>_COMPILER>`. For any configuration run (including the first), the environment variable will be ignored if the :variable:`CMAKE_OBJC_COMPILER <CMAKE_<LANG>_COMPILER>` variable is defined. + +If ``OBJC`` is not defined, the :envvar:`CC` environment variable will +be checked instead. diff --git a/Help/envvar/OBJCXX.rst b/Help/envvar/OBJCXX.rst index be1fa4248c744902642ef48a1f80f205a632bd83..a72f7e7104f3137a7805e047c5b12727819b1c37 100644 --- a/Help/envvar/OBJCXX.rst +++ b/Help/envvar/OBJCXX.rst @@ -9,3 +9,6 @@ which the value for ``OBJCXX`` is stored in the cache as :variable:`CMAKE_OBJCXX_COMPILER <CMAKE_<LANG>_COMPILER>`. For any configuration run (including the first), the environment variable will be ignored if the :variable:`CMAKE_OBJCXX_COMPILER <CMAKE_<LANG>_COMPILER>` variable is defined. + +If ``OBJCXX`` is not defined, the :envvar:`CXX` environment variable will +be checked instead. diff --git a/Help/release/3.16.rst b/Help/release/3.16.rst index e2d6788217603c26b67449b8e2935cff59595692..bd6d041f5f8efd5db9812e45aec4b1a56795072c 100644 --- a/Help/release/3.16.rst +++ b/Help/release/3.16.rst @@ -303,3 +303,10 @@ Changes made since CMake 3.16.0 include the following. Additionally, the modules no longer expose their internal ``_Python*`` cache entries publicly. CMake 3.16.0 through 3.16.4 accidentally made them visible as advanced cache entries. + +3.16.7 +------ + +* Selection of the Objective C or C++ compiler now considers the + :envvar:`CC` or :envvar:`CXX` environment variable if the + :envvar:`OBJC` or :envvar:`OBJCXX` environment variable is not set. diff --git a/Modules/CMakeDetermineOBJCCompiler.cmake b/Modules/CMakeDetermineOBJCCompiler.cmake index ad13eab5e8bf0a4e26f103fe64e9598c80c351a6..11b47fde843971b5e32f24d3c277c2ffcd1c1d51 100644 --- a/Modules/CMakeDetermineOBJCCompiler.cmake +++ b/Modules/CMakeDetermineOBJCCompiler.cmake @@ -34,16 +34,19 @@ else() if(NOT CMAKE_OBJC_COMPILER) set(CMAKE_OBJC_COMPILER_INIT NOTFOUND) - # prefer the environment variable OBJC - if($ENV{OBJC} MATCHES ".+") - get_filename_component(CMAKE_OBJC_COMPILER_INIT $ENV{OBJC} PROGRAM PROGRAM_ARGS CMAKE_OBJC_FLAGS_ENV_INIT) - if(CMAKE_OBJC_FLAGS_ENV_INIT) - set(CMAKE_OBJC_COMPILER_ARG1 "${CMAKE_OBJC_FLAGS_ENV_INIT}" CACHE STRING "First argument to Objective-C compiler") + # prefer the environment variable OBJC or CC + foreach(var OBJC CC) + if($ENV{${var}} MATCHES ".+") + get_filename_component(CMAKE_OBJC_COMPILER_INIT $ENV{${var}} PROGRAM PROGRAM_ARGS CMAKE_OBJC_FLAGS_ENV_INIT) + if(CMAKE_OBJC_FLAGS_ENV_INIT) + set(CMAKE_OBJC_COMPILER_ARG1 "${CMAKE_OBJC_FLAGS_ENV_INIT}" CACHE STRING "First argument to Objective-C compiler") + endif() + if(NOT EXISTS ${CMAKE_OBJC_COMPILER_INIT}) + message(FATAL_ERROR "Could not find compiler set in environment variable ${var}:\n $ENV{${var}}") + endif() + break() endif() - if(NOT EXISTS ${CMAKE_OBJC_COMPILER_INIT}) - message(FATAL_ERROR "Could not find compiler set in environment variable OBJC:\n$ENV{OBJC}.") - endif() - endif() + endforeach() # next try prefer the compiler specified by the generator if(CMAKE_GENERATOR_OBJC) diff --git a/Modules/CMakeDetermineOBJCXXCompiler.cmake b/Modules/CMakeDetermineOBJCXXCompiler.cmake index 60fcbb3f51bbbeebe2f6a036a4d5185c97b707c3..db874d1a68a61e5372160b724d5750b34f4ff4ce 100644 --- a/Modules/CMakeDetermineOBJCXXCompiler.cmake +++ b/Modules/CMakeDetermineOBJCXXCompiler.cmake @@ -36,16 +36,19 @@ else() if(NOT CMAKE_OBJCXX_COMPILER) set(CMAKE_OBJCXX_COMPILER_INIT NOTFOUND) - # prefer the environment variable OBJCXX - if($ENV{OBJCXX} MATCHES ".+") - get_filename_component(CMAKE_OBJCXX_COMPILER_INIT $ENV{OBJCXX} PROGRAM PROGRAM_ARGS CMAKE_OBJCXX_FLAGS_ENV_INIT) - if(CMAKE_OBJCXX_FLAGS_ENV_INIT) - set(CMAKE_OBJCXX_COMPILER_ARG1 "${CMAKE_OBJCXX_FLAGS_ENV_INIT}" CACHE STRING "First argument to Objective-C++ compiler") + # prefer the environment variable OBJCXX or CXX + foreach(var OBJCXX CXX) + if($ENV{${var}} MATCHES ".+") + get_filename_component(CMAKE_OBJCXX_COMPILER_INIT $ENV{${var}} PROGRAM PROGRAM_ARGS CMAKE_OBJCXX_FLAGS_ENV_INIT) + if(CMAKE_OBJCXX_FLAGS_ENV_INIT) + set(CMAKE_OBJCXX_COMPILER_ARG1 "${CMAKE_OBJCXX_FLAGS_ENV_INIT}" CACHE STRING "First argument to Objective-C++ compiler") + endif() + if(NOT EXISTS ${CMAKE_OBJCXX_COMPILER_INIT}) + message(FATAL_ERROR "Could not find compiler set in environment variable ${var}:\n $ENV{${var}}") + endif() + break() endif() - if(NOT EXISTS ${CMAKE_OBJCXX_COMPILER_INIT}) - message(FATAL_ERROR "Could not find compiler set in environment variable OBJCXX:\n$ENV{OBJCXX}.\n${CMAKE_OBJCXX_COMPILER_INIT}") - endif() - endif() + endforeach() # next prefer the generator specified compiler if(CMAKE_GENERATOR_OBJCXX)