summaryrefslogtreecommitdiffstats
path: root/Modules/CMakeDetermineCompilerABI.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2008-01-21 23:30:17 (GMT)
committerBrad King <brad.king@kitware.com>2008-01-21 23:30:17 (GMT)
commita28b197b11f4b647c67a6914c731077972449343 (patch)
tree48e3cad97678cc49ef2b63c210d4e712a4dc58fa /Modules/CMakeDetermineCompilerABI.cmake
parent19d22f6105ae064378e9175bed6a01b197e2eb5d (diff)
downloadCMake-a28b197b11f4b647c67a6914c731077972449343.zip
CMake-a28b197b11f4b647c67a6914c731077972449343.tar.gz
CMake-a28b197b11f4b647c67a6914c731077972449343.tar.bz2
ENH: Generalize the check for sizeof void* to detect more ABI information.
Diffstat (limited to 'Modules/CMakeDetermineCompilerABI.cmake')
-rw-r--r--Modules/CMakeDetermineCompilerABI.cmake49
1 files changed, 49 insertions, 0 deletions
diff --git a/Modules/CMakeDetermineCompilerABI.cmake b/Modules/CMakeDetermineCompilerABI.cmake
new file mode 100644
index 0000000..0571dc6
--- /dev/null
+++ b/Modules/CMakeDetermineCompilerABI.cmake
@@ -0,0 +1,49 @@
+
+# Function to compile a source file to identify the compiler ABI.
+# This is used internally by CMake and should not be included by user
+# code.
+
+FUNCTION(CMAKE_DETERMINE_COMPILER_ABI lang src)
+ IF(NOT DEFINED CMAKE_DETERMINE_${lang}_ABI_COMPILED)
+ MESSAGE(STATUS "Detecting ${lang} compiler info")
+
+ # Compile the ABI identification source.
+ SET(BIN "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeDetermineCompilerABI_${lang}.bin")
+ TRY_COMPILE(CMAKE_DETERMINE_${lang}_ABI_COMPILED
+ ${CMAKE_BINARY_DIR} ${src}
+ OUTPUT_VARIABLE OUTPUT
+ COPY_FILE "${BIN}"
+ )
+
+ # Load the resulting information strings.
+ IF(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
+ MESSAGE(STATUS "Detecting ${lang} compiler info - done")
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
+ "Detecting ${lang} compiler info compiled with the following output:\n${OUTPUT}\n\n")
+ FILE(STRINGS "${BIN}" ABI_STRINGS LIMIT_COUNT 2 REGEX "INFO:[^[]*\\[")
+ FOREACH(info ${ABI_STRINGS})
+ IF("${info}" MATCHES ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*")
+ STRING(REGEX REPLACE ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*" "\\1" ABI_SIZEOF_DPTR "${info}")
+ ENDIF("${info}" MATCHES ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*")
+ IF("${info}" MATCHES ".*INFO:abi\\[([^]]*)\\].*")
+ STRING(REGEX REPLACE ".*INFO:abi\\[([^]]*)\\].*" "\\1" ABI_NAME "${info}")
+ ENDIF("${info}" MATCHES ".*INFO:abi\\[([^]]*)\\].*")
+ ENDFOREACH(info)
+
+ IF(ABI_SIZEOF_DPTR)
+ SET(CMAKE_${lang}_SIZEOF_DATA_PTR "${ABI_SIZEOF_DPTR}" PARENT_SCOPE)
+ SET(CMAKE_SIZEOF_VOID_P "${ABI_SIZEOF_DPTR}" PARENT_SCOPE)
+ ENDIF(ABI_SIZEOF_DPTR)
+
+ IF(ABI_NAME)
+ SET(CMAKE_${lang}_COMPILER_ABI "${ABI_NAME}" PARENT_SCOPE)
+ SET(CMAKE_INTERNAL_PLATFORM_ABI "${ABI_NAME}" PARENT_SCOPE)
+ ENDIF(ABI_NAME)
+
+ ELSE(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
+ MESSAGE(STATUS "Detecting ${lang} compiler info - failed")
+ FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Detecting ${lang} compiler info failed to compile with the following output:\n${OUTPUT}\n\n")
+ ENDIF(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
+ ENDIF(NOT DEFINED CMAKE_DETERMINE_${lang}_ABI_COMPILED)
+ENDFUNCTION(CMAKE_DETERMINE_COMPILER_ABI)