diff options
author | Brad King <brad.king@kitware.com> | 2012-08-15 20:12:05 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2012-08-22 19:14:33 (GMT) |
commit | 9a9e1ee98d59ba1ed2a89a2858224a7f8a92bbf6 (patch) | |
tree | 7478670a51cb38029cfc2a347fcbf594f70914b1 /Modules/CMakeDetermineCompilerId.cmake | |
parent | b8b5c8342a2a2de5f57f9dd83435060b4eb825a8 (diff) | |
download | CMake-9a9e1ee98d59ba1ed2a89a2858224a7f8a92bbf6.zip CMake-9a9e1ee98d59ba1ed2a89a2858224a7f8a92bbf6.tar.gz CMake-9a9e1ee98d59ba1ed2a89a2858224a7f8a92bbf6.tar.bz2 |
CMakeDetermineCompilerId: Prepare to detect IDE compiler id
Teach CMAKE_DETERMINE_COMPILER_ID to check for variable
CMAKE_${lang}_COMPILER_ID_TOOL after CMAKE_DETERMINE_COMPILER_ID_BUILD
to use as CMAKE_${lang}_COMPILER since it will not be known until after
the IDE runs.
In CMAKE_DETERMINE_COMPILER_ID_BUILD prepare a cascading "if" so we can
use a generator-specific method to compile the identification source
file. Leave "if(0)" as a placeholder for now and put the direct
compiler invocation in "else()". After running the compiler to build
the compiler identification source we file(GLOB) the list of output
files as candidates for extracting the compiler information. An IDE may
create directories, so exclude exclude directories from this list.
Diffstat (limited to 'Modules/CMakeDetermineCompilerId.cmake')
-rw-r--r-- | Modules/CMakeDetermineCompilerId.cmake | 70 |
1 files changed, 43 insertions, 27 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index f574978..f4b9bb0 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -66,6 +66,15 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) message(STATUS "The ${lang} compiler identification is unknown") endif() + # Check if compiler id detection gave us the compiler tool. + if(NOT CMAKE_${lang}_COMPILER) + if(CMAKE_${lang}_COMPILER_ID_TOOL) + set(CMAKE_${lang}_COMPILER "${CMAKE_${lang}_COMPILER_ID_TOOL}" PARENT_SCOPE) + else() + set(CMAKE_${lang}_COMPILER "CMAKE_${lang}_COMPILER-NOTFOUND" PARENT_SCOPE) + endif() + endif() + set(CMAKE_${lang}_COMPILER_ID "${CMAKE_${lang}_COMPILER_ID}" PARENT_SCOPE) set(CMAKE_${lang}_PLATFORM_ID "${CMAKE_${lang}_PLATFORM_ID}" PARENT_SCOPE) set(MSVC_${lang}_ARCHITECTURE_ID "${MSVC_${lang}_ARCHITECTURE_ID}" @@ -98,28 +107,31 @@ Id flags: ${testflags} ") # Compile the compiler identification source. - if(COMMAND EXECUTE_PROCESS) - execute_process( - COMMAND ${CMAKE_${lang}_COMPILER} - ${CMAKE_${lang}_COMPILER_ID_ARG1} - ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST} - ${testflags} - "${src}" - WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR} - OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT - ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT - RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT - ) + if(0) else() - exec_program( - ${CMAKE_${lang}_COMPILER} ${CMAKE_${lang}_COMPILER_ID_DIR} - ARGS ${CMAKE_${lang}_COMPILER_ID_ARG1} - ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST} - ${testflags} - \"${src}\" - OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT - RETURN_VALUE CMAKE_${lang}_COMPILER_ID_RESULT - ) + if(COMMAND EXECUTE_PROCESS) + execute_process( + COMMAND ${CMAKE_${lang}_COMPILER} + ${CMAKE_${lang}_COMPILER_ID_ARG1} + ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST} + ${testflags} + "${src}" + WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR} + OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT + ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT + RESULT_VARIABLE CMAKE_${lang}_COMPILER_ID_RESULT + ) + else() + exec_program( + ${CMAKE_${lang}_COMPILER} ${CMAKE_${lang}_COMPILER_ID_DIR} + ARGS ${CMAKE_${lang}_COMPILER_ID_ARG1} + ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST} + ${testflags} + \"${src}\" + OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT + RETURN_VALUE CMAKE_${lang}_COMPILER_ID_RESULT + ) + endif() endif() # Check the result of compilation. @@ -153,14 +165,18 @@ ${CMAKE_${lang}_COMPILER_ID_OUTPUT} # Find the executable produced by the compiler, try all files in the # binary dir. - file(GLOB COMPILER_${lang}_PRODUCED_FILES + file(GLOB files RELATIVE ${CMAKE_${lang}_COMPILER_ID_DIR} ${CMAKE_${lang}_COMPILER_ID_DIR}/*) - list(REMOVE_ITEM COMPILER_${lang}_PRODUCED_FILES "${src}") - foreach(file ${COMPILER_${lang}_PRODUCED_FILES}) - file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log - "Compilation of the ${lang} compiler identification source \"" - "${src}\" produced \"${file}\"\n\n") + list(REMOVE_ITEM files "${src}") + set(COMPILER_${lang}_PRODUCED_FILES "") + foreach(file ${files}) + if(NOT IS_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}/${file}) + list(APPEND COMPILER_${lang}_PRODUCED_FILES ${file}) + file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log + "Compilation of the ${lang} compiler identification source \"" + "${src}\" produced \"${file}\"\n\n") + endif() endforeach() if(NOT COMPILER_${lang}_PRODUCED_FILES) |