summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeDetermineOBJCXXCompiler.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-05-14 11:10:09 (GMT)
committerBrad King <brad.king@kitware.com>2020-05-14 11:17:48 (GMT)
commit67b9f55d46f934de0954ae83d39169c86039ecea (patch)
treee90b8d9048d1d85679511afa18db2189c75ce1e9 /Modules/CMakeDetermineOBJCXXCompiler.cmake
parentab9be6662f3ab7bf93a5793395d0aeb3c2297e86 (diff)
downloadCMake-67b9f55d46f934de0954ae83d39169c86039ecea.zip
CMake-67b9f55d46f934de0954ae83d39169c86039ecea.tar.gz
CMake-67b9f55d46f934de0954ae83d39169c86039ecea.tar.bz2
Objective C/C++: Honor CC and CXX env vars to select compiler
If the `OBJC` or `OBJCXX` environment variable is not set to specify an Objective C or C++ compiler, check `CC` or `CXX` too. Fixes: #20703
Diffstat (limited to 'Modules/CMakeDetermineOBJCXXCompiler.cmake')
-rw-r--r--Modules/CMakeDetermineOBJCXXCompiler.cmake21
1 files changed, 12 insertions, 9 deletions
diff --git a/Modules/CMakeDetermineOBJCXXCompiler.cmake b/Modules/CMakeDetermineOBJCXXCompiler.cmake
index 60fcbb3..db874d1 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)