Introduce "generator expressions" to add_test()
[cmake.git] / Modules / CMakeTestCXXCompiler.cmake
blobdfa1aae2b91d5a669b4604dc19c86e5e0cc0a381
2 # This file is used by EnableLanguage in cmGlobalGenerator to
3 # determine that that selected C++ compiler can actually compile
4 # and link the most basic of programs.   If not, a fatal error
5 # is set and cmake stops processing commands and will not generate
6 # any makefiles or projects.
7 IF(NOT CMAKE_CXX_COMPILER_WORKS)
8   MESSAGE(STATUS "Check for working CXX compiler: ${CMAKE_CXX_COMPILER}")
9   FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx 
10     "#ifndef __cplusplus\n"
11     "# error \"The CMAKE_CXX_COMPILER is set to a C compiler\"\n"
12     "#endif\n"
13     "int main(){return 0;}\n")
14   TRY_COMPILE(CMAKE_CXX_COMPILER_WORKS ${CMAKE_BINARY_DIR} 
15     ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXCompiler.cxx
16     OUTPUT_VARIABLE OUTPUT)
17   SET(CXX_TEST_WAS_RUN 1)
18 ENDIF(NOT CMAKE_CXX_COMPILER_WORKS)
20 IF(NOT CMAKE_CXX_COMPILER_WORKS)
21   MESSAGE(STATUS "Check for working CXX compiler: ${CMAKE_CXX_COMPILER} -- broken")
22   # if the compiler is broken make sure to remove the platform file
23   # since Windows-cl configures both c/cxx files both need to be removed
24   # when c or c++ fails
25   FILE(REMOVE ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCPlatform.cmake )
26   FILE(REMOVE ${CMAKE_PLATFORM_ROOT_BIN}/CMakeCXXPlatform.cmake )
27   FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
28     "Determining if the CXX compiler works failed with "
29     "the following output:\n${OUTPUT}\n\n")
30   MESSAGE(FATAL_ERROR "The C++ compiler \"${CMAKE_CXX_COMPILER}\" "
31     "is not able to compile a simple test program.\nIt fails "
32     "with the following output:\n ${OUTPUT}\n\n"
33     "CMake will not be able to correctly generate this project.")
34 ELSE(NOT CMAKE_CXX_COMPILER_WORKS)
35   IF(CXX_TEST_WAS_RUN)
36     MESSAGE(STATUS "Check for working CXX compiler: ${CMAKE_CXX_COMPILER} -- works")
37     FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
38       "Determining if the CXX compiler works passed with "
39       "the following output:\n${OUTPUT}\n\n")
40   ENDIF(CXX_TEST_WAS_RUN)
41   SET(CMAKE_CXX_COMPILER_WORKS 1 CACHE INTERNAL "")
43   IF(CMAKE_CXX_COMPILER_FORCED)
44     # The compiler configuration was forced by the user.
45     # Assume the user has configured all compiler information.
46   ELSE(CMAKE_CXX_COMPILER_FORCED)
47     # Try to identify the ABI and configure it into CMakeCXXCompiler.cmake
48     INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineCompilerABI.cmake)
49     CMAKE_DETERMINE_COMPILER_ABI(CXX ${CMAKE_ROOT}/Modules/CMakeCXXCompilerABI.cpp)
50     CONFIGURE_FILE(
51       ${CMAKE_ROOT}/Modules/CMakeCXXCompiler.cmake.in
52       ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeCXXCompiler.cmake
53       @ONLY IMMEDIATE # IMMEDIATE must be here for compatibility mode <= 2.0
54       )
55   ENDIF(CMAKE_CXX_COMPILER_FORCED)
56 ENDIF(NOT CMAKE_CXX_COMPILER_WORKS)