Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / CMakeDetermineCompilerABI.cmake
1
2 #=============================================================================
3 # Copyright 2008-2009 Kitware, Inc.
4 #
5 # Distributed under the OSI-approved BSD License (the "License");
6 # see accompanying file Copyright.txt for details.
7 #
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.)
14
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
17 # code.
18
19 include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
20
21 function(CMAKE_DETERMINE_COMPILER_ABI lang src)
22   if(NOT DEFINED CMAKE_${lang}_ABI_COMPILED)
23     message(STATUS "Detecting ${lang} compiler ABI info")
24
25     # Compile the ABI identification source.
26     set(BIN "${CMAKE_PLATFORM_INFO_DIR}/CMakeDetermineCompilerABI_${lang}.bin")
27     set(CMAKE_FLAGS )
28     if(DEFINED CMAKE_${lang}_VERBOSE_FLAG)
29       set(CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}")
30     endif()
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
40       COPY_FILE "${BIN}"
41       )
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)
46
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}")
56         endif()
57         if("${info}" MATCHES ".*INFO:abi\\[([^]]*)\\].*")
58           string(REGEX REPLACE ".*INFO:abi\\[([^]]*)\\].*" "\\1" ABI_NAME "${info}")
59         endif()
60       endforeach()
61
62       if(ABI_SIZEOF_DPTR)
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)
66       endif()
67
68       if(ABI_NAME)
69         set(CMAKE_${lang}_COMPILER_ABI "${ABI_NAME}" PARENT_SCOPE)
70       endif()
71
72       # Parse implicit linker information for this language, if available.
73       set(implicit_dirs "")
74       set(implicit_libs "")
75       set(MULTI_ARCH FALSE)
76       if(DEFINED CMAKE_OSX_ARCHITECTURES)
77         if( "${CMAKE_OSX_ARCHITECTURES}" MATCHES ";" )
78           set(MULTI_ARCH TRUE)
79         endif()
80       endif()
81       if(CMAKE_${lang}_VERBOSE_FLAG
82           # Implicit link information cannot be used explicitly for
83           # multiple OS X architectures, so we skip it.
84           AND NOT MULTI_ARCH
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")
91       endif()
92       # for VS IDE Intel Fortran we have to figure out the
93       # implicit link path for the fortran run time using
94       # a try-compile
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
103           IntelFortranImplicit
104           CMAKE_FLAGS
105           "-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}"
106           OUTPUT_VARIABLE _output)
107         file(WRITE
108           "${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.txt"
109           "${_output}")
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}")
113       endif()
114
115       set(CMAKE_${lang}_IMPLICIT_LINK_LIBRARIES "${implicit_libs}" PARENT_SCOPE)
116       set(CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES "${implicit_dirs}" PARENT_SCOPE)
117
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)
124             break()
125           endif()
126         endforeach()
127       endif()
128
129     else()
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")
133     endif()
134   endif()
135 endfunction()