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.
This commit is contained in:
parent
b8b5c8342a
commit
9a9e1ee98d
|
@ -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,6 +107,8 @@ Id flags: ${testflags}
|
|||
")
|
||||
|
||||
# Compile the compiler identification source.
|
||||
if(0)
|
||||
else()
|
||||
if(COMMAND EXECUTE_PROCESS)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_${lang}_COMPILER}
|
||||
|
@ -121,6 +132,7 @@ Id flags: ${testflags}
|
|||
RETURN_VALUE CMAKE_${lang}_COMPILER_ID_RESULT
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Check the result of compilation.
|
||||
if(CMAKE_${lang}_COMPILER_ID_RESULT)
|
||||
|
@ -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})
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue