summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2008-02-25 14:23:14 (GMT)
committerBrad King <brad.king@kitware.com>2008-02-25 14:23:14 (GMT)
commit9211b0d23482c0fee8dc64171cf3524feb1ae446 (patch)
tree4b65eec4b9abab6658d2f35437d9021f8508c941
parent88bd02a5d1553d31e0d4d8ee6eef599c27abddf2 (diff)
downloadCMake-9211b0d23482c0fee8dc64171cf3524feb1ae446.zip
CMake-9211b0d23482c0fee8dc64171cf3524feb1ae446.tar.gz
CMake-9211b0d23482c0fee8dc64171cf3524feb1ae446.tar.bz2
ENH: Improvied compiler identification robustness
- Write a single source file into the compiler id directory - This avoid requiring the compiler to behave correctly with respect to include rules and the current working directory - Helps to identify cross-compiling toolchains with unusual default behavior
-rw-r--r--Modules/CMakeCCompilerId.c.in (renamed from Modules/CMakeCCompilerId.c)20
-rw-r--r--Modules/CMakeCXXCompilerId.cpp.in (renamed from Modules/CMakeCXXCompilerId.cpp)16
-rw-r--r--Modules/CMakeDetermineCCompiler.cmake4
-rw-r--r--Modules/CMakeDetermineCXXCompiler.cmake4
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake76
-rw-r--r--Modules/CMakeDetermineFortranCompiler.cmake2
-rw-r--r--Modules/CMakeFortranCompilerId.F90.in (renamed from Modules/CMakeFortranCompilerId.F90)0
-rw-r--r--Modules/CMakePlatformId.h.in (renamed from Modules/CMakePlatformId.h)2
8 files changed, 59 insertions, 65 deletions
diff --git a/Modules/CMakeCCompilerId.c b/Modules/CMakeCCompilerId.c.in
index ec11b6c..e9675ca 100644
--- a/Modules/CMakeCCompilerId.c
+++ b/Modules/CMakeCCompilerId.c.in
@@ -2,9 +2,8 @@
# error "A C++ compiler has been selected for C."
#endif
-#ifdef __CLASSIC_C__
-# define const
-#endif
+/* Provide main() so the program can link. */
+int main() { return 0; }
#if defined(__INTEL_COMPILER) || defined(__ICC)
# define COMPILER_ID "Intel"
@@ -37,7 +36,7 @@
# define COMPILER_ID "MSVC"
#elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
-/* Analog Devices C++ compiler for Blackfin, TigerSHARC and
+/* Analog Devices C++ compiler for Blackfin, TigerSHARC and
SHARC (21000) DSPs */
# define COMPILER_ID "ADSP"
@@ -47,7 +46,7 @@
#elif defined(__IAR_SYSTEMS_ICC__)
# define COMPILER_ID "IAR" */
-/* sdcc, the small devices C compiler for embedded systems,
+/* sdcc, the small devices C compiler for embedded systems,
http://sdcc.sourceforge.net */
#elif defined(SDCC)
# define COMPILER_ID "SDCC"
@@ -69,13 +68,6 @@
#endif
-static char const info_compiler[] = "INFO:compiler[" COMPILER_ID "]";
-
-/* Include the platform identification source. */
-#include "CMakePlatformId.h"
+char info_compiler[] = "INFO:compiler[" COMPILER_ID "]";
-/* Make sure the information strings are referenced. */
-int main()
-{
- return (&info_compiler[0] != &info_platform[0]);
-}
+@CMAKE_C_COMPILER_ID_PLATFORM_CONTENT@
diff --git a/Modules/CMakeCXXCompilerId.cpp b/Modules/CMakeCXXCompilerId.cpp.in
index 86d65bd..7bdb5e0 100644
--- a/Modules/CMakeCXXCompilerId.cpp
+++ b/Modules/CMakeCXXCompilerId.cpp.in
@@ -5,6 +5,9 @@
# error "A C compiler has been selected for C++."
#endif
+/* Provide main() so the program can link. */
+int main() { return 0; }
+
#if defined(__COMO__)
# define COMPILER_ID "Comeau"
@@ -39,7 +42,7 @@
# define COMPILER_ID "MSVC"
#elif defined(__ADSPBLACKFIN__) || defined(__ADSPTS__) || defined(__ADSP21000__)
-/* Analog Devices C++ compiler for Blackfin, TigerSHARC and
+/* Analog Devices C++ compiler for Blackfin, TigerSHARC and
SHARC (21000) DSPs */
# define COMPILER_ID "ADSP"
@@ -60,13 +63,6 @@
#endif
-static char const info_compiler[] = "INFO:compiler[" COMPILER_ID "]";
-
-/* Include the platform identification source. */
-#include "CMakePlatformId.h"
+char info_compiler[] = "INFO:compiler[" COMPILER_ID "]";
-/* Make sure the information strings are referenced. */
-int main()
-{
- return (&info_compiler[0] != &info_platform[0]);
-}
+@CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT@
diff --git a/Modules/CMakeDetermineCCompiler.cmake b/Modules/CMakeDetermineCCompiler.cmake
index 3ae9ba2..ffe0703 100644
--- a/Modules/CMakeDetermineCCompiler.cmake
+++ b/Modules/CMakeDetermineCCompiler.cmake
@@ -122,8 +122,10 @@ IF(NOT CMAKE_C_COMPILER_ID_RUN)
# Try to identify the compiler.
SET(CMAKE_C_COMPILER_ID)
+ FILE(READ ${CMAKE_ROOT}/Modules/CMakePlatformId.h.in
+ CMAKE_C_COMPILER_ID_PLATFORM_CONTENT)
INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
- CMAKE_DETERMINE_COMPILER_ID(C CFLAGS ${CMAKE_ROOT}/Modules/CMakeCCompilerId.c)
+ CMAKE_DETERMINE_COMPILER_ID(C CFLAGS CMakeCCompilerId.c)
# Set old compiler and platform id variables.
IF("${CMAKE_C_COMPILER_ID}" MATCHES "GNU")
diff --git a/Modules/CMakeDetermineCXXCompiler.cmake b/Modules/CMakeDetermineCXXCompiler.cmake
index d354165..b024034 100644
--- a/Modules/CMakeDetermineCXXCompiler.cmake
+++ b/Modules/CMakeDetermineCXXCompiler.cmake
@@ -132,8 +132,10 @@ IF(NOT CMAKE_CXX_COMPILER_ID_RUN)
# Try to identify the compiler.
SET(CMAKE_CXX_COMPILER_ID)
+ FILE(READ ${CMAKE_ROOT}/Modules/CMakePlatformId.h.in
+ CMAKE_CXX_COMPILER_ID_PLATFORM_CONTENT)
INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
- CMAKE_DETERMINE_COMPILER_ID(CXX CXXFLAGS ${CMAKE_ROOT}/Modules/CMakeCXXCompilerId.cpp)
+ CMAKE_DETERMINE_COMPILER_ID(CXX CXXFLAGS CMakeCXXCompilerId.cpp)
# Set old compiler and platform id variables.
IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index d684fb8..05c8ca6 100644
--- a/Modules/CMakeDetermineCompilerId.cmake
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -4,16 +4,6 @@
# If successful, sets CMAKE_<lang>_COMPILER_ID and CMAKE_<lang>_PLATFORM_ID
FUNCTION(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
- # Store the compiler identification source file.
- SET(CMAKE_${lang}_COMPILER_ID_SRC "${src}")
- IF(CMAKE_HOST_WIN32 AND NOT CMAKE_HOST_UNIX)
- # This seems to escape spaces:
- #FILE(TO_NATIVE_PATH "${CMAKE_${lang}_COMPILER_ID_SRC}"
- # CMAKE_${lang}_COMPILER_ID_SRC)
- STRING(REGEX REPLACE "/" "\\\\" CMAKE_${lang}_COMPILER_ID_SRC
- "${CMAKE_${lang}_COMPILER_ID_SRC}")
- ENDIF(CMAKE_HOST_WIN32 AND NOT CMAKE_HOST_UNIX)
-
# Make sure the compiler arguments are clean.
STRING(STRIP "${CMAKE_${lang}_COMPILER_ARG1}" CMAKE_${lang}_COMPILER_ID_ARG1)
@@ -32,9 +22,9 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
# of helper flags. Stop when the compiler is identified.
FOREACH(flags "" ${CMAKE_${lang}_COMPILER_ID_TEST_FLAGS})
IF(NOT CMAKE_${lang}_COMPILER_ID)
- CMAKE_DETERMINE_COMPILER_ID_BUILD("${lang}" "${flags}")
+ CMAKE_DETERMINE_COMPILER_ID_BUILD("${lang}" "${flags}" "${src}")
FOREACH(file ${COMPILER_${lang}_PRODUCED_FILES})
- CMAKE_DETERMINE_COMPILER_ID_CHECK("${lang}" "${file}")
+ CMAKE_DETERMINE_COMPILER_ID_CHECK("${lang}" "${CMAKE_${lang}_COMPILER_ID_DIR}/${file}" "${src}")
ENDFOREACH(file)
ENDIF(NOT CMAKE_${lang}_COMPILER_ID)
ENDFOREACH(flags)
@@ -57,19 +47,28 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
ENDFUNCTION(CMAKE_DETERMINE_COMPILER_ID)
#-----------------------------------------------------------------------------
+# Function to write the compiler id source file.
+FUNCTION(CMAKE_DETERMINE_COMPILER_ID_WRITE lang src)
+ FILE(READ ${CMAKE_ROOT}/Modules/${src}.in ID_CONTENT_IN)
+ STRING(CONFIGURE "${ID_CONTENT_IN}" ID_CONTENT_OUT @ONLY)
+ FILE(WRITE ${CMAKE_${lang}_COMPILER_ID_DIR}/${src} "${ID_CONTENT_OUT}")
+ENDFUNCTION(CMAKE_DETERMINE_COMPILER_ID_WRITE)
+
+#-----------------------------------------------------------------------------
# Function to build the compiler id source file and look for output
# files.
-FUNCTION(CMAKE_DETERMINE_COMPILER_ID_BUILD lang testflags)
+FUNCTION(CMAKE_DETERMINE_COMPILER_ID_BUILD lang testflags src)
# Create a clean working directory.
FILE(REMOVE_RECURSE ${CMAKE_${lang}_COMPILER_ID_DIR})
FILE(MAKE_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR})
+ CMAKE_DETERMINE_COMPILER_ID_WRITE("${lang}" "${src}")
# Construct a description of this test case.
SET(COMPILER_DESCRIPTION
- "Compiler: ${CMAKE_${lang}_COMPILER} ${CMAKE_${lang}_COMPILER_ID_ARG1}\n"
- "Build flags: ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}\n"
- "Id flags: ${testflags}\n"
- )
+ "Compiler: ${CMAKE_${lang}_COMPILER} ${CMAKE_${lang}_COMPILER_ID_ARG1}
+Build flags: ${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}
+Id flags: ${testflags}
+")
# Compile the compiler identification source.
IF(COMMAND EXECUTE_PROCESS)
@@ -78,7 +77,7 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID_BUILD lang testflags)
${CMAKE_${lang}_COMPILER_ID_ARG1}
${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}
${testflags}
- ${CMAKE_${lang}_COMPILER_ID_SRC}
+ "${src}"
WORKING_DIRECTORY ${CMAKE_${lang}_COMPILER_ID_DIR}
OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
ERROR_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
@@ -90,7 +89,7 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID_BUILD lang testflags)
ARGS ${CMAKE_${lang}_COMPILER_ID_ARG1}
${CMAKE_${lang}_COMPILER_ID_FLAGS_LIST}
${testflags}
- \"${CMAKE_${lang}_COMPILER_ID_SRC}\"
+ \"${src}\"
OUTPUT_VARIABLE CMAKE_${lang}_COMPILER_ID_OUTPUT
RETURN_VALUE CMAKE_${lang}_COMPILER_ID_RESULT
)
@@ -100,13 +99,13 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID_BUILD lang testflags)
IF(CMAKE_${lang}_COMPILER_ID_RESULT)
# Compilation failed.
SET(MSG
- "Compiling the ${lang} compiler identification source file \""
- "${CMAKE_${lang}_COMPILER_ID_SRC}\" failed.\n"
- ${COMPILER_DESCRIPTION}
- "The output was:\n"
- "${CMAKE_${lang}_COMPILER_ID_RESULT}\n"
- "${CMAKE_${lang}_COMPILER_ID_OUTPUT}\n\n"
- )
+ "Compiling the ${lang} compiler identification source file \"${src}\" failed.
+${COMPILER_DESCRIPTION}
+The output was:
+${CMAKE_${lang}_COMPILER_ID_RESULT}
+${CMAKE_${lang}_COMPILER_ID_OUTPUT}
+
+")
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log "${MSG}")
#IF(NOT CMAKE_${lang}_COMPILER_ID_ALLOW_FAIL)
# MESSAGE(FATAL_ERROR "${MSG}")
@@ -117,35 +116,38 @@ FUNCTION(CMAKE_DETERMINE_COMPILER_ID_BUILD lang testflags)
ELSE(CMAKE_${lang}_COMPILER_ID_RESULT)
# Compilation succeeded.
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
- "Compiling the ${lang} compiler identification source file \""
- "${CMAKE_${lang}_COMPILER_ID_SRC}\" succeeded.\n"
- ${COMPILER_DESCRIPTION}
- "The output was:\n"
- "${CMAKE_${lang}_COMPILER_ID_RESULT}\n"
- "${CMAKE_${lang}_COMPILER_ID_OUTPUT}\n\n"
- )
+ "Compiling the ${lang} compiler identification source file \"${src}\" succeeded.
+${COMPILER_DESCRIPTION}
+The output was:
+${CMAKE_${lang}_COMPILER_ID_RESULT}
+${CMAKE_${lang}_COMPILER_ID_OUTPUT}
+
+")
# Find the executable produced by the compiler, try all files in the
# binary dir.
- FILE(GLOB COMPILER_${lang}_PRODUCED_FILES ${CMAKE_${lang}_COMPILER_ID_DIR}/*)
+ FILE(GLOB COMPILER_${lang}_PRODUCED_FILES
+ RELATIVE ${CMAKE_${lang}_COMPILER_ID_DIR}
+ ${CMAKE_${lang}_COMPILER_ID_DIR}/*)
+ LIST(REMOVE_ITEM COMPILER_${lang}_PRODUCED_FILES "${src}")
FOREACH(file ${COMPILER_${lang}_PRODUCED_FILES})
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
"Compilation of the ${lang} compiler identification source \""
- "${CMAKE_${lang}_COMPILER_ID_SRC}\" produced \"${file}\"\n\n")
+ "${src}\" produced \"${file}\"\n\n")
ENDFOREACH(file)
IF(NOT COMPILER_${lang}_PRODUCED_FILES)
# No executable was found.
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
"Compilation of the ${lang} compiler identification source \""
- "${CMAKE_${lang}_COMPILER_ID_SRC}\" did not produce an executable in \""
+ "${src}\" did not produce an executable in \""
"${CMAKE_${lang}_COMPILER_ID_DIR}\".\n\n")
ENDIF(NOT COMPILER_${lang}_PRODUCED_FILES)
ENDIF(CMAKE_${lang}_COMPILER_ID_RESULT)
# Return the files produced by the compilation.
SET(COMPILER_${lang}_PRODUCED_FILES "${COMPILER_${lang}_PRODUCED_FILES}" PARENT_SCOPE)
-ENDFUNCTION(CMAKE_DETERMINE_COMPILER_ID_BUILD lang testflags)
+ENDFUNCTION(CMAKE_DETERMINE_COMPILER_ID_BUILD lang testflags src)
#-----------------------------------------------------------------------------
# Function to extract the compiler id from an executable.
diff --git a/Modules/CMakeDetermineFortranCompiler.cmake b/Modules/CMakeDetermineFortranCompiler.cmake
index 1f2ce80..defb5a7 100644
--- a/Modules/CMakeDetermineFortranCompiler.cmake
+++ b/Modules/CMakeDetermineFortranCompiler.cmake
@@ -94,7 +94,7 @@ IF(NOT CMAKE_Fortran_COMPILER_ID_RUN)
# Try to identify the compiler.
SET(CMAKE_Fortran_COMPILER_ID)
INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerId.cmake)
- CMAKE_DETERMINE_COMPILER_ID(Fortran FFLAGS ${CMAKE_ROOT}/Modules/CMakeFortranCompilerId.F90)
+ CMAKE_DETERMINE_COMPILER_ID(Fortran FFLAGS CMakeFortranCompilerId.F90)
# Fall back to old is-GNU test.
IF(NOT CMAKE_Fortran_COMPILER_ID)
diff --git a/Modules/CMakeFortranCompilerId.F90 b/Modules/CMakeFortranCompilerId.F90.in
index 870c204..870c204 100644
--- a/Modules/CMakeFortranCompilerId.F90
+++ b/Modules/CMakeFortranCompilerId.F90.in
diff --git a/Modules/CMakePlatformId.h b/Modules/CMakePlatformId.h.in
index 1907422..f62eb36 100644
--- a/Modules/CMakePlatformId.h
+++ b/Modules/CMakePlatformId.h.in
@@ -76,4 +76,4 @@
#endif
-static char const info_platform[] = "INFO:platform[" PLATFORM_ID "]";
+char info_platform[] = "INFO:platform[" PLATFORM_ID "]";