CMakeDetermineCompilerABI.cmake 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #=============================================================================
  2. # Copyright 2008-2009 Kitware, Inc.
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #=============================================================================
  11. # (To distributed this file outside of CMake, substitute the full
  12. # License text for the above reference.)
  13. # Function to compile a source file to identify the compiler ABI.
  14. # This is used internally by CMake and should not be included by user
  15. # code.
  16. INCLUDE(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
  17. FUNCTION(CMAKE_DETERMINE_COMPILER_ABI lang src)
  18. IF(NOT DEFINED CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  19. MESSAGE(STATUS "Detecting ${lang} compiler ABI info")
  20. # Compile the ABI identification source.
  21. SET(BIN "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeDetermineCompilerABI_${lang}.bin")
  22. TRY_COMPILE(CMAKE_DETERMINE_${lang}_ABI_COMPILED
  23. ${CMAKE_BINARY_DIR} ${src}
  24. CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}"
  25. "-DCMAKE_${lang}_STANDARD_LIBRARIES="
  26. OUTPUT_VARIABLE OUTPUT
  27. COPY_FILE "${BIN}"
  28. )
  29. # Load the resulting information strings.
  30. IF(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  31. MESSAGE(STATUS "Detecting ${lang} compiler ABI info - done")
  32. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  33. "Detecting ${lang} compiler ABI info compiled with the following output:\n${OUTPUT}\n\n")
  34. FILE(STRINGS "${BIN}" ABI_STRINGS LIMIT_COUNT 2 REGEX "INFO:[^[]*\\[")
  35. FOREACH(info ${ABI_STRINGS})
  36. IF("${info}" MATCHES ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*")
  37. STRING(REGEX REPLACE ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*" "\\1" ABI_SIZEOF_DPTR "${info}")
  38. ENDIF("${info}" MATCHES ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*")
  39. IF("${info}" MATCHES ".*INFO:abi\\[([^]]*)\\].*")
  40. STRING(REGEX REPLACE ".*INFO:abi\\[([^]]*)\\].*" "\\1" ABI_NAME "${info}")
  41. ENDIF("${info}" MATCHES ".*INFO:abi\\[([^]]*)\\].*")
  42. ENDFOREACH(info)
  43. IF(ABI_SIZEOF_DPTR)
  44. SET(CMAKE_${lang}_SIZEOF_DATA_PTR "${ABI_SIZEOF_DPTR}" PARENT_SCOPE)
  45. SET(CMAKE_SIZEOF_VOID_P "${ABI_SIZEOF_DPTR}" PARENT_SCOPE)
  46. ENDIF(ABI_SIZEOF_DPTR)
  47. IF(ABI_NAME)
  48. SET(CMAKE_${lang}_COMPILER_ABI "${ABI_NAME}" PARENT_SCOPE)
  49. SET(CMAKE_INTERNAL_PLATFORM_ABI "${ABI_NAME}" PARENT_SCOPE)
  50. ENDIF(ABI_NAME)
  51. # Parse implicit linker information for this language, if available.
  52. SET(implicit_dirs "")
  53. SET(implicit_libs "")
  54. IF(CMAKE_${lang}_VERBOSE_FLAG
  55. # Implicit link information cannot be used explicitly for
  56. # multiple OS X architectures, so we skip it.
  57. AND NOT "${CMAKE_OSX_ARCHITECTURES}" MATCHES ";"
  58. # Skip this with Xcode for now.
  59. AND NOT "${CMAKE_GENERATOR}" MATCHES Xcode)
  60. CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs log)
  61. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  62. "Parsed ${lang} implicit link information from above output:\n${log}\n\n")
  63. ENDIF()
  64. SET(CMAKE_${lang}_IMPLICIT_LINK_LIBRARIES "${implicit_libs}" PARENT_SCOPE)
  65. SET(CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES "${implicit_dirs}" PARENT_SCOPE)
  66. ELSE(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  67. MESSAGE(STATUS "Detecting ${lang} compiler ABI info - failed")
  68. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  69. "Detecting ${lang} compiler ABI info failed to compile with the following output:\n${OUTPUT}\n\n")
  70. ENDIF(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  71. ENDIF(NOT DEFINED CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  72. ENDFUNCTION(CMAKE_DETERMINE_COMPILER_ABI)