Brad King | 86578ec | 2016-09-27 15:01:08 -0400 | [diff] [blame] | 1 | # Distributed under the OSI-approved BSD 3-Clause License. See accompanying |
| 2 | # file Copyright.txt or https://cmake.org/licensing for details. |
Bill Hoffman | b7fa820 | 2005-12-14 13:51:08 -0500 | [diff] [blame] | 3 | |
Brad King | 3a66659 | 2009-09-28 11:46:51 -0400 | [diff] [blame] | 4 | |
Brad King | 3df81b4 | 2012-08-24 09:10:34 -0400 | [diff] [blame] | 5 | if(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() |
| 10 | endif() |
| 11 | |
Kitware Robot | 77543bd | 2012-08-13 13:47:32 -0400 | [diff] [blame] | 12 | include(CMakeTestCompilerCommon) |
David Cole | f48660f | 2010-02-12 14:32:20 -0500 | [diff] [blame] | 13 | |
Jean-Christophe Fillion-Robin | 2073738 | 2020-07-21 17:35:14 -0400 | [diff] [blame] | 14 | # work around enforced code signing and / or missing executable target type |
Gregor Jasny | 11da882 | 2018-01-15 22:21:10 +0100 | [diff] [blame] | 15 | set(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE}) |
| 16 | if(_CMAKE_FEATURE_DETECTION_TARGET_TYPE) |
| 17 | set(CMAKE_TRY_COMPILE_TARGET_TYPE ${_CMAKE_FEATURE_DETECTION_TARGET_TYPE}) |
| 18 | endif() |
| 19 | |
Brad King | 3df81b4 | 2012-08-24 09:10:34 -0400 | [diff] [blame] | 20 | # Remove any cached result from an older CMake version. |
| 21 | # We now store this in CMakeCXXCompiler.cmake. |
| 22 | unset(CMAKE_CXX_COMPILER_WORKS CACHE) |
| 23 | |
Brad King | 1d21dd0 | 2020-05-25 14:12:18 -0400 | [diff] [blame] | 24 | # Try to identify the ABI and configure it into CMakeCXXCompiler.cmake |
| 25 | include(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake) |
| 26 | CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp) |
| 27 | if(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") |
| 31 | endif() |
| 32 | |
Bill Hoffman | 2f4ea98 | 2003-01-21 12:50:48 -0500 | [diff] [blame] | 33 | # This file is used by EnableLanguage in cmGlobalGenerator to |
luz.paz | 287e7a1 | 2018-02-15 22:02:13 -0500 | [diff] [blame] | 34 | # determine that the selected C++ compiler can actually compile |
Brad King | ae28d81 | 2003-08-27 16:02:37 -0400 | [diff] [blame] | 35 | # and link the most basic of programs. If not, a fatal error |
Bill Hoffman | 2f4ea98 | 2003-01-21 12:50:48 -0500 | [diff] [blame] | 36 | # is set and cmake stops processing commands and will not generate |
| 37 | # any makefiles or projects. |
Kitware Robot | 77543bd | 2012-08-13 13:47:32 -0400 | [diff] [blame] | 38 | if(NOT CMAKE_CXX_COMPILER_WORKS) |
Alex Turbov | 7b2dd9d | 2019-08-13 05:02:14 +0300 | [diff] [blame] | 39 | PrintTestCompilerStatus("CXX") |
Fred Baksik | 72e0c11 | 2019-01-08 23:52:12 -0500 | [diff] [blame] | 40 | __TestCompiler_setTryCompileTargetType() |
Kitware Robot | 77543bd | 2012-08-13 13:47:32 -0400 | [diff] [blame] | 41 | file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx |
Bill Hoffman | e78a575 | 2004-10-11 11:55:39 -0400 | [diff] [blame] | 42 | "#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") |
Brad King | 3ddd7f3 | 2021-07-15 12:58:44 -0400 | [diff] [blame] | 46 | # Clear result from normal variable. |
| 47 | unset(CMAKE_CXX_COMPILER_WORKS) |
| 48 | # Puts test result in cache variable. |
Matthew Woehlke | 2edf0fc | 2022-09-13 10:07:56 -0400 | [diff] [blame] | 49 | try_compile(CMAKE_CXX_COMPILER_WORKS |
| 50 | SOURCES ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx |
Brad King | 5f6985a | 2011-12-15 08:29:43 -0500 | [diff] [blame] | 51 | OUTPUT_VARIABLE __CMAKE_CXX_COMPILER_OUTPUT) |
Brad King | 3df81b4 | 2012-08-24 09:10:34 -0400 | [diff] [blame] | 52 | # Move result from cache to normal variable. |
| 53 | set(CMAKE_CXX_COMPILER_WORKS ${CMAKE_CXX_COMPILER_WORKS}) |
| 54 | unset(CMAKE_CXX_COMPILER_WORKS CACHE) |
Fred Baksik | 72e0c11 | 2019-01-08 23:52:12 -0500 | [diff] [blame] | 55 | __TestCompiler_restoreTryCompileTargetType() |
Brad King | 1d21dd0 | 2020-05-25 14:12:18 -0400 | [diff] [blame] | 56 | if(NOT CMAKE_CXX_COMPILER_WORKS) |
| 57 | PrintTestCompilerResult(CHECK_FAIL "broken") |
| 58 | file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log |
| 59 | "Determining if the CXX compiler works failed with " |
| 60 | "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n") |
| 61 | string(REPLACE "\n" "\n " _output "${__CMAKE_CXX_COMPILER_OUTPUT}") |
| 62 | message(FATAL_ERROR "The C++ compiler\n \"${CMAKE_CXX_COMPILER}\"\n" |
| 63 | "is not able to compile a simple test program.\nIt fails " |
| 64 | "with the following output:\n ${_output}\n\n" |
| 65 | "CMake will not be able to correctly generate this project.") |
| 66 | endif() |
| 67 | PrintTestCompilerResult(CHECK_PASS "works") |
| 68 | file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log |
| 69 | "Determining if the CXX compiler works passed with " |
| 70 | "the following output:\n${__CMAKE_CXX_COMPILER_OUTPUT}\n\n") |
Kitware Robot | 9db3116 | 2012-08-13 13:50:14 -0400 | [diff] [blame] | 71 | endif() |
Brad King | 81be61b | 2003-12-01 13:06:35 -0500 | [diff] [blame] | 72 | |
Brad King | 1d21dd0 | 2020-05-25 14:12:18 -0400 | [diff] [blame] | 73 | # Try to identify the compiler features |
| 74 | include(${CMAKE_ROOT}/Modules/CMakeDetermineCompileFeatures.cmake) |
| 75 | CMAKE_DETERMINE_COMPILE_FEATURES(CXX) |
Brad King | a28b197 | 2008-01-21 18:30:17 -0500 | [diff] [blame] | 76 | |
Brad King | 1d21dd0 | 2020-05-25 14:12:18 -0400 | [diff] [blame] | 77 | # Re-configure to save learned information. |
| 78 | configure_file( |
| 79 | ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in |
| 80 | ${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake |
| 81 | @ONLY |
| 82 | ) |
| 83 | include(${CMAKE_PLATFORM_INFO_DIR}/CMakeCXXCompiler.cmake) |
Brad King | 3df81b4 | 2012-08-24 09:10:34 -0400 | [diff] [blame] | 84 | |
Brad King | 1d21dd0 | 2020-05-25 14:12:18 -0400 | [diff] [blame] | 85 | if(CMAKE_CXX_SIZEOF_DATA_PTR) |
| 86 | foreach(f ${CMAKE_CXX_ABI_FILES}) |
| 87 | include(${f}) |
| 88 | endforeach() |
| 89 | unset(CMAKE_CXX_ABI_FILES) |
Kitware Robot | 9db3116 | 2012-08-13 13:50:14 -0400 | [diff] [blame] | 90 | endif() |
Brad King | 5f6985a | 2011-12-15 08:29:43 -0500 | [diff] [blame] | 91 | |
Gregor Jasny | 11da882 | 2018-01-15 22:21:10 +0100 | [diff] [blame] | 92 | set(CMAKE_TRY_COMPILE_TARGET_TYPE ${__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE}) |
| 93 | unset(__CMAKE_SAVED_TRY_COMPILE_TARGET_TYPE) |
Kitware Robot | 77543bd | 2012-08-13 13:47:32 -0400 | [diff] [blame] | 94 | unset(__CMAKE_CXX_COMPILER_OUTPUT) |