CMakeDetermineCompilerABI.cmake 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 distribute 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. SET(CMAKE_FLAGS )
  23. IF(DEFINED CMAKE_${lang}_VERBOSE_FLAG)
  24. SET(CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}")
  25. ENDIF()
  26. TRY_COMPILE(CMAKE_DETERMINE_${lang}_ABI_COMPILED
  27. ${CMAKE_BINARY_DIR} ${src}
  28. CMAKE_FLAGS "${CMAKE_FLAGS}"
  29. "-DCMAKE_${lang}_STANDARD_LIBRARIES="
  30. # We need ignore these warnings because some platforms need
  31. # CMAKE_${lang}_STANDARD_LIBRARIES to link properly and we
  32. # don't care when we are just determining the ABI.
  33. "--no-warn-unused-cli"
  34. OUTPUT_VARIABLE OUTPUT
  35. COPY_FILE "${BIN}"
  36. )
  37. # Load the resulting information strings.
  38. IF(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  39. MESSAGE(STATUS "Detecting ${lang} compiler ABI info - done")
  40. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  41. "Detecting ${lang} compiler ABI info compiled with the following output:\n${OUTPUT}\n\n")
  42. FILE(STRINGS "${BIN}" ABI_STRINGS LIMIT_COUNT 2 REGEX "INFO:[^[]*\\[")
  43. FOREACH(info ${ABI_STRINGS})
  44. IF("${info}" MATCHES ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*")
  45. STRING(REGEX REPLACE ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*" "\\1" ABI_SIZEOF_DPTR "${info}")
  46. ENDIF("${info}" MATCHES ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*")
  47. IF("${info}" MATCHES ".*INFO:abi\\[([^]]*)\\].*")
  48. STRING(REGEX REPLACE ".*INFO:abi\\[([^]]*)\\].*" "\\1" ABI_NAME "${info}")
  49. ENDIF("${info}" MATCHES ".*INFO:abi\\[([^]]*)\\].*")
  50. ENDFOREACH(info)
  51. IF(ABI_SIZEOF_DPTR)
  52. SET(CMAKE_${lang}_SIZEOF_DATA_PTR "${ABI_SIZEOF_DPTR}" PARENT_SCOPE)
  53. ENDIF(ABI_SIZEOF_DPTR)
  54. IF(ABI_NAME)
  55. SET(CMAKE_${lang}_COMPILER_ABI "${ABI_NAME}" PARENT_SCOPE)
  56. ENDIF(ABI_NAME)
  57. # Parse implicit linker information for this language, if available.
  58. SET(implicit_dirs "")
  59. SET(implicit_libs "")
  60. SET(MULTI_ARCH FALSE)
  61. IF(DEFINED CMAKE_OSX_ARCHITECTURES)
  62. IF( "${CMAKE_OSX_ARCHITECTURES}" MATCHES ";" )
  63. SET(MULTI_ARCH TRUE)
  64. ENDIF()
  65. ENDIF()
  66. IF(CMAKE_${lang}_VERBOSE_FLAG
  67. # Implicit link information cannot be used explicitly for
  68. # multiple OS X architectures, so we skip it.
  69. AND NOT MULTI_ARCH
  70. # Skip this with Xcode for now.
  71. AND NOT "${CMAKE_GENERATOR}" MATCHES Xcode)
  72. CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs log
  73. "${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}")
  74. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
  75. "Parsed ${lang} implicit link information from above output:\n${log}\n\n")
  76. ENDIF()
  77. # for VS IDE Intel Fortran we have to figure out the
  78. # implicit link path for the fortran run time using
  79. # a try-compile
  80. IF("${lang}" MATCHES "Fortran"
  81. AND "${CMAKE_GENERATOR}" MATCHES "Visual Studio")
  82. SET(_desc "Determine Intel Fortran Compiler Implicit Link Path")
  83. MESSAGE(STATUS "${_desc}")
  84. # Build a sample project which reports symbols.
  85. TRY_COMPILE(IFORT_LIB_PATH_COMPILED
  86. ${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath
  87. ${CMAKE_ROOT}/Modules/IntelVSImplicitPath
  88. IntelFortranImplicit
  89. CMAKE_FLAGS
  90. "-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}"
  91. OUTPUT_VARIABLE _output)
  92. FILE(READ
  93. ${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/implict_link.txt
  94. dir)
  95. LIST(APPEND implicit_dirs "${dir}")
  96. FILE(WRITE
  97. "${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.txt"
  98. "${_output}")
  99. SET(_desc "Determine Intel Fortran Compiler Implicit Link Path -- done")
  100. MESSAGE(STATUS "${_desc}")
  101. ENDIF()
  102. SET(CMAKE_${lang}_IMPLICIT_LINK_LIBRARIES "${implicit_libs}" PARENT_SCOPE)
  103. SET(CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES "${implicit_dirs}" PARENT_SCOPE)
  104. # Detect library architecture directory name.
  105. IF(CMAKE_LIBRARY_ARCHITECTURE_REGEX)
  106. FOREACH(dir ${implicit_dirs})
  107. IF("${dir}" MATCHES "/lib/${CMAKE_LIBRARY_ARCHITECTURE_REGEX}$")
  108. GET_FILENAME_COMPONENT(arch "${dir}" NAME)
  109. SET(CMAKE_${lang}_LIBRARY_ARCHITECTURE "${arch}" PARENT_SCOPE)
  110. BREAK()
  111. ENDIF()
  112. ENDFOREACH()
  113. ENDIF()
  114. ELSE(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  115. MESSAGE(STATUS "Detecting ${lang} compiler ABI info - failed")
  116. FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
  117. "Detecting ${lang} compiler ABI info failed to compile with the following output:\n${OUTPUT}\n\n")
  118. ENDIF(CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  119. ENDIF(NOT DEFINED CMAKE_DETERMINE_${lang}_ABI_COMPILED)
  120. ENDFUNCTION(CMAKE_DETERMINE_COMPILER_ABI)