From 9d285600d484c8e539801310f2c4bbe2bb4daef8 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Tue, 22 Apr 2014 16:34:47 +0200 Subject: [PATCH 1/7] Project: Generate the CXX compiler Id test from multiple files. This will allow sharing of the logic of the order to test compilers in and the preprocessor macros used to do that and to determine the version components. --- Modules/CMakeCXXCompilerId.cpp.in | 219 +----------------- Modules/CMakeDetermineCompilerId.cmake | 77 ++++++ Modules/Compiler/ADSP-DetermineCompiler.cmake | 10 + .../AppleClang-DetermineCompiler.cmake | 7 + .../Compiler/Borland-DetermineCompiler.cmake | 7 + .../Compiler/Clang-DetermineCompiler.cmake | 4 + .../Clang-DetermineCompilerInternal.cmake | 11 + .../Comeau-CXX-DetermineCompiler.cmake | 7 + .../Compaq-CXX-DetermineCompiler.cmake | 8 + Modules/Compiler/Cray-DetermineCompiler.cmake | 6 + .../Embarcadero-DetermineCompiler.cmake | 7 + Modules/Compiler/GNU-DetermineCompiler.cmake | 9 + .../Compiler/HP-CXX-DetermineCompiler.cmake | 8 + Modules/Compiler/IAR-DetermineCompiler.cmake | 4 + .../IBMCPP-CXX-DetermineVersionInternal.cmake | 6 + .../Compiler/Intel-DetermineCompiler.cmake | 22 ++ .../Compiler/MIPSpro-DetermineCompiler.cmake | 15 ++ Modules/Compiler/MSVC-DetermineCompiler.cmake | 19 ++ .../OpenWatcom-DetermineCompiler.cmake | 10 + Modules/Compiler/PGI-DetermineCompiler.cmake | 9 + .../PathScale-DetermineCompiler.cmake | 9 + Modules/Compiler/SCO-DetermineCompiler.cmake | 2 + .../SunPro-CXX-DetermineCompiler.cmake | 15 ++ Modules/Compiler/TI-DetermineCompiler.cmake | 8 + .../VisualAge-CXX-DetermineCompiler.cmake | 4 + .../Compiler/Watcom-DetermineCompiler.cmake | 10 + .../Compiler/XL-CXX-DetermineCompiler.cmake | 4 + .../Compiler/zOS-CXX-DetermineCompiler.cmake | 4 + 28 files changed, 303 insertions(+), 218 deletions(-) create mode 100644 Modules/Compiler/ADSP-DetermineCompiler.cmake create mode 100644 Modules/Compiler/AppleClang-DetermineCompiler.cmake create mode 100644 Modules/Compiler/Borland-DetermineCompiler.cmake create mode 100644 Modules/Compiler/Clang-DetermineCompiler.cmake create mode 100644 Modules/Compiler/Clang-DetermineCompilerInternal.cmake create mode 100644 Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake create mode 100644 Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake create mode 100644 Modules/Compiler/Cray-DetermineCompiler.cmake create mode 100644 Modules/Compiler/Embarcadero-DetermineCompiler.cmake create mode 100644 Modules/Compiler/GNU-DetermineCompiler.cmake create mode 100644 Modules/Compiler/HP-CXX-DetermineCompiler.cmake create mode 100644 Modules/Compiler/IAR-DetermineCompiler.cmake create mode 100644 Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake create mode 100644 Modules/Compiler/Intel-DetermineCompiler.cmake create mode 100644 Modules/Compiler/MIPSpro-DetermineCompiler.cmake create mode 100644 Modules/Compiler/MSVC-DetermineCompiler.cmake create mode 100644 Modules/Compiler/OpenWatcom-DetermineCompiler.cmake create mode 100644 Modules/Compiler/PGI-DetermineCompiler.cmake create mode 100644 Modules/Compiler/PathScale-DetermineCompiler.cmake create mode 100644 Modules/Compiler/SCO-DetermineCompiler.cmake create mode 100644 Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake create mode 100644 Modules/Compiler/TI-DetermineCompiler.cmake create mode 100644 Modules/Compiler/VisualAge-CXX-DetermineCompiler.cmake create mode 100644 Modules/Compiler/Watcom-DetermineCompiler.cmake create mode 100644 Modules/Compiler/XL-CXX-DetermineCompiler.cmake create mode 100644 Modules/Compiler/zOS-CXX-DetermineCompiler.cmake diff --git a/Modules/CMakeCXXCompilerId.cpp.in b/Modules/CMakeCXXCompilerId.cpp.in index f7ad80ee2..9ece26def 100644 --- a/Modules/CMakeCXXCompilerId.cpp.in +++ b/Modules/CMakeCXXCompilerId.cpp.in @@ -5,224 +5,7 @@ # error "A C compiler has been selected for C++." #endif -/* Version number components: V=Version, R=Revision, P=Patch - Version date components: YYYY=Year, MM=Month, DD=Day */ - -#if defined(__COMO__) -# define COMPILER_ID "Comeau" - /* __COMO_VERSION__ = VRR */ -# define COMPILER_VERSION_MAJOR DEC(__COMO_VERSION__ / 100) -# define COMPILER_VERSION_MINOR DEC(__COMO_VERSION__ % 100) - -#elif defined(__INTEL_COMPILER) || defined(__ICC) -# define COMPILER_ID "Intel" - /* __INTEL_COMPILER = VRP */ -# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) -# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) -# if defined(__INTEL_COMPILER_UPDATE) -# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) -# else -# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) -# endif -# if defined(__INTEL_COMPILER_BUILD_DATE) - /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ -# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) -# endif -# if defined(_MSC_VER) -# define SIMULATE_ID "MSVC" - /* _MSC_VER = VVRR */ -# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) -# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) -# endif - -#elif defined(__PATHCC__) -# define COMPILER_ID "PathScale" -# define COMPILER_VERSION_MAJOR DEC(__PATHCC__) -# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) -# if defined(__PATHCC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) -# endif - -#elif defined(__clang__) -# if defined(__apple_build_version__) -# define COMPILER_ID "AppleClang" -# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__) -# else -# define COMPILER_ID "Clang" -# endif -# define COMPILER_VERSION_MAJOR DEC(__clang_major__) -# define COMPILER_VERSION_MINOR DEC(__clang_minor__) -# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) -# if defined(_MSC_VER) -# define SIMULATE_ID "MSVC" - /* _MSC_VER = VVRR */ -# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) -# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) -# endif - -#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) -# define COMPILER_ID "Embarcadero" -# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) -# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) -# define COMPILER_VERSION_PATCH HEX(__CODEGEARC_VERSION__ & 0xFFFF) - -#elif defined(__BORLANDC__) -# define COMPILER_ID "Borland" - /* __BORLANDC__ = 0xVRR */ -# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) -# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) - -#elif defined(__WATCOMC__) -# if __WATCOMC__ < 1200 -# define COMPILER_ID "Watcom" - /* __WATCOMC__ = VVRP */ -# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) -# else -# define COMPILER_ID "OpenWatcom" - /* __WATCOMC__ = VVRP + 1100 */ -# define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) -# endif -# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) -# if (__WATCOMC__ % 10) > 0 -# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) -# endif - -#elif defined(__SUNPRO_CC) -# define COMPILER_ID "SunPro" -# if __SUNPRO_CC >= 0x5100 - /* __SUNPRO_CC = 0xVRRP */ -# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>12) -# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xFF) -# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) -# else - /* __SUNPRO_CC = 0xVRP */ -# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>8) -# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xF) -# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) -# endif - -#elif defined(__HP_aCC) -# define COMPILER_ID "HP" - /* __HP_aCC = VVRRPP */ -# define COMPILER_VERSION_MAJOR DEC(__HP_aCC/10000) -# define COMPILER_VERSION_MINOR DEC(__HP_aCC/100 % 100) -# define COMPILER_VERSION_PATCH DEC(__HP_aCC % 100) - -#elif defined(__DECCXX) -# define COMPILER_ID "Compaq" - /* __DECCXX_VER = VVRRTPPPP */ -# define COMPILER_VERSION_MAJOR DEC(__DECCXX_VER/10000000) -# define COMPILER_VERSION_MINOR DEC(__DECCXX_VER/100000 % 100) -# define COMPILER_VERSION_PATCH DEC(__DECCXX_VER % 10000) - -#elif defined(__IBMCPP__) -# if defined(__COMPILER_VER__) -# define COMPILER_ID "zOS" -# else -# if __IBMCPP__ >= 800 -# define COMPILER_ID "XL" -# else -# define COMPILER_ID "VisualAge" -# endif - /* __IBMCPP__ = VRP */ -# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) -# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) -# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10) -# endif - -#elif defined(__PGI) -# define COMPILER_ID "PGI" -# define COMPILER_VERSION_MAJOR DEC(__PGIC__) -# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) -# if defined(__PGIC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) -# endif - -#elif defined(_CRAYC) -# define COMPILER_ID "Cray" -# define COMPILER_VERSION_MAJOR DEC(_RELEASE) -# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR) - -#elif defined(__TI_COMPILER_VERSION__) -# define COMPILER_ID "TI" - /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ -# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) -# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) -# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000) - -#elif defined(__SCO_VERSION__) -# define COMPILER_ID "SCO" - -#elif defined(__GNUC__) -# define COMPILER_ID "GNU" -# define COMPILER_VERSION_MAJOR DEC(__GNUC__) -# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) -# if defined(__GNUC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) -# endif - -#elif defined(_MSC_VER) -# define COMPILER_ID "MSVC" - /* _MSC_VER = VVRR */ -# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) -# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) -# if defined(_MSC_FULL_VER) -# if _MSC_VER >= 1400 - /* _MSC_FULL_VER = VVRRPPPPP */ -# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) -# else - /* _MSC_FULL_VER = VVRRPPPP */ -# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) -# endif -# endif -# if defined(_MSC_BUILD) -# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) -# endif - -/* Analog VisualDSP++ >= 4.5.6 */ -#elif defined(__VISUALDSPVERSION__) -# define COMPILER_ID "ADSP" - /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ -# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) -# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) -# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) - -/* Analog VisualDSP++ < 4.5.6 */ -#elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) -# define COMPILER_ID "ADSP" - -/* IAR Systems compiler for embedded systems. - http://www.iar.com */ -#elif defined(__IAR_SYSTEMS_ICC__ ) || defined(__IAR_SYSTEMS_ICC) -# define COMPILER_ID "IAR" - -#elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION) -# define COMPILER_ID "MIPSpro" -# if defined(_SGI_COMPILER_VERSION) - /* _SGI_COMPILER_VERSION = VRP */ -# define COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100) -# define COMPILER_VERSION_MINOR DEC(_SGI_COMPILER_VERSION/10 % 10) -# define COMPILER_VERSION_PATCH DEC(_SGI_COMPILER_VERSION % 10) -# else - /* _COMPILER_VERSION = VRP */ -# define COMPILER_VERSION_MAJOR DEC(_COMPILER_VERSION/100) -# define COMPILER_VERSION_MINOR DEC(_COMPILER_VERSION/10 % 10) -# define COMPILER_VERSION_PATCH DEC(_COMPILER_VERSION % 10) -# endif - -/* These compilers are either not known or too old to define an - identification macro. Try to identify the platform and guess that - it is the native compiler. */ -#elif defined(__sgi) -# define COMPILER_ID "MIPSpro" - -#elif defined(__hpux) || defined(__hpua) -# define COMPILER_ID "HP" - -#else /* unknown compiler */ -# define COMPILER_ID "" - -#endif +@CMAKE_CXX_COMPILER_ID_CONTENT@ /* Construct the string literal in pieces to prevent the source from getting matched. Store it in a pointer rather than an array diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 17f27b3dc..ddaa8ef16 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -97,11 +97,88 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE) endfunction() +function(_readFile file) + include(${file}) + get_filename_component(name ${file} NAME_WE) + string(REGEX REPLACE "-.*" "" CompilerId ${name}) + set(_compiler_id_version_compute_${CompilerId} ${_compiler_id_version_compute} PARENT_SCOPE) + set(_compiler_id_pp_test_${CompilerId} ${_compiler_id_pp_test} PARENT_SCOPE) +endfunction() + #----------------------------------------------------------------------------- # Function to write the compiler id source file. 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) + + file(GLOB lang_files + "${CMAKE_ROOT}/Modules/Compiler/*-${lang}-DetermineCompiler.cmake") + + if (NOT lang STREQUAL Fortran) + file(GLOB non_lang_files + "${CMAKE_ROOT}/Modules/Compiler/*-${lang}-DetermineCompiler.cmake") + endif() + + set(files ${lang_files} ${non_lang_files}) + if (files) + foreach(file ${files}) + _readFile(${file}) + endforeach() + set(pp_if "#if") + set(CMAKE_CXX_COMPILER_ID_CONTENT "/* Version number components: V=Version, R=Revision, P=Patch + Version date components: YYYY=Year, MM=Month, DD=Day */\n") + + foreach(Id + Comeau + Intel + PathScale + AppleClang + Clang + Embarcadero + Borland + Watcom + OpenWatcom + SunPro + HP + Compaq + zOS + XL + VisualAge + PGI + Cray + TI + SCO + GNU + MSVC + ADSP + IAR + MIPSpro) + if (NOT _compiler_id_pp_test_${Id}) + message(FATAL_ERROR "No 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(CMAKE_CXX_COMPILER_ID_CONTENT "${CMAKE_CXX_COMPILER_ID_CONTENT}\n${id_content}") + set(pp_if "#elif") + endforeach() + + set(platform_compiler_detection " +/* These compilers are either not known or too old to define an + identification macro. Try to identify the platform and guess that + it is the native compiler. */ +#elif defined(__sgi) +# define COMPILER_ID \"MIPSpro\" + +#elif defined(__hpux) || defined(__hpua) +# define COMPILER_ID \"HP\" + +#else /* unknown compiler */ +# define COMPILER_ID \"\" + +#endif") + + set(CMAKE_CXX_COMPILER_ID_CONTENT "${CMAKE_CXX_COMPILER_ID_CONTENT}\n${platform_compiler_detection}") + endif() + unset(src_in CACHE) string(CONFIGURE "${ID_CONTENT_IN}" ID_CONTENT_OUT @ONLY) file(WRITE ${CMAKE_${lang}_COMPILER_ID_DIR}/${src} "${ID_CONTENT_OUT}") diff --git a/Modules/Compiler/ADSP-DetermineCompiler.cmake b/Modules/Compiler/ADSP-DetermineCompiler.cmake new file mode 100644 index 000000000..fc0fd6e11 --- /dev/null +++ b/Modules/Compiler/ADSP-DetermineCompiler.cmake @@ -0,0 +1,10 @@ + +set(_compiler_id_pp_test "defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)") + +set(_compiler_id_version_compute " +#if defined(__VISUALDSPVERSION__) + /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ +# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) +# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) +# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) +#endif") diff --git a/Modules/Compiler/AppleClang-DetermineCompiler.cmake b/Modules/Compiler/AppleClang-DetermineCompiler.cmake new file mode 100644 index 000000000..ca05eee88 --- /dev/null +++ b/Modules/Compiler/AppleClang-DetermineCompiler.cmake @@ -0,0 +1,7 @@ + +set(_compiler_id_pp_test "defined(__clang__) && defined(__apple_build_version__)") + +include("${CMAKE_CURRENT_LIST_DIR}/Clang-DetermineCompilerInternal.cmake") + +set(_compiler_id_version_compute "${_compiler_id_version_compute} +# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__)") diff --git a/Modules/Compiler/Borland-DetermineCompiler.cmake b/Modules/Compiler/Borland-DetermineCompiler.cmake new file mode 100644 index 000000000..8b468307e --- /dev/null +++ b/Modules/Compiler/Borland-DetermineCompiler.cmake @@ -0,0 +1,7 @@ + +set(_compiler_id_pp_test "defined(__BORLANDC__)") + +set(_compiler_id_version_compute " + /* __BORLANDC__ = 0xVRR */ +# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) +# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF)") diff --git a/Modules/Compiler/Clang-DetermineCompiler.cmake b/Modules/Compiler/Clang-DetermineCompiler.cmake new file mode 100644 index 000000000..89df1b6dc --- /dev/null +++ b/Modules/Compiler/Clang-DetermineCompiler.cmake @@ -0,0 +1,4 @@ + +set(_compiler_id_pp_test "defined(__clang__)") + +include("${CMAKE_CURRENT_LIST_DIR}/Clang-DetermineCompilerInternal.cmake") diff --git a/Modules/Compiler/Clang-DetermineCompilerInternal.cmake b/Modules/Compiler/Clang-DetermineCompilerInternal.cmake new file mode 100644 index 000000000..615032df3 --- /dev/null +++ b/Modules/Compiler/Clang-DetermineCompilerInternal.cmake @@ -0,0 +1,11 @@ + +set(_compiler_id_version_compute " +# define COMPILER_VERSION_MAJOR DEC(__clang_major__) +# define COMPILER_VERSION_MINOR DEC(__clang_minor__) +# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) +# if defined(_MSC_VER) +# define SIMULATE_ID \"MSVC\" + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif") diff --git a/Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake b/Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake new file mode 100644 index 000000000..78f26716e --- /dev/null +++ b/Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake @@ -0,0 +1,7 @@ + +set(_compiler_id_pp_test "defined(__COMO__)") + +set(_compiler_id_version_compute " + /* __COMO_VERSION__ = VRR */ +# define COMPILER_VERSION_MAJOR DEC(__COMO_VERSION__ / 100) +# define COMPILER_VERSION_MINOR DEC(__COMO_VERSION__ % 100)") diff --git a/Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake b/Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake new file mode 100644 index 000000000..2b09102a6 --- /dev/null +++ b/Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake @@ -0,0 +1,8 @@ + +set(_compiler_id_pp_test "defined(__DECCXX)") + +set(_compiler_id_version_compute " + /* __DECCXX_VER = VVRRTPPPP */ +# define COMPILER_VERSION_MAJOR DEC(__DECCXX_VER/10000000) +# define COMPILER_VERSION_MINOR DEC(__DECCXX_VER/100000 % 100) +# define COMPILER_VERSION_PATCH DEC(__DECCXX_VER % 10000)") diff --git a/Modules/Compiler/Cray-DetermineCompiler.cmake b/Modules/Compiler/Cray-DetermineCompiler.cmake new file mode 100644 index 000000000..cf55d2d19 --- /dev/null +++ b/Modules/Compiler/Cray-DetermineCompiler.cmake @@ -0,0 +1,6 @@ + +set(_compiler_id_pp_test "defined(_CRAYC)") + +set(_compiler_id_version_compute " +# define COMPILER_VERSION_MAJOR DEC(_RELEASE) +# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR)") diff --git a/Modules/Compiler/Embarcadero-DetermineCompiler.cmake b/Modules/Compiler/Embarcadero-DetermineCompiler.cmake new file mode 100644 index 000000000..4b8594076 --- /dev/null +++ b/Modules/Compiler/Embarcadero-DetermineCompiler.cmake @@ -0,0 +1,7 @@ + +set(_compiler_id_pp_test "defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__)") + +set(_compiler_id_version_compute " +# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) +# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) +# define COMPILER_VERSION_PATCH HEX(__CODEGEARC_VERSION__ & 0xFFFF)") diff --git a/Modules/Compiler/GNU-DetermineCompiler.cmake b/Modules/Compiler/GNU-DetermineCompiler.cmake new file mode 100644 index 000000000..abb19e737 --- /dev/null +++ b/Modules/Compiler/GNU-DetermineCompiler.cmake @@ -0,0 +1,9 @@ + +set(_compiler_id_pp_test "defined(__GNUC__)") + +set(_compiler_id_version_compute " +# define COMPILER_VERSION_MAJOR DEC(__GNUC__) +# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) +# if defined(__GNUC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) +# endif") diff --git a/Modules/Compiler/HP-CXX-DetermineCompiler.cmake b/Modules/Compiler/HP-CXX-DetermineCompiler.cmake new file mode 100644 index 000000000..2506e06cc --- /dev/null +++ b/Modules/Compiler/HP-CXX-DetermineCompiler.cmake @@ -0,0 +1,8 @@ + +set(_compiler_id_pp_test "defined(__HP_aCC)") + +set(_compiler_id_version_compute " + /* __HP_aCC = VVRRPP */ +# define COMPILER_VERSION_MAJOR DEC(__HP_aCC/10000) +# define COMPILER_VERSION_MINOR DEC(__HP_aCC/100 % 100) +# define COMPILER_VERSION_PATCH DEC(__HP_aCC % 100)") diff --git a/Modules/Compiler/IAR-DetermineCompiler.cmake b/Modules/Compiler/IAR-DetermineCompiler.cmake new file mode 100644 index 000000000..c39810a24 --- /dev/null +++ b/Modules/Compiler/IAR-DetermineCompiler.cmake @@ -0,0 +1,4 @@ + +# IAR Systems compiler for embedded systems. +# http://www.iar.com +set(_compiler_id_pp_test "defined(__IAR_SYSTEMS_ICC__ ) || defined(__IAR_SYSTEMS_ICC)") diff --git a/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake b/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake new file mode 100644 index 000000000..9db0663bd --- /dev/null +++ b/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake @@ -0,0 +1,6 @@ + +set(_compiler_id_version_compute " + /* __IBMCPP__ = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) +# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) +# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10)") diff --git a/Modules/Compiler/Intel-DetermineCompiler.cmake b/Modules/Compiler/Intel-DetermineCompiler.cmake new file mode 100644 index 000000000..6171ba961 --- /dev/null +++ b/Modules/Compiler/Intel-DetermineCompiler.cmake @@ -0,0 +1,22 @@ + +set(_compiler_id_pp_test "defined(__INTEL_COMPILER) || defined(__ICC)") + +set(_compiler_id_version_compute " + /* __INTEL_COMPILER = VRP */ +# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) +# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) +# if defined(__INTEL_COMPILER_UPDATE) +# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) +# else +# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) +# endif +# if defined(__INTEL_COMPILER_BUILD_DATE) + /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ +# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) +# endif +# if defined(_MSC_VER) +# define SIMULATE_ID \"MSVC\" + /* _MSC_VER = VVRR */ +# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# endif") diff --git a/Modules/Compiler/MIPSpro-DetermineCompiler.cmake b/Modules/Compiler/MIPSpro-DetermineCompiler.cmake new file mode 100644 index 000000000..12cf1dbd9 --- /dev/null +++ b/Modules/Compiler/MIPSpro-DetermineCompiler.cmake @@ -0,0 +1,15 @@ + +set(_compiler_id_pp_test "defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION)") + +set(_compiler_id_version_compute " +# if defined(_SGI_COMPILER_VERSION) + /* _SGI_COMPILER_VERSION = VRP */ +# define COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100) +# define COMPILER_VERSION_MINOR DEC(_SGI_COMPILER_VERSION/10 % 10) +# define COMPILER_VERSION_PATCH DEC(_SGI_COMPILER_VERSION % 10) +# else + /* _COMPILER_VERSION = VRP */ +# define COMPILER_VERSION_MAJOR DEC(_COMPILER_VERSION/100) +# define COMPILER_VERSION_MINOR DEC(_COMPILER_VERSION/10 % 10) +# define COMPILER_VERSION_PATCH DEC(_COMPILER_VERSION % 10) +# endif") diff --git a/Modules/Compiler/MSVC-DetermineCompiler.cmake b/Modules/Compiler/MSVC-DetermineCompiler.cmake new file mode 100644 index 000000000..342476a01 --- /dev/null +++ b/Modules/Compiler/MSVC-DetermineCompiler.cmake @@ -0,0 +1,19 @@ + +set(_compiler_id_pp_test "defined(_MSC_VER)") + +set(_compiler_id_version_compute " + /* _MSC_VER = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) +# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) +# if defined(_MSC_FULL_VER) +# if _MSC_VER >= 1400 + /* _MSC_FULL_VER = VVRRPPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) +# else + /* _MSC_FULL_VER = VVRRPPPP */ +# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) +# endif +# endif +# if defined(_MSC_BUILD) +# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) +# endif") diff --git a/Modules/Compiler/OpenWatcom-DetermineCompiler.cmake b/Modules/Compiler/OpenWatcom-DetermineCompiler.cmake new file mode 100644 index 000000000..97dd16c29 --- /dev/null +++ b/Modules/Compiler/OpenWatcom-DetermineCompiler.cmake @@ -0,0 +1,10 @@ + +set(_compiler_id_pp_test "defined(__WATCOMC__)") + +set(_compiler_id_version_compute " + /* __WATCOMC__ = VVRP + 1100 */ +# define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) +# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) +# if (__WATCOMC__ % 10) > 0 +# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) +# endif") diff --git a/Modules/Compiler/PGI-DetermineCompiler.cmake b/Modules/Compiler/PGI-DetermineCompiler.cmake new file mode 100644 index 000000000..6647f1507 --- /dev/null +++ b/Modules/Compiler/PGI-DetermineCompiler.cmake @@ -0,0 +1,9 @@ + +set(_compiler_id_pp_test "defined(__PGI)") + +set(_compiler_id_version_compute " +# define COMPILER_VERSION_MAJOR DEC(__PGIC__) +# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) +# if defined(__PGIC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) +# endif") diff --git a/Modules/Compiler/PathScale-DetermineCompiler.cmake b/Modules/Compiler/PathScale-DetermineCompiler.cmake new file mode 100644 index 000000000..40199e674 --- /dev/null +++ b/Modules/Compiler/PathScale-DetermineCompiler.cmake @@ -0,0 +1,9 @@ + +set(_compiler_id_pp_test "defined(__PATHCC__)") + +set(_compiler_id_version_compute " +# define COMPILER_VERSION_MAJOR DEC(__PATHCC__) +# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) +# if defined(__PATHCC_PATCHLEVEL__) +# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) +# endif") diff --git a/Modules/Compiler/SCO-DetermineCompiler.cmake b/Modules/Compiler/SCO-DetermineCompiler.cmake new file mode 100644 index 000000000..a44b22b71 --- /dev/null +++ b/Modules/Compiler/SCO-DetermineCompiler.cmake @@ -0,0 +1,2 @@ + +set(_compiler_id_pp_test "defined(__SCO_VERSION__)") diff --git a/Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake b/Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake new file mode 100644 index 000000000..044f0fa06 --- /dev/null +++ b/Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake @@ -0,0 +1,15 @@ + +set(_compiler_id_pp_test "defined(__SUNPRO_CC)") + +set(_compiler_id_version_compute " +# if __SUNPRO_CC >= 0x5100 + /* __SUNPRO_CC = 0xVRRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>12) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xFF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) +# else + /* __SUNPRO_CC = 0xVRP */ +# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>8) +# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xF) +# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) +# endif") diff --git a/Modules/Compiler/TI-DetermineCompiler.cmake b/Modules/Compiler/TI-DetermineCompiler.cmake new file mode 100644 index 000000000..d05e5bd3d --- /dev/null +++ b/Modules/Compiler/TI-DetermineCompiler.cmake @@ -0,0 +1,8 @@ + +set(_compiler_id_pp_test "defined(__TI_COMPILER_VERSION__)") + +set(_compiler_id_version_compute " + /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ +# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) +# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) +# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000)") diff --git a/Modules/Compiler/VisualAge-CXX-DetermineCompiler.cmake b/Modules/Compiler/VisualAge-CXX-DetermineCompiler.cmake new file mode 100644 index 000000000..cd5349968 --- /dev/null +++ b/Modules/Compiler/VisualAge-CXX-DetermineCompiler.cmake @@ -0,0 +1,4 @@ + +set(_compiler_id_pp_test "defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ < 800") + +include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-CXX-DetermineVersionInternal.cmake") diff --git a/Modules/Compiler/Watcom-DetermineCompiler.cmake b/Modules/Compiler/Watcom-DetermineCompiler.cmake new file mode 100644 index 000000000..2a082776f --- /dev/null +++ b/Modules/Compiler/Watcom-DetermineCompiler.cmake @@ -0,0 +1,10 @@ + +set(_compiler_id_pp_test "defined(__WATCOMC__) && __WATCOMC__ < 1200") + +set(_compiler_id_version_compute " + /* __WATCOMC__ = VVRR */ +# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) +# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) +# if (__WATCOMC__ % 10) > 0 +# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) +# endif") diff --git a/Modules/Compiler/XL-CXX-DetermineCompiler.cmake b/Modules/Compiler/XL-CXX-DetermineCompiler.cmake new file mode 100644 index 000000000..dffa4bc21 --- /dev/null +++ b/Modules/Compiler/XL-CXX-DetermineCompiler.cmake @@ -0,0 +1,4 @@ + +set(_compiler_id_pp_test "defined(__IBMCPP__) && !defined(__COMPILER_VER__) && __IBMCPP__ >= 800") + +include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-CXX-DetermineVersionInternal.cmake") diff --git a/Modules/Compiler/zOS-CXX-DetermineCompiler.cmake b/Modules/Compiler/zOS-CXX-DetermineCompiler.cmake new file mode 100644 index 000000000..a08ff5713 --- /dev/null +++ b/Modules/Compiler/zOS-CXX-DetermineCompiler.cmake @@ -0,0 +1,4 @@ + +set(_compiler_id_pp_test "defined(__IBMCPP__) && defined(__COMPILER_VER__)") + +include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-CXX-DetermineVersionInternal.cmake") From 9a083bce83cfa31192ad34ba504454f8087c4fce Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 23 Apr 2014 10:33:16 +0200 Subject: [PATCH 2/7] Project: Split the compiler id detection into a separate function. This can be extended with parameters to control the output and re-used in other contexts. --- Modules/CMakeCompilerIdDetection.cmake | 99 ++++++++++++++++++++++++++ Modules/CMakeDetermineCompilerId.cmake | 76 +------------------- 2 files changed, 101 insertions(+), 74 deletions(-) create mode 100644 Modules/CMakeCompilerIdDetection.cmake diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake new file mode 100644 index 000000000..eee1337fc --- /dev/null +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -0,0 +1,99 @@ + +#============================================================================= +# Copyright 2014 Stephen Kelly +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +function(_readFile file) + include(${file}) + get_filename_component(name ${file} NAME_WE) + string(REGEX REPLACE "-.*" "" CompilerId ${name}) + set(_compiler_id_version_compute_${CompilerId} ${_compiler_id_version_compute} PARENT_SCOPE) + set(_compiler_id_pp_test_${CompilerId} ${_compiler_id_pp_test} PARENT_SCOPE) +endfunction() + +function(compiler_id_detection outvar lang) + + file(GLOB lang_files + "${CMAKE_ROOT}/Modules/Compiler/*-${lang}-DetermineCompiler.cmake") + + if (NOT lang STREQUAL Fortran) + file(GLOB non_lang_files + "${CMAKE_ROOT}/Modules/Compiler/*-DetermineCompiler.cmake") + endif() + + set(files ${lang_files} ${non_lang_files}) + if (files) + foreach(file ${files}) + _readFile(${file}) + endforeach() + + set(ordered_compilers + # Order is relevant here. For example, compilers which pretend to be + # GCC must appear before the actual GCC. + Comeau + Intel + PathScale + AppleClang + Clang + Embarcadero + Borland + Watcom + OpenWatcom + SunPro + HP + Compaq + zOS + XL + VisualAge + PGI + Cray + TI + SCO + GNU + MSVC + ADSP + IAR + MIPSpro) + + set(pp_if "#if") + 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") + + 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(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${id_content}") + set(pp_if "#elif") + endforeach() + + set(platform_compiler_detection " +/* These compilers are either not known or too old to define an + identification macro. Try to identify the platform and guess that + it is the native compiler. */ +#elif defined(__sgi) +# define COMPILER_ID \"MIPSpro\" + +#elif defined(__hpux) || defined(__hpua) +# define COMPILER_ID \"HP\" + +#else /* unknown compiler */ +# define COMPILER_ID \"\" + +#endif") + + set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${platform_compiler_detection}") + endif() + + set(${outvar} ${CMAKE_${lang}_COMPILER_ID_CONTENT} PARENT_SCOPE) +endfunction() diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index ddaa8ef16..94c2e5052 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -97,13 +97,7 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) set(CMAKE_${lang}_SIMULATE_VERSION "${CMAKE_${lang}_SIMULATE_VERSION}" PARENT_SCOPE) endfunction() -function(_readFile file) - include(${file}) - get_filename_component(name ${file} NAME_WE) - string(REGEX REPLACE "-.*" "" CompilerId ${name}) - set(_compiler_id_version_compute_${CompilerId} ${_compiler_id_version_compute} PARENT_SCOPE) - set(_compiler_id_pp_test_${CompilerId} ${_compiler_id_pp_test} PARENT_SCOPE) -endfunction() +include(CMakeCompilerIdDetection) #----------------------------------------------------------------------------- # Function to write the compiler id source file. @@ -111,73 +105,7 @@ 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) - file(GLOB lang_files - "${CMAKE_ROOT}/Modules/Compiler/*-${lang}-DetermineCompiler.cmake") - - if (NOT lang STREQUAL Fortran) - file(GLOB non_lang_files - "${CMAKE_ROOT}/Modules/Compiler/*-${lang}-DetermineCompiler.cmake") - endif() - - set(files ${lang_files} ${non_lang_files}) - if (files) - foreach(file ${files}) - _readFile(${file}) - endforeach() - set(pp_if "#if") - set(CMAKE_CXX_COMPILER_ID_CONTENT "/* Version number components: V=Version, R=Revision, P=Patch - Version date components: YYYY=Year, MM=Month, DD=Day */\n") - - foreach(Id - Comeau - Intel - PathScale - AppleClang - Clang - Embarcadero - Borland - Watcom - OpenWatcom - SunPro - HP - Compaq - zOS - XL - VisualAge - PGI - Cray - TI - SCO - GNU - MSVC - ADSP - IAR - MIPSpro) - if (NOT _compiler_id_pp_test_${Id}) - message(FATAL_ERROR "No 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(CMAKE_CXX_COMPILER_ID_CONTENT "${CMAKE_CXX_COMPILER_ID_CONTENT}\n${id_content}") - set(pp_if "#elif") - endforeach() - - set(platform_compiler_detection " -/* These compilers are either not known or too old to define an - identification macro. Try to identify the platform and guess that - it is the native compiler. */ -#elif defined(__sgi) -# define COMPILER_ID \"MIPSpro\" - -#elif defined(__hpux) || defined(__hpua) -# define COMPILER_ID \"HP\" - -#else /* unknown compiler */ -# define COMPILER_ID \"\" - -#endif") - - set(CMAKE_CXX_COMPILER_ID_CONTENT "${CMAKE_CXX_COMPILER_ID_CONTENT}\n${platform_compiler_detection}") - endif() + compiler_id_detection(CMAKE_${lang}_COMPILER_ID_CONTENT ${lang}) unset(src_in CACHE) string(CONFIGURE "${ID_CONTENT_IN}" ID_CONTENT_OUT @ONLY) From 36ed5894840f40f6859710d44be607c929e5d38c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 23 Apr 2014 10:46:47 +0200 Subject: [PATCH 3/7] 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) From 30a99f5c063d1d66a40b57554a7beec5d8fbf54c Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 23 Apr 2014 10:51:33 +0200 Subject: [PATCH 4/7] CompilerId: Add option to generate compiler-id-specific defines. --- Modules/CMakeCompilerIdDetection.cmake | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index 5df525fe1..4316c4161 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -38,7 +38,7 @@ function(compiler_id_detection outvar lang) _readFile(${file}) endforeach() - set(options ID_STRING VERSION_STRINGS) + set(options ID_STRING VERSION_STRINGS ID_DEFINE) cmake_parse_arguments(CID "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if (CID_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unrecognized arguments: \"${CID_UNPARSED_ARGUMENTS}\"") @@ -72,9 +72,15 @@ function(compiler_id_detection outvar lang) IAR MIPSpro) + if(CID_ID_DEFINE) + foreach(Id ${ordered_compilers}) + set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}# define COMPILER_IS_${Id} 0\n") + endforeach() + endif() + set(pp_if "#if") if (CID_VERSION_STRINGS) - set(CMAKE_${lang}_COMPILER_ID_CONTENT "/* Version number components: V=Version, R=Revision, P=Patch + set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n/* Version number components: V=Version, R=Revision, P=Patch Version date components: YYYY=Year, MM=Month, DD=Day */\n") endif() @@ -86,6 +92,10 @@ function(compiler_id_detection outvar lang) if (CID_ID_STRING) set(id_content "${id_content}# define COMPILER_ID \"${Id}\"") endif() + if (CID_ID_DEFINE) + set(id_content "${id_content}# undef COMPILER_IS_${Id}\n") + set(id_content "${id_content}# define COMPILER_IS_${Id} 1\n") + endif() if (CID_VERSION_STRINGS) set(id_content "${id_content}${_compiler_id_version_compute_${Id}}\n") endif() From 23f451bb33c384d19ec29934b2811e081ff3e685 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 23 Apr 2014 12:10:04 +0200 Subject: [PATCH 5/7] CompilerId: Guard the platform-default compiler code with a parameter. --- Modules/CMakeCompilerIdDetection.cmake | 12 ++++++------ Modules/CMakeDetermineCompilerId.cmake | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index 4316c4161..13e420c17 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -38,7 +38,7 @@ function(compiler_id_detection outvar lang) _readFile(${file}) endforeach() - set(options ID_STRING VERSION_STRINGS ID_DEFINE) + set(options ID_STRING VERSION_STRINGS ID_DEFINE PLATFORM_DEFAULT_COMPILER) cmake_parse_arguments(CID "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if (CID_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unrecognized arguments: \"${CID_UNPARSED_ARGUMENTS}\"") @@ -103,7 +103,8 @@ function(compiler_id_detection outvar lang) set(pp_if "#elif") endforeach() - set(platform_compiler_detection " + if (CID_PLATFORM_DEFAULT_COMPILER) + set(platform_compiler_detection " /* These compilers are either not known or too old to define an identification macro. Try to identify the platform and guess that it is the native compiler. */ @@ -114,11 +115,10 @@ function(compiler_id_detection outvar lang) # define COMPILER_ID \"HP\" #else /* unknown compiler */ -# define COMPILER_ID \"\" +# define COMPILER_ID \"\"") + endif() -#endif") - - set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${platform_compiler_detection}") + set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${platform_compiler_detection}\n#endif") endif() set(${outvar} ${CMAKE_${lang}_COMPILER_ID_CONTENT} PARENT_SCOPE) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 712b7488b..025d29656 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -108,6 +108,7 @@ function(CMAKE_DETERMINE_COMPILER_ID_WRITE lang src) compiler_id_detection(CMAKE_${lang}_COMPILER_ID_CONTENT ${lang} ID_STRING VERSION_STRINGS + PLATFORM_DEFAULT_COMPILER ) unset(src_in CACHE) From 8896501b236258f6908a59eb81f49983892bdcff Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 23 Apr 2014 11:00:28 +0200 Subject: [PATCH 6/7] CompilerId: Allow specifying a prefix for preprocessor defines. --- Modules/CMakeCompilerIdDetection.cmake | 19 +++++++++++-------- Modules/Compiler/ADSP-DetermineCompiler.cmake | 6 +++--- .../AppleClang-DetermineCompiler.cmake | 2 +- .../Compiler/Borland-DetermineCompiler.cmake | 4 ++-- .../Clang-DetermineCompilerInternal.cmake | 12 ++++++------ .../Comeau-CXX-DetermineCompiler.cmake | 4 ++-- .../Compaq-CXX-DetermineCompiler.cmake | 6 +++--- Modules/Compiler/Cray-DetermineCompiler.cmake | 4 ++-- .../Embarcadero-DetermineCompiler.cmake | 6 +++--- Modules/Compiler/GNU-DetermineCompiler.cmake | 6 +++--- .../Compiler/HP-CXX-DetermineCompiler.cmake | 6 +++--- .../IBMCPP-CXX-DetermineVersionInternal.cmake | 6 +++--- .../Compiler/Intel-DetermineCompiler.cmake | 16 ++++++++-------- .../Compiler/MIPSpro-DetermineCompiler.cmake | 12 ++++++------ Modules/Compiler/MSVC-DetermineCompiler.cmake | 10 +++++----- .../OpenWatcom-DetermineCompiler.cmake | 6 +++--- Modules/Compiler/PGI-DetermineCompiler.cmake | 6 +++--- .../PathScale-DetermineCompiler.cmake | 6 +++--- .../SunPro-CXX-DetermineCompiler.cmake | 12 ++++++------ Modules/Compiler/TI-DetermineCompiler.cmake | 6 +++--- .../Compiler/Watcom-DetermineCompiler.cmake | 6 +++--- 21 files changed, 82 insertions(+), 79 deletions(-) diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index 13e420c17..f0e39ad37 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -39,6 +39,7 @@ function(compiler_id_detection outvar lang) endforeach() set(options ID_STRING VERSION_STRINGS ID_DEFINE PLATFORM_DEFAULT_COMPILER) + set(oneValueArgs PREFIX) cmake_parse_arguments(CID "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) if (CID_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unrecognized arguments: \"${CID_UNPARSED_ARGUMENTS}\"") @@ -74,7 +75,7 @@ function(compiler_id_detection outvar lang) if(CID_ID_DEFINE) foreach(Id ${ordered_compilers}) - set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}# define COMPILER_IS_${Id} 0\n") + set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}# define ${CID_PREFIX}COMPILER_IS_${Id} 0\n") endforeach() endif() @@ -90,14 +91,16 @@ function(compiler_id_detection outvar lang) endif() set(id_content "${pp_if} ${_compiler_id_pp_test_${Id}}\n") if (CID_ID_STRING) - set(id_content "${id_content}# define COMPILER_ID \"${Id}\"") + set(id_content "${id_content}# define ${CID_PREFIX}COMPILER_ID \"${Id}\"") endif() if (CID_ID_DEFINE) - set(id_content "${id_content}# undef COMPILER_IS_${Id}\n") - set(id_content "${id_content}# define COMPILER_IS_${Id} 1\n") + set(id_content "${id_content}# undef ${CID_PREFIX}COMPILER_IS_${Id}\n") + set(id_content "${id_content}# define ${CID_PREFIX}COMPILER_IS_${Id} 1\n") endif() if (CID_VERSION_STRINGS) - set(id_content "${id_content}${_compiler_id_version_compute_${Id}}\n") + set(PREFIX ${CID_PREFIX}) + string(CONFIGURE "${_compiler_id_version_compute_${Id}}" VERSION_BLOCK @ONLY) + set(id_content "${id_content}${VERSION_BLOCK}\n") endif() set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${id_content}") set(pp_if "#elif") @@ -109,13 +112,13 @@ function(compiler_id_detection outvar lang) identification macro. Try to identify the platform and guess that it is the native compiler. */ #elif defined(__sgi) -# define COMPILER_ID \"MIPSpro\" +# define ${CID_PREFIX}COMPILER_ID \"MIPSpro\" #elif defined(__hpux) || defined(__hpua) -# define COMPILER_ID \"HP\" +# define ${CID_PREFIX}COMPILER_ID \"HP\" #else /* unknown compiler */ -# define COMPILER_ID \"\"") +# define ${CID_PREFIX}COMPILER_ID \"\"") endif() set(CMAKE_${lang}_COMPILER_ID_CONTENT "${CMAKE_${lang}_COMPILER_ID_CONTENT}\n${platform_compiler_detection}\n#endif") diff --git a/Modules/Compiler/ADSP-DetermineCompiler.cmake b/Modules/Compiler/ADSP-DetermineCompiler.cmake index fc0fd6e11..0b5af0d04 100644 --- a/Modules/Compiler/ADSP-DetermineCompiler.cmake +++ b/Modules/Compiler/ADSP-DetermineCompiler.cmake @@ -4,7 +4,7 @@ set(_compiler_id_pp_test "defined(__VISUALDSPVERSION__) || defined(__ADSPBLACKFI set(_compiler_id_version_compute " #if defined(__VISUALDSPVERSION__) /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ -# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) -# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) -# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) +# define @PREFIX@COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) +# define @PREFIX@COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) +# define @PREFIX@COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) #endif") diff --git a/Modules/Compiler/AppleClang-DetermineCompiler.cmake b/Modules/Compiler/AppleClang-DetermineCompiler.cmake index ca05eee88..d293b7b8b 100644 --- a/Modules/Compiler/AppleClang-DetermineCompiler.cmake +++ b/Modules/Compiler/AppleClang-DetermineCompiler.cmake @@ -4,4 +4,4 @@ set(_compiler_id_pp_test "defined(__clang__) && defined(__apple_build_version__) include("${CMAKE_CURRENT_LIST_DIR}/Clang-DetermineCompilerInternal.cmake") set(_compiler_id_version_compute "${_compiler_id_version_compute} -# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__)") +# define @PREFIX@COMPILER_VERSION_TWEAK DEC(__apple_build_version__)") diff --git a/Modules/Compiler/Borland-DetermineCompiler.cmake b/Modules/Compiler/Borland-DetermineCompiler.cmake index 8b468307e..2e8a94868 100644 --- a/Modules/Compiler/Borland-DetermineCompiler.cmake +++ b/Modules/Compiler/Borland-DetermineCompiler.cmake @@ -3,5 +3,5 @@ set(_compiler_id_pp_test "defined(__BORLANDC__)") set(_compiler_id_version_compute " /* __BORLANDC__ = 0xVRR */ -# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) -# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF)") +# define @PREFIX@COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) +# define @PREFIX@COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF)") diff --git a/Modules/Compiler/Clang-DetermineCompilerInternal.cmake b/Modules/Compiler/Clang-DetermineCompilerInternal.cmake index 615032df3..9a37a637b 100644 --- a/Modules/Compiler/Clang-DetermineCompilerInternal.cmake +++ b/Modules/Compiler/Clang-DetermineCompilerInternal.cmake @@ -1,11 +1,11 @@ set(_compiler_id_version_compute " -# define COMPILER_VERSION_MAJOR DEC(__clang_major__) -# define COMPILER_VERSION_MINOR DEC(__clang_minor__) -# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__clang_major__) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__clang_minor__) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) # if defined(_MSC_VER) -# define SIMULATE_ID \"MSVC\" +# define @PREFIX@SIMULATE_ID \"MSVC\" /* _MSC_VER = VVRR */ -# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) -# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# define @PREFIX@SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define @PREFIX@SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) # endif") diff --git a/Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake b/Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake index 78f26716e..e4def4d65 100644 --- a/Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake +++ b/Modules/Compiler/Comeau-CXX-DetermineCompiler.cmake @@ -3,5 +3,5 @@ set(_compiler_id_pp_test "defined(__COMO__)") set(_compiler_id_version_compute " /* __COMO_VERSION__ = VRR */ -# define COMPILER_VERSION_MAJOR DEC(__COMO_VERSION__ / 100) -# define COMPILER_VERSION_MINOR DEC(__COMO_VERSION__ % 100)") +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__COMO_VERSION__ / 100) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__COMO_VERSION__ % 100)") diff --git a/Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake b/Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake index 2b09102a6..5855c24e2 100644 --- a/Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake +++ b/Modules/Compiler/Compaq-CXX-DetermineCompiler.cmake @@ -3,6 +3,6 @@ set(_compiler_id_pp_test "defined(__DECCXX)") set(_compiler_id_version_compute " /* __DECCXX_VER = VVRRTPPPP */ -# define COMPILER_VERSION_MAJOR DEC(__DECCXX_VER/10000000) -# define COMPILER_VERSION_MINOR DEC(__DECCXX_VER/100000 % 100) -# define COMPILER_VERSION_PATCH DEC(__DECCXX_VER % 10000)") +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__DECCXX_VER/10000000) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__DECCXX_VER/100000 % 100) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__DECCXX_VER % 10000)") diff --git a/Modules/Compiler/Cray-DetermineCompiler.cmake b/Modules/Compiler/Cray-DetermineCompiler.cmake index cf55d2d19..6e4eaf9c0 100644 --- a/Modules/Compiler/Cray-DetermineCompiler.cmake +++ b/Modules/Compiler/Cray-DetermineCompiler.cmake @@ -2,5 +2,5 @@ set(_compiler_id_pp_test "defined(_CRAYC)") set(_compiler_id_version_compute " -# define COMPILER_VERSION_MAJOR DEC(_RELEASE) -# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR)") +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(_RELEASE) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR)") diff --git a/Modules/Compiler/Embarcadero-DetermineCompiler.cmake b/Modules/Compiler/Embarcadero-DetermineCompiler.cmake index 4b8594076..f52d79b3e 100644 --- a/Modules/Compiler/Embarcadero-DetermineCompiler.cmake +++ b/Modules/Compiler/Embarcadero-DetermineCompiler.cmake @@ -2,6 +2,6 @@ set(_compiler_id_pp_test "defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__)") set(_compiler_id_version_compute " -# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) -# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) -# define COMPILER_VERSION_PATCH HEX(__CODEGEARC_VERSION__ & 0xFFFF)") +# define @PREFIX@COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) +# define @PREFIX@COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) +# define @PREFIX@COMPILER_VERSION_PATCH HEX(__CODEGEARC_VERSION__ & 0xFFFF)") diff --git a/Modules/Compiler/GNU-DetermineCompiler.cmake b/Modules/Compiler/GNU-DetermineCompiler.cmake index abb19e737..f0c25dd97 100644 --- a/Modules/Compiler/GNU-DetermineCompiler.cmake +++ b/Modules/Compiler/GNU-DetermineCompiler.cmake @@ -2,8 +2,8 @@ set(_compiler_id_pp_test "defined(__GNUC__)") set(_compiler_id_version_compute " -# define COMPILER_VERSION_MAJOR DEC(__GNUC__) -# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__GNUC__) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) # if defined(__GNUC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) # endif") diff --git a/Modules/Compiler/HP-CXX-DetermineCompiler.cmake b/Modules/Compiler/HP-CXX-DetermineCompiler.cmake index 2506e06cc..699949231 100644 --- a/Modules/Compiler/HP-CXX-DetermineCompiler.cmake +++ b/Modules/Compiler/HP-CXX-DetermineCompiler.cmake @@ -3,6 +3,6 @@ set(_compiler_id_pp_test "defined(__HP_aCC)") set(_compiler_id_version_compute " /* __HP_aCC = VVRRPP */ -# define COMPILER_VERSION_MAJOR DEC(__HP_aCC/10000) -# define COMPILER_VERSION_MINOR DEC(__HP_aCC/100 % 100) -# define COMPILER_VERSION_PATCH DEC(__HP_aCC % 100)") +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__HP_aCC/10000) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__HP_aCC/100 % 100) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__HP_aCC % 100)") diff --git a/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake b/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake index 9db0663bd..f673d7261 100644 --- a/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake +++ b/Modules/Compiler/IBMCPP-CXX-DetermineVersionInternal.cmake @@ -1,6 +1,6 @@ set(_compiler_id_version_compute " /* __IBMCPP__ = VRP */ -# define COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) -# define COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) -# define COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10)") +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__IBMCPP__/100) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__IBMCPP__/10 % 10) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__IBMCPP__ % 10)") diff --git a/Modules/Compiler/Intel-DetermineCompiler.cmake b/Modules/Compiler/Intel-DetermineCompiler.cmake index 6171ba961..6fada1cd5 100644 --- a/Modules/Compiler/Intel-DetermineCompiler.cmake +++ b/Modules/Compiler/Intel-DetermineCompiler.cmake @@ -3,20 +3,20 @@ set(_compiler_id_pp_test "defined(__INTEL_COMPILER) || defined(__ICC)") set(_compiler_id_version_compute " /* __INTEL_COMPILER = VRP */ -# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) -# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) # if defined(__INTEL_COMPILER_UPDATE) -# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) # else -# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) # endif # if defined(__INTEL_COMPILER_BUILD_DATE) /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ -# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) +# define @PREFIX@COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) # endif # if defined(_MSC_VER) -# define SIMULATE_ID \"MSVC\" +# define @PREFIX@SIMULATE_ID \"MSVC\" /* _MSC_VER = VVRR */ -# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) -# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) +# define @PREFIX@SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) +# define @PREFIX@SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) # endif") diff --git a/Modules/Compiler/MIPSpro-DetermineCompiler.cmake b/Modules/Compiler/MIPSpro-DetermineCompiler.cmake index 12cf1dbd9..31eb34524 100644 --- a/Modules/Compiler/MIPSpro-DetermineCompiler.cmake +++ b/Modules/Compiler/MIPSpro-DetermineCompiler.cmake @@ -4,12 +4,12 @@ set(_compiler_id_pp_test "defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VE set(_compiler_id_version_compute " # if defined(_SGI_COMPILER_VERSION) /* _SGI_COMPILER_VERSION = VRP */ -# define COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100) -# define COMPILER_VERSION_MINOR DEC(_SGI_COMPILER_VERSION/10 % 10) -# define COMPILER_VERSION_PATCH DEC(_SGI_COMPILER_VERSION % 10) +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(_SGI_COMPILER_VERSION/10 % 10) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(_SGI_COMPILER_VERSION % 10) # else /* _COMPILER_VERSION = VRP */ -# define COMPILER_VERSION_MAJOR DEC(_COMPILER_VERSION/100) -# define COMPILER_VERSION_MINOR DEC(_COMPILER_VERSION/10 % 10) -# define COMPILER_VERSION_PATCH DEC(_COMPILER_VERSION % 10) +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(_COMPILER_VERSION/100) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(_COMPILER_VERSION/10 % 10) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(_COMPILER_VERSION % 10) # endif") diff --git a/Modules/Compiler/MSVC-DetermineCompiler.cmake b/Modules/Compiler/MSVC-DetermineCompiler.cmake index 342476a01..d462d0711 100644 --- a/Modules/Compiler/MSVC-DetermineCompiler.cmake +++ b/Modules/Compiler/MSVC-DetermineCompiler.cmake @@ -3,17 +3,17 @@ set(_compiler_id_pp_test "defined(_MSC_VER)") set(_compiler_id_version_compute " /* _MSC_VER = VVRR */ -# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) -# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) # if defined(_MSC_FULL_VER) # if _MSC_VER >= 1400 /* _MSC_FULL_VER = VVRRPPPPP */ -# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) # else /* _MSC_FULL_VER = VVRRPPPP */ -# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) # endif # endif # if defined(_MSC_BUILD) -# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) +# define @PREFIX@COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) # endif") diff --git a/Modules/Compiler/OpenWatcom-DetermineCompiler.cmake b/Modules/Compiler/OpenWatcom-DetermineCompiler.cmake index 97dd16c29..6d416c191 100644 --- a/Modules/Compiler/OpenWatcom-DetermineCompiler.cmake +++ b/Modules/Compiler/OpenWatcom-DetermineCompiler.cmake @@ -3,8 +3,8 @@ set(_compiler_id_pp_test "defined(__WATCOMC__)") set(_compiler_id_version_compute " /* __WATCOMC__ = VVRP + 1100 */ -# define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) -# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) +# define @PREFIX@COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) +# define @PREFIX@COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) # if (__WATCOMC__ % 10) > 0 -# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) # endif") diff --git a/Modules/Compiler/PGI-DetermineCompiler.cmake b/Modules/Compiler/PGI-DetermineCompiler.cmake index 6647f1507..8e68bd637 100644 --- a/Modules/Compiler/PGI-DetermineCompiler.cmake +++ b/Modules/Compiler/PGI-DetermineCompiler.cmake @@ -2,8 +2,8 @@ set(_compiler_id_pp_test "defined(__PGI)") set(_compiler_id_version_compute " -# define COMPILER_VERSION_MAJOR DEC(__PGIC__) -# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__PGIC__) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) # if defined(__PGIC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) # endif") diff --git a/Modules/Compiler/PathScale-DetermineCompiler.cmake b/Modules/Compiler/PathScale-DetermineCompiler.cmake index 40199e674..3335e260e 100644 --- a/Modules/Compiler/PathScale-DetermineCompiler.cmake +++ b/Modules/Compiler/PathScale-DetermineCompiler.cmake @@ -2,8 +2,8 @@ set(_compiler_id_pp_test "defined(__PATHCC__)") set(_compiler_id_version_compute " -# define COMPILER_VERSION_MAJOR DEC(__PATHCC__) -# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__PATHCC__) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) # if defined(__PATHCC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) # endif") diff --git a/Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake b/Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake index 044f0fa06..0a48cc677 100644 --- a/Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake +++ b/Modules/Compiler/SunPro-CXX-DetermineCompiler.cmake @@ -4,12 +4,12 @@ set(_compiler_id_pp_test "defined(__SUNPRO_CC)") set(_compiler_id_version_compute " # if __SUNPRO_CC >= 0x5100 /* __SUNPRO_CC = 0xVRRP */ -# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>12) -# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xFF) -# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) +# define @PREFIX@COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>12) +# define @PREFIX@COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xFF) +# define @PREFIX@COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) # else /* __SUNPRO_CC = 0xVRP */ -# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>8) -# define COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xF) -# define COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) +# define @PREFIX@COMPILER_VERSION_MAJOR HEX(__SUNPRO_CC>>8) +# define @PREFIX@COMPILER_VERSION_MINOR HEX(__SUNPRO_CC>>4 & 0xF) +# define @PREFIX@COMPILER_VERSION_PATCH HEX(__SUNPRO_CC & 0xF) # endif") diff --git a/Modules/Compiler/TI-DetermineCompiler.cmake b/Modules/Compiler/TI-DetermineCompiler.cmake index d05e5bd3d..1856c9b5a 100644 --- a/Modules/Compiler/TI-DetermineCompiler.cmake +++ b/Modules/Compiler/TI-DetermineCompiler.cmake @@ -3,6 +3,6 @@ set(_compiler_id_pp_test "defined(__TI_COMPILER_VERSION__)") set(_compiler_id_version_compute " /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ -# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) -# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) -# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000)") +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000)") diff --git a/Modules/Compiler/Watcom-DetermineCompiler.cmake b/Modules/Compiler/Watcom-DetermineCompiler.cmake index 2a082776f..cc59abfdc 100644 --- a/Modules/Compiler/Watcom-DetermineCompiler.cmake +++ b/Modules/Compiler/Watcom-DetermineCompiler.cmake @@ -3,8 +3,8 @@ set(_compiler_id_pp_test "defined(__WATCOMC__) && __WATCOMC__ < 1200") set(_compiler_id_version_compute " /* __WATCOMC__ = VVRR */ -# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) -# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) +# define @PREFIX@COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) # if (__WATCOMC__ % 10) > 0 -# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) # endif") From 3b59f8b7c68127c649fd72983e6f0a24cbb51427 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 7 May 2014 12:25:39 +0200 Subject: [PATCH 7/7] Project: Refactor C compiler determination into multiple files. --- Modules/CMakeCCompilerId.c.in | 225 +----------------- Modules/CMakeCompilerIdDetection.cmake | 41 +++- .../Compiler/Compaq-C-DetermineCompiler.cmake | 8 + Modules/Compiler/HP-C-DetermineCompiler.cmake | 8 + .../IBMCPP-C-DetermineVersionInternal.cmake | 6 + .../Compiler/SDCC-C-DetermineCompiler.cmake | 10 + .../Compiler/SunPro-C-DetermineCompiler.cmake | 15 ++ .../Compiler/TinyCC-C-DetermineCompiler.cmake | 2 + .../VisualAge-C-DetermineCompiler.cmake | 4 + Modules/Compiler/XL-C-DetermineCompiler.cmake | 4 + .../Compiler/zOS-C-DetermineCompiler.cmake | 4 + 11 files changed, 94 insertions(+), 233 deletions(-) create mode 100644 Modules/Compiler/Compaq-C-DetermineCompiler.cmake create mode 100644 Modules/Compiler/HP-C-DetermineCompiler.cmake create mode 100644 Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake create mode 100644 Modules/Compiler/SDCC-C-DetermineCompiler.cmake create mode 100644 Modules/Compiler/SunPro-C-DetermineCompiler.cmake create mode 100644 Modules/Compiler/TinyCC-C-DetermineCompiler.cmake create mode 100644 Modules/Compiler/VisualAge-C-DetermineCompiler.cmake create mode 100644 Modules/Compiler/XL-C-DetermineCompiler.cmake create mode 100644 Modules/Compiler/zOS-C-DetermineCompiler.cmake diff --git a/Modules/CMakeCCompilerId.c.in b/Modules/CMakeCCompilerId.c.in index 78d7c4721..0221cbd46 100644 --- a/Modules/CMakeCCompilerId.c.in +++ b/Modules/CMakeCCompilerId.c.in @@ -2,234 +2,11 @@ # error "A C++ compiler has been selected for C." #endif -/* Version number components: V=Version, R=Revision, P=Patch - Version date components: YYYY=Year, MM=Month, DD=Day */ - #if defined(__18CXX) # define ID_VOID_MAIN #endif -#if defined(__INTEL_COMPILER) || defined(__ICC) -# define COMPILER_ID "Intel" - /* __INTEL_COMPILER = VRP */ -# define COMPILER_VERSION_MAJOR DEC(__INTEL_COMPILER/100) -# define COMPILER_VERSION_MINOR DEC(__INTEL_COMPILER/10 % 10) -# if defined(__INTEL_COMPILER_UPDATE) -# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER_UPDATE) -# else -# define COMPILER_VERSION_PATCH DEC(__INTEL_COMPILER % 10) -# endif -# if defined(__INTEL_COMPILER_BUILD_DATE) - /* __INTEL_COMPILER_BUILD_DATE = YYYYMMDD */ -# define COMPILER_VERSION_TWEAK DEC(__INTEL_COMPILER_BUILD_DATE) -# endif -# if defined(_MSC_VER) -# define SIMULATE_ID "MSVC" - /* _MSC_VER = VVRR */ -# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) -# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) -# endif - -#elif defined(__PATHCC__) -# define COMPILER_ID "PathScale" -# define COMPILER_VERSION_MAJOR DEC(__PATHCC__) -# define COMPILER_VERSION_MINOR DEC(__PATHCC_MINOR__) -# if defined(__PATHCC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__PATHCC_PATCHLEVEL__) -# endif - -#elif defined(__clang__) -# if defined(__apple_build_version__) -# define COMPILER_ID "AppleClang" -# define COMPILER_VERSION_TWEAK DEC(__apple_build_version__) -# else -# define COMPILER_ID "Clang" -# endif -# define COMPILER_VERSION_MAJOR DEC(__clang_major__) -# define COMPILER_VERSION_MINOR DEC(__clang_minor__) -# define COMPILER_VERSION_PATCH DEC(__clang_patchlevel__) -# if defined(_MSC_VER) -# define SIMULATE_ID "MSVC" - /* _MSC_VER = VVRR */ -# define SIMULATE_VERSION_MAJOR DEC(_MSC_VER / 100) -# define SIMULATE_VERSION_MINOR DEC(_MSC_VER % 100) -# endif - -#elif defined(__BORLANDC__) && defined(__CODEGEARC_VERSION__) -# define COMPILER_ID "Embarcadero" -# define COMPILER_VERSION_MAJOR HEX(__CODEGEARC_VERSION__>>24 & 0x00FF) -# define COMPILER_VERSION_MINOR HEX(__CODEGEARC_VERSION__>>16 & 0x00FF) -# define COMPILER_VERSION_PATCH HEX(__CODEGEARC_VERSION__ & 0xFFFF) - -#elif defined(__BORLANDC__) -# define COMPILER_ID "Borland" - /* __BORLANDC__ = 0xVRR */ -# define COMPILER_VERSION_MAJOR HEX(__BORLANDC__>>8) -# define COMPILER_VERSION_MINOR HEX(__BORLANDC__ & 0xFF) - -#elif defined(__WATCOMC__) -# if __WATCOMC__ < 1200 -# define COMPILER_ID "Watcom" - /* __WATCOMC__ = VVRP */ -# define COMPILER_VERSION_MAJOR DEC(__WATCOMC__ / 100) -# else -# define COMPILER_ID "OpenWatcom" - /* __WATCOMC__ = VVRP + 1100 */ -# define COMPILER_VERSION_MAJOR DEC((__WATCOMC__ - 1100) / 100) -# endif -# define COMPILER_VERSION_MINOR DEC((__WATCOMC__ / 10) % 10) -# if (__WATCOMC__ % 10) > 0 -# define COMPILER_VERSION_PATCH DEC(__WATCOMC__ % 10) -# endif - -#elif defined(__SUNPRO_C) -# define COMPILER_ID "SunPro" -# if __SUNPRO_C >= 0x5100 - /* __SUNPRO_C = 0xVRRP */ -# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12) -# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF) -# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) -# else - /* __SUNPRO_C = 0xVRP */ -# define COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8) -# define COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF) -# define COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) -# endif - -#elif defined(__HP_cc) -# define COMPILER_ID "HP" - /* __HP_cc = VVRRPP */ -# define COMPILER_VERSION_MAJOR DEC(__HP_cc/10000) -# define COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100) -# define COMPILER_VERSION_PATCH DEC(__HP_cc % 100) - -#elif defined(__DECC) -# define COMPILER_ID "Compaq" - /* __DECC_VER = VVRRTPPPP */ -# define COMPILER_VERSION_MAJOR DEC(__DECC_VER/10000000) -# define COMPILER_VERSION_MINOR DEC(__DECC_VER/100000 % 100) -# define COMPILER_VERSION_PATCH DEC(__DECC_VER % 10000) - -#elif defined(__IBMC__) -# if defined(__COMPILER_VER__) -# define COMPILER_ID "zOS" -# else -# if __IBMC__ >= 800 -# define COMPILER_ID "XL" -# else -# define COMPILER_ID "VisualAge" -# endif - /* __IBMC__ = VRP */ -# define COMPILER_VERSION_MAJOR DEC(__IBMC__/100) -# define COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) -# define COMPILER_VERSION_PATCH DEC(__IBMC__ % 10) -# endif - -#elif defined(__PGI) -# define COMPILER_ID "PGI" -# define COMPILER_VERSION_MAJOR DEC(__PGIC__) -# define COMPILER_VERSION_MINOR DEC(__PGIC_MINOR__) -# if defined(__PGIC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__PGIC_PATCHLEVEL__) -# endif - -#elif defined(_CRAYC) -# define COMPILER_ID "Cray" -# define COMPILER_VERSION_MAJOR DEC(_RELEASE) -# define COMPILER_VERSION_MINOR DEC(_RELEASE_MINOR) - -#elif defined(__TI_COMPILER_VERSION__) -# define COMPILER_ID "TI" - /* __TI_COMPILER_VERSION__ = VVVRRRPPP */ -# define COMPILER_VERSION_MAJOR DEC(__TI_COMPILER_VERSION__/1000000) -# define COMPILER_VERSION_MINOR DEC(__TI_COMPILER_VERSION__/1000 % 1000) -# define COMPILER_VERSION_PATCH DEC(__TI_COMPILER_VERSION__ % 1000) - -#elif defined(__TINYC__) -# define COMPILER_ID "TinyCC" - -#elif defined(__SCO_VERSION__) -# define COMPILER_ID "SCO" - -#elif defined(__GNUC__) -# define COMPILER_ID "GNU" -# define COMPILER_VERSION_MAJOR DEC(__GNUC__) -# define COMPILER_VERSION_MINOR DEC(__GNUC_MINOR__) -# if defined(__GNUC_PATCHLEVEL__) -# define COMPILER_VERSION_PATCH DEC(__GNUC_PATCHLEVEL__) -# endif - -#elif defined(_MSC_VER) -# define COMPILER_ID "MSVC" - /* _MSC_VER = VVRR */ -# define COMPILER_VERSION_MAJOR DEC(_MSC_VER / 100) -# define COMPILER_VERSION_MINOR DEC(_MSC_VER % 100) -# if defined(_MSC_FULL_VER) -# if _MSC_VER >= 1400 - /* _MSC_FULL_VER = VVRRPPPPP */ -# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 100000) -# else - /* _MSC_FULL_VER = VVRRPPPP */ -# define COMPILER_VERSION_PATCH DEC(_MSC_FULL_VER % 10000) -# endif -# endif -# if defined(_MSC_BUILD) -# define COMPILER_VERSION_TWEAK DEC(_MSC_BUILD) -# endif - -/* Analog VisualDSP++ >= 4.5.6 */ -#elif defined(__VISUALDSPVERSION__) -# define COMPILER_ID "ADSP" - /* __VISUALDSPVERSION__ = 0xVVRRPP00 */ -# define COMPILER_VERSION_MAJOR HEX(__VISUALDSPVERSION__>>24) -# define COMPILER_VERSION_MINOR HEX(__VISUALDSPVERSION__>>16 & 0xFF) -# define COMPILER_VERSION_PATCH HEX(__VISUALDSPVERSION__>>8 & 0xFF) - -/* Analog VisualDSP++ < 4.5.6 */ -#elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__) -# define COMPILER_ID "ADSP" - -/* IAR Systems compiler for embedded systems. - http://www.iar.com */ -#elif defined(__IAR_SYSTEMS_ICC__ ) || defined(__IAR_SYSTEMS_ICC) -# define COMPILER_ID "IAR" - -/* sdcc, the small devices C compiler for embedded systems, - http://sdcc.sourceforge.net */ -#elif defined(SDCC) -# define COMPILER_ID "SDCC" - /* SDCC = VRP */ -# define COMPILER_VERSION_MAJOR DEC(SDCC/100) -# define COMPILER_VERSION_MINOR DEC(SDCC/10 % 10) -# define COMPILER_VERSION_PATCH DEC(SDCC % 10) - -#elif defined(_SGI_COMPILER_VERSION) || defined(_COMPILER_VERSION) -# define COMPILER_ID "MIPSpro" -# if defined(_SGI_COMPILER_VERSION) - /* _SGI_COMPILER_VERSION = VRP */ -# define COMPILER_VERSION_MAJOR DEC(_SGI_COMPILER_VERSION/100) -# define COMPILER_VERSION_MINOR DEC(_SGI_COMPILER_VERSION/10 % 10) -# define COMPILER_VERSION_PATCH DEC(_SGI_COMPILER_VERSION % 10) -# else - /* _COMPILER_VERSION = VRP */ -# define COMPILER_VERSION_MAJOR DEC(_COMPILER_VERSION/100) -# define COMPILER_VERSION_MINOR DEC(_COMPILER_VERSION/10 % 10) -# define COMPILER_VERSION_PATCH DEC(_COMPILER_VERSION % 10) -# endif - -/* These compilers are either not known or too old to define an - identification macro. Try to identify the platform and guess that - it is the native compiler. */ -#elif defined(__sgi) -# define COMPILER_ID "MIPSpro" - -#elif defined(__hpux) || defined(__hpua) -# define COMPILER_ID "HP" - -#else /* unknown compiler */ -# define COMPILER_ID "" - -#endif +@CMAKE_C_COMPILER_ID_CONTENT@ /* Construct the string literal in pieces to prevent the source from getting matched. Store it in a pointer rather than an array diff --git a/Modules/CMakeCompilerIdDetection.cmake b/Modules/CMakeCompilerIdDetection.cmake index f0e39ad37..d8a0d6798 100644 --- a/Modules/CMakeCompilerIdDetection.cmake +++ b/Modules/CMakeCompilerIdDetection.cmake @@ -24,15 +24,20 @@ include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake) function(compiler_id_detection outvar lang) - file(GLOB lang_files - "${CMAKE_ROOT}/Modules/Compiler/*-${lang}-DetermineCompiler.cmake") - if (NOT lang STREQUAL Fortran) - file(GLOB non_lang_files + file(GLOB lang_files "${CMAKE_ROOT}/Modules/Compiler/*-DetermineCompiler.cmake") + set(nonlang CXX) + if (lang STREQUAL CXX) + set(nonlang C) + endif() + + file(GLOB nonlang_files + "${CMAKE_ROOT}/Modules/Compiler/*-${nonlang}-DetermineCompiler.cmake") + list(REMOVE_ITEM lang_files ${nonlang_files}) endif() - set(files ${lang_files} ${non_lang_files}) + set(files ${lang_files}) if (files) foreach(file ${files}) _readFile(${file}) @@ -45,10 +50,14 @@ function(compiler_id_detection outvar lang) 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. - Comeau + # Order is relevant here. For example, compilers which pretend to be + # GCC must appear before the actual GCC. + if (lang STREQUAL CXX) + list(APPEND ordered_compilers + Comeau + ) + endif() + list(APPEND ordered_compilers Intel PathScale AppleClang @@ -66,11 +75,25 @@ function(compiler_id_detection outvar lang) PGI Cray TI + ) + if (lang STREQUAL C) + list(APPEND ordered_compilers + TinyCC + ) + endif() + list(APPEND ordered_compilers SCO GNU MSVC ADSP IAR + ) + if (lang STREQUAL C) + list(APPEND ordered_compilers + SDCC + ) + endif() + list(APPEND ordered_compilers MIPSpro) if(CID_ID_DEFINE) diff --git a/Modules/Compiler/Compaq-C-DetermineCompiler.cmake b/Modules/Compiler/Compaq-C-DetermineCompiler.cmake new file mode 100644 index 000000000..56fedb1f5 --- /dev/null +++ b/Modules/Compiler/Compaq-C-DetermineCompiler.cmake @@ -0,0 +1,8 @@ + +set(_compiler_id_pp_test "defined(__DECC)") + +set(_compiler_id_version_compute " + /* __DECC_VER = VVRRTPPPP */ +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__DECC_VER/10000000) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__DECC_VER/100000 % 100) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__DECC_VER % 10000)") diff --git a/Modules/Compiler/HP-C-DetermineCompiler.cmake b/Modules/Compiler/HP-C-DetermineCompiler.cmake new file mode 100644 index 000000000..024a658d2 --- /dev/null +++ b/Modules/Compiler/HP-C-DetermineCompiler.cmake @@ -0,0 +1,8 @@ + +set(_compiler_id_pp_test "defined(__HP_cc)") + +set(_compiler_id_version_compute " + /* __HP_cc = VVRRPP */ +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__HP_cc/10000) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__HP_cc/100 % 100) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__HP_cc % 100)") diff --git a/Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake b/Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake new file mode 100644 index 000000000..6169ab43c --- /dev/null +++ b/Modules/Compiler/IBMCPP-C-DetermineVersionInternal.cmake @@ -0,0 +1,6 @@ + +set(_compiler_id_version_compute " + /* __IBMC__ = VRP */ +# define @PREFIX@COMPILER_VERSION_MAJOR DEC(__IBMC__/100) +# define @PREFIX@COMPILER_VERSION_MINOR DEC(__IBMC__/10 % 10) +# define @PREFIX@COMPILER_VERSION_PATCH DEC(__IBMC__ % 10)") diff --git a/Modules/Compiler/SDCC-C-DetermineCompiler.cmake b/Modules/Compiler/SDCC-C-DetermineCompiler.cmake new file mode 100644 index 000000000..8fe60d9aa --- /dev/null +++ b/Modules/Compiler/SDCC-C-DetermineCompiler.cmake @@ -0,0 +1,10 @@ + +# sdcc, the small devices C compiler for embedded systems, +# http://sdcc.sourceforge.net */ +set(_compiler_id_pp_test "defined(SDCC)") + +set(_compiler_id_version_compute " + /* SDCC = VRP */ +# define COMPILER_VERSION_MAJOR DEC(SDCC/100) +# define COMPILER_VERSION_MINOR DEC(SDCC/10 % 10) +# define COMPILER_VERSION_PATCH DEC(SDCC % 10)") diff --git a/Modules/Compiler/SunPro-C-DetermineCompiler.cmake b/Modules/Compiler/SunPro-C-DetermineCompiler.cmake new file mode 100644 index 000000000..7db1a971a --- /dev/null +++ b/Modules/Compiler/SunPro-C-DetermineCompiler.cmake @@ -0,0 +1,15 @@ + +set(_compiler_id_pp_test "defined(__SUNPRO_C)") + +set(_compiler_id_version_compute " +# if __SUNPRO_C >= 0x5100 + /* __SUNPRO_C = 0xVRRP */ +# define @PREFIX@COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>12) +# define @PREFIX@COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xFF) +# define @PREFIX@COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) +# else + /* __SUNPRO_CC = 0xVRP */ +# define @PREFIX@COMPILER_VERSION_MAJOR HEX(__SUNPRO_C>>8) +# define @PREFIX@COMPILER_VERSION_MINOR HEX(__SUNPRO_C>>4 & 0xF) +# define @PREFIX@COMPILER_VERSION_PATCH HEX(__SUNPRO_C & 0xF) +# endif") diff --git a/Modules/Compiler/TinyCC-C-DetermineCompiler.cmake b/Modules/Compiler/TinyCC-C-DetermineCompiler.cmake new file mode 100644 index 000000000..8d6de7e44 --- /dev/null +++ b/Modules/Compiler/TinyCC-C-DetermineCompiler.cmake @@ -0,0 +1,2 @@ + +set(_compiler_id_pp_test "defined(__TINYC__)") diff --git a/Modules/Compiler/VisualAge-C-DetermineCompiler.cmake b/Modules/Compiler/VisualAge-C-DetermineCompiler.cmake new file mode 100644 index 000000000..97c226313 --- /dev/null +++ b/Modules/Compiler/VisualAge-C-DetermineCompiler.cmake @@ -0,0 +1,4 @@ + +set(_compiler_id_pp_test "defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ < 800") + +include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-C-DetermineVersionInternal.cmake") diff --git a/Modules/Compiler/XL-C-DetermineCompiler.cmake b/Modules/Compiler/XL-C-DetermineCompiler.cmake new file mode 100644 index 000000000..3f4e05c55 --- /dev/null +++ b/Modules/Compiler/XL-C-DetermineCompiler.cmake @@ -0,0 +1,4 @@ + +set(_compiler_id_pp_test "defined(__IBMC__) && !defined(__COMPILER_VER__) && __IBMC__ >= 800") + +include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-C-DetermineVersionInternal.cmake") diff --git a/Modules/Compiler/zOS-C-DetermineCompiler.cmake b/Modules/Compiler/zOS-C-DetermineCompiler.cmake new file mode 100644 index 000000000..daa378198 --- /dev/null +++ b/Modules/Compiler/zOS-C-DetermineCompiler.cmake @@ -0,0 +1,4 @@ + +set(_compiler_id_pp_test "defined(__IBMC__) && defined(__COMPILER_VER__)") + +include("${CMAKE_CURRENT_LIST_DIR}/IBMCPP-C-DetermineVersionInternal.cmake")