From 36ed5894840f40f6859710d44be607c929e5d38c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 23 Apr 2014 10:46:47 +0200 Subject: [PATCH] CompilerId: Allow specifying the compiler-specific components to generate. --- Modules/CMakeCompilerIdDetection.cmake | 20 ++++++++++++++++++-- Modules/CMakeDetermineCompilerId.cmake | 5 ++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index eee1337fc..5df525fe1 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -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() diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 94c2e5052..712b7488b 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -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)