[cmake-commits] alex committed CMakeDetermineCompilerId.cmake 1.13 1.14 CMakeFindBinUtils.cmake 1.10 1.11

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Jan 2 16:52:14 EST 2008


Update of /cvsroot/CMake/CMake/Modules
In directory public:/mounts/ram/cvs-serv14512

Modified Files:
	CMakeDetermineCompilerId.cmake CMakeFindBinUtils.cmake 
Log Message:
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


Index: CMakeFindBinUtils.cmake
===================================================================
RCS file: /cvsroot/CMake/CMake/Modules/CMakeFindBinUtils.cmake,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- CMakeFindBinUtils.cmake	19 Dec 2007 08:55:11 -0000	1.10
+++ CMakeFindBinUtils.cmake	2 Jan 2008 21:52:12 -0000	1.11
@@ -75,13 +75,13 @@
   MARK_AS_ADVANCED(CMAKE_INSTALL_NAME_TOOL)
 ENDIF(APPLE)
 
-IF(UNIX  AND NOT  APPLE  AND NOT  WIN32)
+# if we are on an ELF system, search for chrpath
+IF("${CMAKE_EXECUTABLE_FORMAT}" STREQUAL "ELF")
   # on ELF platforms there might be chrpath, which works similar to install_name_tool
-  SET(CMAKE_USE_CHRPATH OFF CACHE BOOL "Enable this to use chrpath if available")
+  OPTION(CMAKE_USE_CHRPATH "Enable this to use chrpath if available" OFF)
 
   FIND_PROGRAM(CMAKE_CHRPATH chrpath PATHS ${_CMAKE_TOOLCHAIN_LOCATION} NO_DEFAULT_PATH)
   FIND_PROGRAM(CMAKE_CHRPATH chrpath)
 
   MARK_AS_ADVANCED(CMAKE_CHRPATH)
-ENDIF(UNIX  AND NOT  APPLE  AND NOT  WIN32)
-
+ENDIF("${CMAKE_EXECUTABLE_FORMAT}" STREQUAL "ELF")

Index: CMakeDetermineCompilerId.cmake
===================================================================
RCS file: /cvsroot/CMake/CMake/Modules/CMakeDetermineCompilerId.cmake,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- CMakeDetermineCompilerId.cmake	15 Dec 2007 21:03:29 -0000	1.13
+++ CMakeDetermineCompilerId.cmake	2 Jan 2008 21:52:12 -0000	1.14
@@ -77,6 +77,31 @@
         "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 @@
       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



More information about the Cmake-commits mailing list