diff options
author | Brad King <brad.king@kitware.com> | 2020-05-14 11:10:09 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-05-14 11:17:48 (GMT) |
commit | 67b9f55d46f934de0954ae83d39169c86039ecea (patch) | |
tree | e90b8d9048d1d85679511afa18db2189c75ce1e9 /Modules/CMakeDetermineOBJCCompiler.cmake | |
parent | ab9be6662f3ab7bf93a5793395d0aeb3c2297e86 (diff) | |
download | CMake-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/CMakeDetermineOBJCCompiler.cmake')
-rw-r--r-- | Modules/CMakeDetermineOBJCCompiler.cmake | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/Modules/CMakeDetermineOBJCCompiler.cmake b/Modules/CMakeDetermineOBJCCompiler.cmake index ad13eab..11b47fd 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) |