summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeDetermineCompilerId.cmake
diff options
context:
space:
mode:
authorAlexander Neundorf <neundorf@kde.org>2008-01-02 21:52:12 (GMT)
committerAlexander Neundorf <neundorf@kde.org>2008-01-02 21:52:12 (GMT)
commit474629568c8b96b3883589a5dec8bba3cb0d53e0 (patch)
tree6bc637090b7e4e3bdbeda6ae06da205bc995cd72 /Modules/CMakeDetermineCompilerId.cmake
parent7b54af713dd9ab72335dabb161afba8cd2cc4cc8 (diff)
downloadCMake-474629568c8b96b3883589a5dec8bba3cb0d53e0.zip
CMake-474629568c8b96b3883589a5dec8bba3cb0d53e0.tar.gz
CMake-474629568c8b96b3883589a5dec8bba3cb0d53e0.tar.bz2
ENH: check the magic code of the executable file to determine the executable
file format. Tested for ELF on x86 Linux, COFF and Mach-O prepared but commented out since I don't have such systems available. Please have a look a CMakeDetermineCompilerId.cmake and enable the test for them too. Only add the option for using chrpath if the executable format is ELF Alex
Diffstat (limited to 'Modules/CMakeDetermineCompilerId.cmake')
-rw-r--r--Modules/CMakeDetermineCompilerId.cmake32
1 files changed, 32 insertions, 0 deletions
diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake
index b3417d3..f8dab51 100644
--- a/Modules/CMakeDetermineCompilerId.cmake
+++ b/Modules/CMakeDetermineCompilerId.cmake
@@ -77,6 +77,31 @@ MACRO(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
"Compilation of the ${lang} compiler identification source \""
"${CMAKE_${lang}_COMPILER_ID_SRC}\" produced \""
"${CMAKE_${lang}_COMPILER_ID_EXE}\"\n\n")
+
+ # try to figure out the executable format: ELF, COFF, Mach-O
+ IF(NOT CMAKE_EXECUTABLE_FORMAT)
+ FILE(READ ${CMAKE_${lang}_COMPILER_ID_EXE} CMAKE_EXECUTABLE_MAGIC LIMIT 4 HEX)
+
+ # ELF files start with 0x7f"ELF"
+ IF("${CMAKE_EXECUTABLE_MAGIC}" STREQUAL "7f454c46")
+ SET(CMAKE_EXECUTABLE_FORMAT "ELF" CACHE STRING "Executable file format")
+ ENDIF("${CMAKE_EXECUTABLE_MAGIC}" STREQUAL "7f454c46")
+
+# # COFF (.exe) files start with "MZ"
+# IF("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "4d5a....")
+# SET(CMAKE_EXECUTABLE_FORMAT "COFF" CACHE STRING "Executable file format")
+# ENDIF("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "4d5a....")
+#
+# # Mach-O files start with CAFEBABE or FEEDFACE, according to http://radio.weblogs.com/0100490/2003/01/28.html
+# IF("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "cafebabe")
+# SET(CMAKE_EXECUTABLE_FORMAT "MACHO" CACHE STRING "Executable file format")
+# ENDIF("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "cafebabe")
+# IF("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "feedface")
+# SET(CMAKE_EXECUTABLE_FORMAT "MACHO" CACHE STRING "Executable file format")
+# ENDIF("${CMAKE_EXECUTABLE_MAGIC}" MATCHES "feedface")
+
+ ENDIF(NOT CMAKE_EXECUTABLE_FORMAT)
+
# only check if we don't have it yet
IF(NOT CMAKE_${lang}_COMPILER_ID)
# Read the compiler identification string from the executable file.
@@ -108,6 +133,13 @@ MACRO(CMAKE_DETERMINE_COMPILER_ID lang flagvar src)
ENDIF(NOT CMAKE_${lang}_COMPILER_ID)
ENDFOREACH(CMAKE_${lang}_COMPILER_ID_EXE)
+ # if the format is unknown after all files have been checked, put "Unknown" in the cache
+ IF(NOT CMAKE_EXECUTABLE_FORMAT)
+ SET(CMAKE_EXECUTABLE_FORMAT "Unknown" CACHE STRING "Executable file format")
+ ELSE(NOT CMAKE_EXECUTABLE_FORMAT)
+ MESSAGE(STATUS "The executable file format is ${CMAKE_EXECUTABLE_FORMAT}")
+ ENDIF(NOT CMAKE_EXECUTABLE_FORMAT)
+
IF(NOT COMPILER_${lang}_PRODUCED_FILES)
# No executable was found.
FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log