summaryrefslogtreecommitdiff
path: root/Modules/CMakeDetermineOBJCCompiler.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2020-05-14 07:10:09 -0400
committerBrad King <brad.king@kitware.com>2020-05-14 07:17:48 -0400
commit67b9f55d46f934de0954ae83d39169c86039ecea (patch)
treee90b8d9048d1d85679511afa18db2189c75ce1e9 /Modules/CMakeDetermineOBJCCompiler.cmake
parentab9be6662f3ab7bf93a5793395d0aeb3c2297e86 (diff)
downloadcmake-67b9f55d46f934de0954ae83d39169c86039ecea.tar.gz
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/CMakeDetermineOBJCCompiler.cmake')
-rw-r--r--Modules/CMakeDetermineOBJCCompiler.cmake21
1 files changed, 12 insertions, 9 deletions
diff --git a/Modules/CMakeDetermineOBJCCompiler.cmake b/Modules/CMakeDetermineOBJCCompiler.cmake
index ad13eab5e8..11b47fde84 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)