2 #=============================================================================
3 # Copyright 2008-2009 Kitware, Inc.
5 # Distributed under the OSI-approved BSD License (the "License");
6 # see accompanying file Copyright.txt for details.
8 # This software is distributed WITHOUT ANY WARRANTY; without even the
9 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # See the License for more information.
11 #=============================================================================
12 # (To distribute this file outside of CMake, substitute the full
13 # License text for the above reference.)
15 # Function to compile a source file to identify the compiler ABI.
16 # This is used internally by CMake and should not be included by user
19 include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
21 function(CMAKE_DETERMINE_COMPILER_ABI lang src)
22 if(NOT DEFINED CMAKE_${lang}_ABI_COMPILED)
23 message(STATUS "Detecting ${lang} compiler ABI info")
25 # Compile the ABI identification source.
26 set(BIN "${CMAKE_PLATFORM_INFO_DIR}/CMakeDetermineCompilerABI_${lang}.bin")
28 if(DEFINED CMAKE_${lang}_VERBOSE_FLAG)
29 set(CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}")
31 try_compile(CMAKE_${lang}_ABI_COMPILED
32 ${CMAKE_BINARY_DIR} ${src}
33 CMAKE_FLAGS "${CMAKE_FLAGS}"
34 "-DCMAKE_${lang}_STANDARD_LIBRARIES="
35 # We need ignore these warnings because some platforms need
36 # CMAKE_${lang}_STANDARD_LIBRARIES to link properly and we
37 # don't care when we are just determining the ABI.
38 "--no-warn-unused-cli"
39 OUTPUT_VARIABLE OUTPUT
42 # Move result from cache to normal variable.
43 set(CMAKE_${lang}_ABI_COMPILED ${CMAKE_${lang}_ABI_COMPILED})
44 unset(CMAKE_${lang}_ABI_COMPILED CACHE)
45 set(CMAKE_${lang}_ABI_COMPILED ${CMAKE_${lang}_ABI_COMPILED} PARENT_SCOPE)
47 # Load the resulting information strings.
48 if(CMAKE_${lang}_ABI_COMPILED)
49 message(STATUS "Detecting ${lang} compiler ABI info - done")
50 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
51 "Detecting ${lang} compiler ABI info compiled with the following output:\n${OUTPUT}\n\n")
52 file(STRINGS "${BIN}" ABI_STRINGS LIMIT_COUNT 2 REGEX "INFO:[^[]*\\[")
53 foreach(info ${ABI_STRINGS})
54 if("${info}" MATCHES ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*")
55 string(REGEX REPLACE ".*INFO:sizeof_dptr\\[0*([^]]*)\\].*" "\\1" ABI_SIZEOF_DPTR "${info}")
57 if("${info}" MATCHES ".*INFO:abi\\[([^]]*)\\].*")
58 string(REGEX REPLACE ".*INFO:abi\\[([^]]*)\\].*" "\\1" ABI_NAME "${info}")
63 set(CMAKE_${lang}_SIZEOF_DATA_PTR "${ABI_SIZEOF_DPTR}" PARENT_SCOPE)
64 elseif(CMAKE_${lang}_SIZEOF_DATA_PTR_DEFAULT)
65 set(CMAKE_${lang}_SIZEOF_DATA_PTR "${CMAKE_${lang}_SIZEOF_DATA_PTR_DEFAULT}" PARENT_SCOPE)
69 set(CMAKE_${lang}_COMPILER_ABI "${ABI_NAME}" PARENT_SCOPE)
72 # Parse implicit linker information for this language, if available.
76 if(DEFINED CMAKE_OSX_ARCHITECTURES)
77 if( "${CMAKE_OSX_ARCHITECTURES}" MATCHES ";" )
81 if(CMAKE_${lang}_VERBOSE_FLAG
82 # Implicit link information cannot be used explicitly for
83 # multiple OS X architectures, so we skip it.
85 # Skip this with Xcode for now.
86 AND NOT "${CMAKE_GENERATOR}" MATCHES Xcode)
87 CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs log
88 "${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}")
89 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
90 "Parsed ${lang} implicit link information from above output:\n${log}\n\n")
92 # for VS IDE Intel Fortran we have to figure out the
93 # implicit link path for the fortran run time using
95 if("${lang}" MATCHES "Fortran"
96 AND "${CMAKE_GENERATOR}" MATCHES "Visual Studio")
97 set(_desc "Determine Intel Fortran Compiler Implicit Link Path")
98 message(STATUS "${_desc}")
99 # Build a sample project which reports symbols.
100 try_compile(IFORT_LIB_PATH_COMPILED
101 ${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath
102 ${CMAKE_ROOT}/Modules/IntelVSImplicitPath
105 "-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}"
106 OUTPUT_VARIABLE _output)
108 "${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.txt"
110 include(${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.cmake OPTIONAL)
111 set(_desc "Determine Intel Fortran Compiler Implicit Link Path -- done")
112 message(STATUS "${_desc}")
115 set(CMAKE_${lang}_IMPLICIT_LINK_LIBRARIES "${implicit_libs}" PARENT_SCOPE)
116 set(CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES "${implicit_dirs}" PARENT_SCOPE)
118 # Detect library architecture directory name.
119 if(CMAKE_LIBRARY_ARCHITECTURE_REGEX)
120 foreach(dir ${implicit_dirs})
121 if("${dir}" MATCHES "/lib/${CMAKE_LIBRARY_ARCHITECTURE_REGEX}$")
122 get_filename_component(arch "${dir}" NAME)
123 set(CMAKE_${lang}_LIBRARY_ARCHITECTURE "${arch}" PARENT_SCOPE)
130 message(STATUS "Detecting ${lang} compiler ABI info - failed")
131 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
132 "Detecting ${lang} compiler ABI info failed to compile with the following output:\n${OUTPUT}\n\n")