From c65a060e1b19a463312f9003bc4d7793db9630e5 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 18 Jun 2015 10:57:46 -0400 Subject: [PATCH 1/5] CMakeDetermineCompilerId: Optionally try some flags before no flags Teach CMAKE_DETERMINE_COMPILER_ID to optionally try detecting the compiler id using some given flags before trying to detect it with no special flags. This will be useful for Fortran detection to distinguish some compilers that use the preprocessors of others but have no macro of their own by getting verbose output. --- Modules/CMakeDetermineCCompiler.cmake | 1 + Modules/CMakeDetermineCXXCompiler.cmake | 1 + Modules/CMakeDetermineCompilerId.cmake | 4 +++- Modules/CMakeDetermineFortranCompiler.cmake | 1 + 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake index 937aa8c3e..40d4ce6c3 100644 --- a/Modules/CMakeDetermineCCompiler.cmake +++ b/Modules/CMakeDetermineCCompiler.cmake @@ -80,6 +80,7 @@ else() # Each entry in this list is a set of extra flags to try # adding to the compile line to see if it helps produce # a valid identification file. + set(CMAKE_C_COMPILER_ID_TEST_FLAGS_FIRST) set(CMAKE_C_COMPILER_ID_TEST_FLAGS # Try compiling to an object file only. "-c" diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake index 893c454cc..a673525a8 100644 --- a/Modules/CMakeDetermineCXXCompiler.cmake +++ b/Modules/CMakeDetermineCXXCompiler.cmake @@ -78,6 +78,7 @@ else() # Each entry in this list is a set of extra flags to try # adding to the compile line to see if it helps produce # a valid identification file. + set(CMAKE_CXX_COMPILER_ID_TEST_FLAGS_FIRST) set(CMAKE_CXX_COMPILER_ID_TEST_FLAGS # Try compiling to an object file only. "-c" diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 403ac089a..7ddf33fcf 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -34,7 +34,9 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) # Try building with no extra flags and then try each set # of helper flags. Stop when the compiler is identified. - foreach(flags "" ${CMAKE_${lang}_COMPILER_ID_TEST_FLAGS}) + foreach(flags ${CMAKE_${lang}_COMPILER_ID_TEST_FLAGS_FIRST} + "" + ${CMAKE_${lang}_COMPILER_ID_TEST_FLAGS}) if(NOT CMAKE_${lang}_COMPILER_ID) CMAKE_DETERMINE_COMPILER_ID_BUILD("${lang}" "${flags}" "${src}") foreach(file ${COMPILER_${lang}_PRODUCED_FILES}) diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake index 3a27127e2..ca68900a5 100644 --- a/Modules/CMakeDetermineFortranCompiler.cmake +++ b/Modules/CMakeDetermineFortranCompiler.cmake @@ -98,6 +98,7 @@ else() # Each entry in this list is a set of extra flags to try # adding to the compile line to see if it helps produce # a valid identification executable. + set(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS_FIRST) set(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS # Try compiling to an object file only. "-c" From 5f0dad75a9dd9bb9e7b2f917806588563c3ed39e Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 18 Jun 2015 11:24:54 -0400 Subject: [PATCH 2/5] CMakeDetermineCompilerId: Refactor id build/check loop logic Callers of CMAKE_DETERMINE_COMPILER_ID initialize the CMAKE_${lang}_COMPILER_ID to unset so we can check it at the end of each loop iteration instead of the beginning. This approach allows us to break out of the loop as soon as we succeed. It will also allow checks to be added in more places within the loop later. --- Modules/CMakeDetermineCompilerId.cmake | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 7ddf33fcf..3c715e91e 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -37,11 +37,12 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) foreach(flags ${CMAKE_${lang}_COMPILER_ID_TEST_FLAGS_FIRST} "" ${CMAKE_${lang}_COMPILER_ID_TEST_FLAGS}) - if(NOT CMAKE_${lang}_COMPILER_ID) - CMAKE_DETERMINE_COMPILER_ID_BUILD("${lang}" "${flags}" "${src}") - foreach(file ${COMPILER_${lang}_PRODUCED_FILES}) - CMAKE_DETERMINE_COMPILER_ID_CHECK("${lang}" "${CMAKE_${lang}_COMPILER_ID_DIR}/${file}" "${src}") - endforeach() + CMAKE_DETERMINE_COMPILER_ID_BUILD("${lang}" "${flags}" "${src}") + foreach(file ${COMPILER_${lang}_PRODUCED_FILES}) + CMAKE_DETERMINE_COMPILER_ID_CHECK("${lang}" "${CMAKE_${lang}_COMPILER_ID_DIR}/${file}" "${src}") + endforeach() + if(CMAKE_${lang}_COMPILER_ID) + break() endif() endforeach() From 0d204c1c1dabba2dc87957e9ce6bcd32aab70dae Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 18 Jun 2015 11:28:36 -0400 Subject: [PATCH 3/5] CMakeDetermineCompilerId: Try matching compiler output to detect id Some compilers can only be distinguished by their compilation output rather than preprocessor symbols or special flags. Add infrastructure to determine the compiler id by matching output. --- Modules/CMakeDetermineCompilerId.cmake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 3c715e91e..68f219451 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -38,6 +38,10 @@ function(CMAKE_DETERMINE_COMPILER_ID lang flagvar src) "" ${CMAKE_${lang}_COMPILER_ID_TEST_FLAGS}) CMAKE_DETERMINE_COMPILER_ID_BUILD("${lang}" "${flags}" "${src}") + CMAKE_DETERMINE_COMPILER_ID_MATCH_VENDOR("${lang}" "${COMPILER_${lang}_PRODUCED_OUTPUT}") + if(CMAKE_${lang}_COMPILER_ID) + break() + endif() foreach(file ${COMPILER_${lang}_PRODUCED_FILES}) CMAKE_DETERMINE_COMPILER_ID_CHECK("${lang}" "${CMAKE_${lang}_COMPILER_ID_DIR}/${file}" "${src}") endforeach() @@ -358,6 +362,7 @@ ${CMAKE_${lang}_COMPILER_ID_OUTPUT} # No output files should be inspected. set(COMPILER_${lang}_PRODUCED_FILES) + set(COMPILER_${lang}_PRODUCED_OUTPUT) else() # Compilation succeeded. file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log @@ -398,10 +403,24 @@ ${CMAKE_${lang}_COMPILER_ID_OUTPUT} "${src}\" did not produce an executable in \"" "${CMAKE_${lang}_COMPILER_ID_DIR}\".\n\n") endif() + + set(COMPILER_${lang}_PRODUCED_OUTPUT "${CMAKE_${lang}_COMPILER_ID_OUTPUT}") endif() # Return the files produced by the compilation. set(COMPILER_${lang}_PRODUCED_FILES "${COMPILER_${lang}_PRODUCED_FILES}" PARENT_SCOPE) + set(COMPILER_${lang}_PRODUCED_OUTPUT "${COMPILER_${lang}_PRODUCED_OUTPUT}" PARENT_SCOPE) +endfunction() + +#----------------------------------------------------------------------------- +# Function to extract the compiler id from compiler output. +function(CMAKE_DETERMINE_COMPILER_ID_MATCH_VENDOR lang output) + foreach(vendor ${CMAKE_${lang}_COMPILER_ID_MATCH_VENDORS}) + if(output MATCHES "${CMAKE_${lang}_COMPILER_ID_MATCH_VENDOR_REGEX_${vendor}}") + set(CMAKE_${lang}_COMPILER_ID "${vendor}") + endif() + endforeach() + set(CMAKE_${lang}_COMPILER_ID "${CMAKE_${lang}_COMPILER_ID}" PARENT_SCOPE) endfunction() #----------------------------------------------------------------------------- From 7cd539b163a58f8b594e2318bdc7e7d7b1ba6577 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 18 Jun 2015 11:33:45 -0400 Subject: [PATCH 4/5] Add support for Concurrent Fortran 77 Compiler The Concurrent Fortran compiler (ccur.com) is available on Linux and can be used much like the GNU Fortran compiler. Currently it has no preprocessor symbols to identify it so we need to detect it by matching compiler output. Suggested-by: Anthony Ette --- Help/variable/CMAKE_LANG_COMPILER_ID.rst | 1 + Modules/CMakeDetermineFortranCompiler.cmake | 9 ++++++++- Modules/Compiler/CCur-Fortran.cmake | 1 + Modules/Platform/Linux-CCur-Fortran.cmake | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 Modules/Compiler/CCur-Fortran.cmake create mode 100644 Modules/Platform/Linux-CCur-Fortran.cmake diff --git a/Help/variable/CMAKE_LANG_COMPILER_ID.rst b/Help/variable/CMAKE_LANG_COMPILER_ID.rst index f554f4ec4..1c3b134d0 100644 --- a/Help/variable/CMAKE_LANG_COMPILER_ID.rst +++ b/Help/variable/CMAKE_LANG_COMPILER_ID.rst @@ -11,6 +11,7 @@ include: Absoft = Absoft Fortran (absoft.com) ADSP = Analog VisualDSP++ (analog.com) AppleClang = Apple Clang (apple.com) + CCur = Concurrent Fortran (ccur.com) Clang = LLVM Clang (clang.llvm.org) Cray = Cray Compiler (cray.com) Embarcadero, Borland = Embarcadero (embarcadero.com) diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake index ca68900a5..52ec25a13 100644 --- a/Modules/CMakeDetermineFortranCompiler.cmake +++ b/Modules/CMakeDetermineFortranCompiler.cmake @@ -98,7 +98,10 @@ else() # Each entry in this list is a set of extra flags to try # adding to the compile line to see if it helps produce # a valid identification executable. - set(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS_FIRST) + set(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS_FIRST + # Get verbose output to help distinguish compilers. + "-v" + ) set(CMAKE_Fortran_COMPILER_ID_TEST_FLAGS # Try compiling to an object file only. "-c" @@ -112,6 +115,10 @@ endif() if(NOT CMAKE_Fortran_COMPILER_ID_RUN) set(CMAKE_Fortran_COMPILER_ID_RUN 1) + # Table of per-vendor compiler output regular expressions. + list(APPEND CMAKE_Fortran_COMPILER_ID_MATCH_VENDORS CCur) + set(CMAKE_Fortran_COMPILER_ID_MATCH_VENDOR_REGEX_CCur "Concurrent Fortran [0-9]+ Compiler") + # Table of per-vendor compiler id flags with expected output. list(APPEND CMAKE_Fortran_COMPILER_ID_VENDORS Compaq) set(CMAKE_Fortran_COMPILER_ID_VENDOR_FLAGS_Compaq "-what") diff --git a/Modules/Compiler/CCur-Fortran.cmake b/Modules/Compiler/CCur-Fortran.cmake new file mode 100644 index 000000000..6ec06ae11 --- /dev/null +++ b/Modules/Compiler/CCur-Fortran.cmake @@ -0,0 +1 @@ +include(Compiler/GNU-Fortran) diff --git a/Modules/Platform/Linux-CCur-Fortran.cmake b/Modules/Platform/Linux-CCur-Fortran.cmake new file mode 100644 index 000000000..ceecc2f69 --- /dev/null +++ b/Modules/Platform/Linux-CCur-Fortran.cmake @@ -0,0 +1 @@ +include(Platform/Linux-GNU-Fortran) From 54676a0e4cf30d9f026a0f6521f7171a75f85803 Mon Sep 17 00:00:00 2001 From: Brad King Date: Thu, 18 Jun 2015 16:16:50 -0400 Subject: [PATCH 5/5] Help: Add notes for topic 'ConcurrentFortran-compiler-id' --- Help/release/dev/ConcurrentFortran-compiler-id.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Help/release/dev/ConcurrentFortran-compiler-id.rst diff --git a/Help/release/dev/ConcurrentFortran-compiler-id.rst b/Help/release/dev/ConcurrentFortran-compiler-id.rst new file mode 100644 index 000000000..71e79aa7e --- /dev/null +++ b/Help/release/dev/ConcurrentFortran-compiler-id.rst @@ -0,0 +1,5 @@ +ConcurrentFortran-compiler-id +----------------------------- + +* The `Concurrent Fortran 77 `__ compiler is now supported. + Its :variable:`compiler id _COMPILER_ID>` is ``CCur``.