summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeDetermineCompiler.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2014-03-10 20:51:41 (GMT)
committerBrad King <brad.king@kitware.com>2014-03-10 21:12:00 (GMT)
commit6852fb8034d30d14498dc874378881696a6ada23 (patch)
tree59345bdceb1b7894b2ff919aaeeb240e776755c1 /Modules/CMakeDetermineCompiler.cmake
parenta7c956b86736ea82ade88bea6414cd6a8c84e307 (diff)
downloadCMake-6852fb8034d30d14498dc874378881696a6ada23.zip
CMake-6852fb8034d30d14498dc874378881696a6ada23.tar.gz
CMake-6852fb8034d30d14498dc874378881696a6ada23.tar.bz2
CMakeDetermine*Compiler: Factor out search for compiler in PATH
Factor out a _cmake_find_compiler_path helper macro to avoid duplication of the search for a full path to the compiler.
Diffstat (limited to 'Modules/CMakeDetermineCompiler.cmake')
-rw-r--r--Modules/CMakeDetermineCompiler.cmake30
1 files changed, 30 insertions, 0 deletions
diff --git a/Modules/CMakeDetermineCompiler.cmake b/Modules/CMakeDetermineCompiler.cmake
index f522c44..cd0f8b8 100644
--- a/Modules/CMakeDetermineCompiler.cmake
+++ b/Modules/CMakeDetermineCompiler.cmake
@@ -83,3 +83,33 @@ macro(_cmake_find_compiler lang)
endforeach()
endif()
endmacro()
+
+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)
+
+ # find the compiler in the PATH if necessary
+ 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})
+ if(CMAKE_${lang}_COMPILER_WITH_PATH)
+ set(CMAKE_${lang}_COMPILER ${CMAKE_${lang}_COMPILER_WITH_PATH})
+ 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()
+ unset(CMAKE_${lang}_COMPILER_WITH_PATH CACHE)
+ endif()
+ endif()
+endmacro()