2016-09-27 22:01:08 +03:00
|
|
|
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
# file Copyright.txt or https://cmake.org/licensing for details.
|
2008-01-22 02:30:17 +03:00
|
|
|
|
2009-09-28 19:46:51 +04:00
|
|
|
|
2008-01-22 02:30:17 +03:00
|
|
|
# Function to compile a source file to identify the compiler ABI.
|
|
|
|
# This is used internally by CMake and should not be included by user
|
|
|
|
# code.
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
include(${CMAKE_ROOT}/Modules/CMakeParseImplicitLinkInfo.cmake)
|
2009-07-23 18:07:25 +04:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
function(CMAKE_DETERMINE_COMPILER_ABI lang src)
|
2012-08-24 23:15:14 +04:00
|
|
|
if(NOT DEFINED CMAKE_${lang}_ABI_COMPILED)
|
2012-08-13 21:47:32 +04:00
|
|
|
message(STATUS "Detecting ${lang} compiler ABI info")
|
2008-01-22 02:30:17 +03:00
|
|
|
|
|
|
|
# Compile the ABI identification source.
|
2012-08-24 16:48:59 +04:00
|
|
|
set(BIN "${CMAKE_PLATFORM_INFO_DIR}/CMakeDetermineCompilerABI_${lang}.bin")
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CMAKE_FLAGS )
|
|
|
|
if(DEFINED CMAKE_${lang}_VERBOSE_FLAG)
|
2014-12-03 22:52:05 +03:00
|
|
|
set(CMAKE_FLAGS "-DEXE_LINKER_FLAGS=${CMAKE_${lang}_VERBOSE_FLAG}")
|
2012-08-13 21:47:32 +04:00
|
|
|
endif()
|
2014-08-19 17:04:25 +04:00
|
|
|
if(NOT "x${CMAKE_${lang}_COMPILER_ID}" STREQUAL "xMSVC")
|
|
|
|
# Avoid adding our own platform standard libraries for compilers
|
|
|
|
# from which we might detect implicit link libraries.
|
|
|
|
list(APPEND CMAKE_FLAGS "-DCMAKE_${lang}_STANDARD_LIBRARIES=")
|
|
|
|
endif()
|
2012-08-24 23:15:14 +04:00
|
|
|
try_compile(CMAKE_${lang}_ABI_COMPILED
|
2008-01-22 02:30:17 +03:00
|
|
|
${CMAKE_BINARY_DIR} ${src}
|
2014-08-19 17:04:25 +04:00
|
|
|
CMAKE_FLAGS ${CMAKE_FLAGS}
|
|
|
|
# Ignore unused flags when we are just determining the ABI.
|
2010-09-17 01:49:37 +04:00
|
|
|
"--no-warn-unused-cli"
|
2008-01-22 02:30:17 +03:00
|
|
|
OUTPUT_VARIABLE OUTPUT
|
|
|
|
COPY_FILE "${BIN}"
|
2013-07-17 22:56:40 +04:00
|
|
|
COPY_FILE_ERROR _copy_error
|
2008-01-22 02:30:17 +03:00
|
|
|
)
|
2012-08-24 23:15:14 +04:00
|
|
|
# Move result from cache to normal variable.
|
|
|
|
set(CMAKE_${lang}_ABI_COMPILED ${CMAKE_${lang}_ABI_COMPILED})
|
|
|
|
unset(CMAKE_${lang}_ABI_COMPILED CACHE)
|
|
|
|
set(CMAKE_${lang}_ABI_COMPILED ${CMAKE_${lang}_ABI_COMPILED} PARENT_SCOPE)
|
2008-01-22 02:30:17 +03:00
|
|
|
|
|
|
|
# Load the resulting information strings.
|
2013-07-17 22:56:40 +04:00
|
|
|
if(CMAKE_${lang}_ABI_COMPILED AND NOT _copy_error)
|
2012-08-13 21:47:32 +04:00
|
|
|
message(STATUS "Detecting ${lang} compiler ABI info - done")
|
|
|
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
2008-04-14 23:25:57 +04:00
|
|
|
"Detecting ${lang} compiler ABI info compiled with the following output:\n${OUTPUT}\n\n")
|
2014-09-04 01:00:48 +04:00
|
|
|
file(STRINGS "${BIN}" ABI_STRINGS LIMIT_COUNT 2 REGEX "INFO:[A-Za-z0-9_]+\\[[^]]*\\]")
|
2012-08-13 21:47:32 +04:00
|
|
|
foreach(info ${ABI_STRINGS})
|
2014-04-11 20:17:46 +04:00
|
|
|
if("${info}" MATCHES "INFO:sizeof_dptr\\[0*([^]]*)\\]")
|
2014-04-06 23:30:00 +04:00
|
|
|
set(ABI_SIZEOF_DPTR "${CMAKE_MATCH_1}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2014-04-11 20:17:46 +04:00
|
|
|
if("${info}" MATCHES "INFO:abi\\[([^]]*)\\]")
|
2014-04-06 23:30:00 +04:00
|
|
|
set(ABI_NAME "${CMAKE_MATCH_1}")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endforeach()
|
2008-01-22 02:30:17 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(ABI_SIZEOF_DPTR)
|
|
|
|
set(CMAKE_${lang}_SIZEOF_DATA_PTR "${ABI_SIZEOF_DPTR}" PARENT_SCOPE)
|
|
|
|
elseif(CMAKE_${lang}_SIZEOF_DATA_PTR_DEFAULT)
|
|
|
|
set(CMAKE_${lang}_SIZEOF_DATA_PTR "${CMAKE_${lang}_SIZEOF_DATA_PTR_DEFAULT}" PARENT_SCOPE)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-01-22 02:30:17 +03:00
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
if(ABI_NAME)
|
|
|
|
set(CMAKE_${lang}_COMPILER_ABI "${ABI_NAME}" PARENT_SCOPE)
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
2008-01-22 02:30:17 +03:00
|
|
|
|
2009-07-23 18:07:25 +04:00
|
|
|
# Parse implicit linker information for this language, if available.
|
2012-08-13 21:47:32 +04:00
|
|
|
set(implicit_dirs "")
|
|
|
|
set(implicit_libs "")
|
2012-12-05 22:46:04 +04:00
|
|
|
set(implicit_fwks "")
|
2012-12-05 20:49:13 +04:00
|
|
|
if(CMAKE_${lang}_VERBOSE_FLAG)
|
2012-12-05 22:46:04 +04:00
|
|
|
CMAKE_PARSE_IMPLICIT_LINK_INFO("${OUTPUT}" implicit_libs implicit_dirs implicit_fwks log
|
2010-12-10 01:07:34 +03:00
|
|
|
"${CMAKE_${lang}_IMPLICIT_OBJECT_REGEX}")
|
2012-08-13 21:47:32 +04:00
|
|
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
|
2009-10-06 23:16:12 +04:00
|
|
|
"Parsed ${lang} implicit link information from above output:\n${log}\n\n")
|
2012-08-13 21:47:32 +04:00
|
|
|
endif()
|
2011-09-09 01:42:49 +04:00
|
|
|
# for VS IDE Intel Fortran we have to figure out the
|
|
|
|
# implicit link path for the fortran run time using
|
|
|
|
# a try-compile
|
2012-08-13 21:47:32 +04:00
|
|
|
if("${lang}" MATCHES "Fortran"
|
2011-09-09 01:42:49 +04:00
|
|
|
AND "${CMAKE_GENERATOR}" MATCHES "Visual Studio")
|
2012-08-13 21:47:32 +04:00
|
|
|
set(_desc "Determine Intel Fortran Compiler Implicit Link Path")
|
|
|
|
message(STATUS "${_desc}")
|
2011-09-09 01:42:49 +04:00
|
|
|
# Build a sample project which reports symbols.
|
2012-08-13 21:47:32 +04:00
|
|
|
try_compile(IFORT_LIB_PATH_COMPILED
|
2011-09-09 01:42:49 +04:00
|
|
|
${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath
|
2011-09-14 21:49:40 +04:00
|
|
|
${CMAKE_ROOT}/Modules/IntelVSImplicitPath
|
2011-09-09 01:42:49 +04:00
|
|
|
IntelFortranImplicit
|
|
|
|
CMAKE_FLAGS
|
|
|
|
"-DCMAKE_Fortran_FLAGS:STRING=${CMAKE_Fortran_FLAGS}"
|
|
|
|
OUTPUT_VARIABLE _output)
|
2012-08-13 21:47:32 +04:00
|
|
|
file(WRITE
|
2011-09-09 01:42:49 +04:00
|
|
|
"${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.txt"
|
|
|
|
"${_output}")
|
2012-08-13 21:47:32 +04:00
|
|
|
include(${CMAKE_BINARY_DIR}/CMakeFiles/IntelVSImplicitPath/output.cmake OPTIONAL)
|
|
|
|
set(_desc "Determine Intel Fortran Compiler Implicit Link Path -- done")
|
|
|
|
message(STATUS "${_desc}")
|
|
|
|
endif()
|
2011-09-09 01:42:49 +04:00
|
|
|
|
2012-12-05 20:49:13 +04:00
|
|
|
# Implicit link libraries cannot be used explicitly for multiple
|
|
|
|
# OS X architectures, so we skip it.
|
|
|
|
if(DEFINED CMAKE_OSX_ARCHITECTURES)
|
|
|
|
if("${CMAKE_OSX_ARCHITECTURES}" MATCHES ";")
|
|
|
|
set(implicit_libs "")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2012-08-13 21:47:32 +04:00
|
|
|
set(CMAKE_${lang}_IMPLICIT_LINK_LIBRARIES "${implicit_libs}" PARENT_SCOPE)
|
|
|
|
set(CMAKE_${lang}_IMPLICIT_LINK_DIRECTORIES "${implicit_dirs}" PARENT_SCOPE)
|
2012-12-05 22:46:04 +04:00
|
|
|
set(CMAKE_${lang}_IMPLICIT_LINK_FRAMEWORK_DIRECTORIES "${implicit_fwks}" PARENT_SCOPE)
|
2009-07-23 18:07:25 +04:00
|
|
|
|
2011-06-08 16:46:31 +04:00
|
|
|
# Detect library architecture directory name.
|
2012-08-13 21:47:32 +04:00
|
|
|
if(CMAKE_LIBRARY_ARCHITECTURE_REGEX)
|
|
|
|
foreach(dir ${implicit_dirs})
|
|
|
|
if("${dir}" MATCHES "/lib/${CMAKE_LIBRARY_ARCHITECTURE_REGEX}$")
|
|
|
|
get_filename_component(arch "${dir}" NAME)
|
|
|
|
set(CMAKE_${lang}_LIBRARY_ARCHITECTURE "${arch}" PARENT_SCOPE)
|
|
|
|
break()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
2011-06-08 16:46:31 +04:00
|
|
|
|
2012-08-13 21:50:14 +04:00
|
|
|
else()
|
2012-08-13 21:47:32 +04:00
|
|
|
message(STATUS "Detecting ${lang} compiler ABI info - failed")
|
|
|
|
file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
|
2013-07-17 22:56:40 +04:00
|
|
|
"Detecting ${lang} compiler ABI info failed to compile with the following output:\n${OUTPUT}\n${_copy_error}\n\n")
|
2012-08-13 21:50:14 +04:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|