CMakeDetermineCompilerABI.cmake 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Function to compile a source file to identify the compiler ABI.
  2. # This is used internally by CMake and should not be included by user
  3. # code.
  4. FUNCTION(CMAKE_DETERMINE_COMPILER_ABI lang src)
  5. IF(NOT DEFINED CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  6. MESSAGE(STATUS "Detecting ${lang} compiler info")
  7. # Compile the ABI identification source.
  8. SET(BIN "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeDetermineCompilerABI_${lang}.bin")
  9. TRY_COMPILE(CMAKE_DETERMINE_${lang}_ABI_COMPILED
  10. ${CMAKE_BINARY_DIR} ${src}
  11. OUTPUT_VARIABLE OUTPUT
  12. COPY_FILE "${BIN}"
  13. )
  14. # Load the resulting information strings.
  15. IF(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  16. MESSAGE(STATUS "Detecting ${lang} compiler info - done")
  17. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  18. "Detecting ${lang} compiler info compiled with the following output:\n${OUTPUT}\n\n")
  19. FILE(STRINGS "${BIN}" ABI_STRINGS LIMIT_COUNT 2 REGEX "INFO:[^[]*\\[")
  20. FOREACH(info ${ABI_STRINGS})
  21. IF("${info}" MATCHES ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*")
  22. STRING(REGEX REPLACE ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*" "\\1" ABI_SIZEOF_DPTR "${info}")
  23. ENDIF("${info}" MATCHES ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*")
  24. IF("${info}" MATCHES ".*INFO:abi\\[([^]]*)\\].*")
  25. STRING(REGEX REPLACE ".*INFO:abi\\[([^]]*)\\].*" "\\1" ABI_NAME "${info}")
  26. ENDIF("${info}" MATCHES ".*INFO:abi\\[([^]]*)\\].*")
  27. ENDFOREACH(info)
  28. IF(ABI_SIZEOF_DPTR)
  29. SET(CMAKE_${lang}_SIZEOF_DATA_PTR "${ABI_SIZEOF_DPTR}" PARENT_SCOPE)
  30. SET(CMAKE_SIZEOF_VOID_P "${ABI_SIZEOF_DPTR}" PARENT_SCOPE)
  31. ENDIF(ABI_SIZEOF_DPTR)
  32. IF(ABI_NAME)
  33. SET(CMAKE_${lang}_COMPILER_ABI "${ABI_NAME}" PARENT_SCOPE)
  34. SET(CMAKE_INTERNAL_PLATFORM_ABI "${ABI_NAME}" PARENT_SCOPE)
  35. ENDIF(ABI_NAME)
  36. ELSE(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  37. MESSAGE(STATUS "Detecting ${lang} compiler info - failed")
  38. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  39. "Detecting ${lang} compiler info failed to compile with the following output:\n${OUTPUT}\n\n")
  40. ENDIF(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  41. ENDIF(NOT DEFINED CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  42. ENDFUNCTION(CMAKE_DETERMINE_COMPILER_ABI)