CompilerId: Allow specifying the compiler-specific components to generate.

This commit is contained in:
Stephen Kelly 2014-04-23 10:46:47 +02:00
parent 9a083bce83
commit 36ed589484
2 changed files with 22 additions and 3 deletions

View File

@ -20,6 +20,8 @@ function(_readFile file)
set(_compiler_id_pp_test_${CompilerId} ${_compiler_id_pp_test} PARENT_SCOPE)
endfunction()
include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
function(compiler_id_detection outvar lang)
file(GLOB lang_files
@ -36,6 +38,12 @@ function(compiler_id_detection outvar lang)
_readFile(${file})
endforeach()
set(options ID_STRING VERSION_STRINGS)
cmake_parse_arguments(CID "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (CID_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unrecognized arguments: \"${CID_UNPARSED_ARGUMENTS}\"")
endif()
set(ordered_compilers
# Order is relevant here. For example, compilers which pretend to be
# GCC must appear before the actual GCC.
@ -65,14 +73,22 @@ function(compiler_id_detection outvar lang)
MIPSpro)
set(pp_if "#if")
set(CMAKE_${lang}_COMPILER_ID_CONTENT "/* Version number components: V=Version, R=Revision, P=Patch
if (CID_VERSION_STRINGS)
set(CMAKE_${lang}_COMPILER_ID_CONTENT "/* Version number components: V=Version, R=Revision, P=Patch
Version date components: YYYY=Year, MM=Month, DD=Day */\n")
endif()
foreach(Id ${ordered_compilers})
if (NOT _compiler_id_pp_test_${Id})
message(FATAL_ERROR "No preprocessor test for \"${Id}\"")
endif()
set(id_content "${pp_if} ${_compiler_id_pp_test_${Id}}\n# define COMPILER_ID \"${Id}\"${_compiler_id_version_compute_${Id}}\n")
set(id_content "${pp_if} ${_compiler_id_pp_test_${Id}}\n")
if (CID_ID_STRING)
set(id_content "${id_content}# define COMPILER_ID \"${Id}\"")
endif()
if (CID_VERSION_STRINGS)
set(id_content "${id_content}${_compiler_id_version_compute_${Id}}\n")
endif()
set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${id_content}")
set(pp_if "#elif")
endforeach()

View File

@ -105,7 +105,10 @@ function(CMAKE_DETERMINE_COMPILER_ID_WRITE lang src)
find_file(src_in ${src}.in PATHS ${CMAKE_ROOT}/Modules ${CMAKE_MODULE_PATH} NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
file(READ ${src_in} ID_CONTENT_IN)
compiler_id_detection(CMAKE_${lang}_COMPILER_ID_CONTENT ${lang})
compiler_id_detection(CMAKE_${lang}_COMPILER_ID_CONTENT ${lang}
ID_STRING
VERSION_STRINGS
)
unset(src_in CACHE)
string(CONFIGURE "${ID_CONTENT_IN}" ID_CONTENT_OUT @ONLY)