CMakeDetermineCompilerABI.cmake 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. INCLUDE(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
  5. FUNCTION(CMAKE_DETERMINE_COMPILER_ABI lang src)
  6. IF(NOT DEFINED CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  7. MESSAGE(STATUS "Detecting ${lang} compiler ABI info")
  8. # Compile the ABI identification source.
  9. SET(BIN "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeDetermineCompilerABI_${lang}.bin")
  10. TRY_COMPILE(CMAKE_DETERMINE_${lang}_ABI_COMPILED
  11. ${CMAKE_BINARY_DIR} ${src}
  12. CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}"
  13. "-DCMAKE_${lang}_STANDARD_LIBRARIES="
  14. OUTPUT_VARIABLE OUTPUT
  15. COPY_FILE "${BIN}"
  16. )
  17. # Load the resulting information strings.
  18. IF(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  19. MESSAGE(STATUS "Detecting ${lang} compiler ABI info - done")
  20. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  21. "Detecting ${lang} compiler ABI info compiled with the following output:\n${OUTPUT}\n\n")
  22. FILE(STRINGS "${BIN}" ABI_STRINGS LIMIT_COUNT 2 REGEX "INFO:[^[]*\\[")
  23. FOREACH(info ${ABI_STRINGS})
  24. IF("${info}" MATCHES ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*")
  25. STRING(REGEX REPLACE ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*" "\\1" ABI_SIZEOF_DPTR "${info}")
  26. ENDIF("${info}" MATCHES ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*")
  27. IF("${info}" MATCHES ".*INFO:abi\\[([^]]*)\\].*")
  28. STRING(REGEX REPLACE ".*INFO:abi\\[([^]]*)\\].*" "\\1" ABI_NAME "${info}")
  29. ENDIF("${info}" MATCHES ".*INFO:abi\\[([^]]*)\\].*")
  30. ENDFOREACH(info)
  31. IF(ABI_SIZEOF_DPTR)
  32. SET(CMAKE_${lang}_SIZEOF_DATA_PTR "${ABI_SIZEOF_DPTR}" PARENT_SCOPE)
  33. SET(CMAKE_SIZEOF_VOID_P "${ABI_SIZEOF_DPTR}" PARENT_SCOPE)
  34. ENDIF(ABI_SIZEOF_DPTR)
  35. IF(ABI_NAME)
  36. SET(CMAKE_${lang}_COMPILER_ABI "${ABI_NAME}" PARENT_SCOPE)
  37. SET(CMAKE_INTERNAL_PLATFORM_ABI "${ABI_NAME}" PARENT_SCOPE)
  38. ENDIF(ABI_NAME)
  39. # Parse implicit linker information for this language, if available.
  40. SET(implicit_dirs "")
  41. SET(implicit_libs "")
  42. IF(CMAKE_${lang}_VERBOSE_FLAG)
  43. CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs)
  44. ENDIF()
  45. SET(CMAKE_${lang}_IMPLICIT_LINK_LIBRARIES "${implicit_libs}" PARENT_SCOPE)
  46. SET(CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES "${implicit_dirs}" PARENT_SCOPE)
  47. ELSE(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  48. MESSAGE(STATUS "Detecting ${lang} compiler ABI info - failed")
  49. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  50. "Detecting ${lang} compiler ABI info failed to compile with the following output:\n${OUTPUT}\n\n")
  51. ENDIF(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  52. ENDIF(NOT DEFINED CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  53. ENDFUNCTION(CMAKE_DETERMINE_COMPILER_ABI)