1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
4 #[=======================================================================[.rst:
10 See :module:`CheckCXXCompilerFlag`.
12 Check if the CXX compiler accepts a flag.
16 CHECK_CXX_ACCEPTS_FLAG(<flags> <variable>)
21 variable to store the result
22 #]=======================================================================]
24 macro(CHECK_CXX_ACCEPTS_FLAG FLAGS VARIABLE)
25 if(NOT DEFINED ${VARIABLE})
26 message(CHECK_START "Checking to see if CXX compiler accepts flag ${FLAGS}")
27 try_compile(${VARIABLE}
29 ${CMAKE_ROOT}/Modules/DummyCXXFile.cxx
30 CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${FLAGS}
31 OUTPUT_VARIABLE OUTPUT)
33 message(CHECK_PASS "yes")
34 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
35 "Determining if the CXX compiler accepts the flag ${FLAGS} passed with "
36 "the following output:\n${OUTPUT}\n\n")
38 message(CHECK_FAIL "no")
39 file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
40 "Determining if the CXX compiler accepts the flag ${FLAGS} failed with "
41 "the following output:\n${OUTPUT}\n\n")