blob: b9cb1dd0eb1643e317c2ef94563972641ad5b688 [file] [log] [blame]
Brad King86578ec2016-09-27 15:01:08 -04001# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2# file Copyright.txt or https://cmake.org/licensing for details.
Bill Hoffmanb7fa8202005-12-14 13:51:08 -05003
Brad King3a666592009-09-28 11:46:51 -04004
Brad King3df81b42012-08-24 09:10:34 -04005if(CMAKE_CXX_COMPILER_FORCED)
6 # The compiler configuration was forced by the user.
7 # Assume the user has configured all compiler information.
8 set(CMAKE_CXX_COMPILER_WORKS TRUE)
9 return()
10endif()
11
Kitware Robot77543bd2012-08-13 13:47:32 -040012include(CMakeTestCompilerCommon)
David Colef48660f2010-02-12 14:32:20 -050013
Gregor Jasny11da8822018-01-15 22:21:10 +010014# work around enforced code signing and / or missing exectuable target type
15set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})
16if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE)
17 set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE})
18endif()
19
Brad King3df81b42012-08-24 09:10:34 -040020# Remove any cached result from an older CMake version.
21# We now store this in CMakeCXXCompiler.cmake.
22unset(CMAKE_CXX_COMPILER_WORKS CACHE)
23
Brad King1d21dd02020-05-25 14:12:18 -040024# Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
25include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
26CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
27if(CMAKE_CXX_ABI_COMPILED)
28 # The compiler worked so skip dedicated test below.
29 set(CMAKE_CXX_COMPILER_WORKS TRUE)
30 message(STATUS "Check for working CXX compiler: ${CMAKE_CXX_COMPILER} - skipped")
31endif()
32
Bill Hoffman2f4ea982003-01-21 12:50:48 -050033# This file is used by EnableLanguage in cmGlobalGenerator to
luz.paz287e7a12018-02-15 22:02:13 -050034# determine that the selected C++ compiler can actually compile
Brad Kingae28d812003-08-27 16:02:37 -040035# and link the most basic of programs. If not, a fatal error
Bill Hoffman2f4ea982003-01-21 12:50:48 -050036# is set and cmake stops processing commands and will not generate
37# any makefiles or projects.
Kitware Robot77543bd2012-08-13 13:47:32 -040038if(NOT CMAKE_CXX_COMPILER_WORKS)
Alex Turbov7b2dd9d2019-08-13 05:02:14 +030039 PrintTestCompilerStatus("CXX")
Fred Baksik72e0c112019-01-08 23:52:12 -050040 __TestCompiler_setTryCompileTargetType()
Kitware Robot77543bd2012-08-13 13:47:32 -040041 file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
Bill Hoffmane78a5752004-10-11 11:55:39 -040042 "#ifndef __cplusplus\n"
43 "# error \"The CMAKE_CXX_COMPILER is set to a C compiler\"\n"
44 "#endif\n"
45 "int main(){return 0;}\n")
Kitware Robot77543bd2012-08-13 13:47:32 -040046 try_compile(CMAKE_CXX_COMPILER_WORKS ${CMAKE_BINARY_DIR}
Ken Martin8e9a6be2006-06-14 12:28:32 -040047 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
Brad King5f6985a2011-12-15 08:29:43 -050048 OUTPUT_VARIABLE __CMAKE_CXX_COMPILER_OUTPUT)
Brad King3df81b42012-08-24 09:10:34 -040049 # Move result from cache to normal variable.
50 set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS})
51 unset(CMAKE_CXX_COMPILER_WORKS CACHE)
Fred Baksik72e0c112019-01-08 23:52:12 -050052 __TestCompiler_restoreTryCompileTargetType()
Brad King1d21dd02020-05-25 14:12:18 -040053 if(NOT CMAKE_CXX_COMPILER_WORKS)
54 PrintTestCompilerResult(CHECK_FAIL "broken")
55 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
56 "Determining if the CXX compiler works failed with "
57 "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
58 string(REPLACE "\n" "\n " _output "${__CMAKE_CXX_COMPILER_OUTPUT}")
59 message(FATAL_ERROR "The C++ compiler\n \"${CMAKE_CXX_COMPILER}\"\n"
60 "is not able to compile a simple test program.\nIt fails "
61 "with the following output:\n ${_output}\n\n"
62 "CMake will not be able to correctly generate this project.")
63 endif()
64 PrintTestCompilerResult(CHECK_PASS "works")
65 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
66 "Determining if the CXX compiler works passed with "
67 "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n")
Kitware Robot9db31162012-08-13 13:50:14 -040068endif()
Brad King81be61b2003-12-01 13:06:35 -050069
Brad King1d21dd02020-05-25 14:12:18 -040070# Try to identify the compiler features
71include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake)
72CMAKE_DETERMINE_COMPILE_FEATURES(CXX)
Brad Kinga28b1972008-01-21 18:30:17 -050073
Brad King1d21dd02020-05-25 14:12:18 -040074# Re-configure to save learned information.
75configure_file(
76 ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in
77 ${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake
78 @ONLY
79 )
80include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake)
Brad King3df81b42012-08-24 09:10:34 -040081
Brad King1d21dd02020-05-25 14:12:18 -040082if(CMAKE_CXX_SIZEOF_DATA_PTR)
83 foreach(f ${CMAKE_CXX_ABI_FILES})
84 include(${f})
85 endforeach()
86 unset(CMAKE_CXX_ABI_FILES)
Kitware Robot9db31162012-08-13 13:50:14 -040087endif()
Brad King5f6985a2011-12-15 08:29:43 -050088
Gregor Jasny11da8822018-01-15 22:21:10 +010089set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE})
90unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE)
Kitware Robot77543bd2012-08-13 13:47:32 -040091unset(__CMAKE_CXX_COMPILER_OUTPUT)