diff options
14 files changed, 95 insertions, 5 deletions
diff --git a/Help/release/dev/CheckIncludeFiles-language-CXX.rst b/Help/release/dev/CheckIncludeFiles-language-CXX.rst new file mode 100644 index 0000000..1631a5e --- /dev/null +++ b/Help/release/dev/CheckIncludeFiles-language-CXX.rst @@ -0,0 +1,6 @@ +CheckIncludeFiles-language-CXX +------------------------------ + +* The :module:`CheckIncludeFiles` module :command:`CHECK_INCLUDE_FILES` + command gained a ``LANGUAGE`` option to specify whether to check using the + ``C`` or ``CXX`` compiler. diff --git a/Modules/CheckIncludeFiles.cmake b/Modules/CheckIncludeFiles.cmake index bef11a5..347231c 100644 --- a/Modules/CheckIncludeFiles.cmake +++ b/Modules/CheckIncludeFiles.cmake @@ -6,19 +6,24 @@ # ----------------- # # Provides a macro to check if a list of one or more header files can -# be included together in ``C``. +# be included together. # # .. command:: CHECK_INCLUDE_FILES # # :: # -# CHECK_INCLUDE_FILES("<includes>" <variable>) +# CHECK_INCLUDE_FILES("<includes>" <variable> [LANGUAGE <language>]) # # Check if the given ``<includes>`` list may be included together -# in a ``C`` source file and store the result in an internal cache +# in a source file and store the result in an internal cache # entry named ``<variable>``. Specify the ``<includes>`` argument # as a :ref:`;-list <CMake Language Lists>` of header file names. # +# If LANGUAGE is set, the specified compiler will be used to perform the +# check. Acceptable values are ``C`` and ``CXX``. If not set, the C compiler +# will be used if enabled. If the C compiler is not enabled, the C++ +# compiler will be used if enabled. +# # The following variables may be set before calling this macro to modify # the way the check is run: # @@ -37,6 +42,31 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE) if(NOT DEFINED "${VARIABLE}") set(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n") + + if("x${ARGN}" STREQUAL "x") + if(CMAKE_C_COMPILER_LOADED) + set(_lang C) + elseif(CMAKE_CXX_COMPILER_LOADED) + set(_lang CXX) + else() + message(FATAL_ERROR "CHECK_INCLUDE_FILES needs either C or CXX language enabled.\n") + endif() + elseif("x${ARGN}" MATCHES "^xLANGUAGE;([a-zA-Z]+)$") + set(_lang "${CMAKE_MATCH_1}") + elseif("x${ARGN}" MATCHES "^xLANGUAGE$") + message(FATAL_ERROR "No languages listed for LANGUAGE option.\nSupported languages: C, CXX.\n") + else() + message(FATAL_ERROR "Unknown arguments:\n ${ARGN}\n") + endif() + + if(_lang STREQUAL "C") + set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckIncludeFiles/${var}.c) + elseif(_lang STREQUAL "CXX") + set(src ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CheckIncludeFiles/${var}.cpp) + else() + message(FATAL_ERROR "Unknown language:\n ${_lang}\nSupported languages: C, CXX.\n") + endif() + if(CMAKE_REQUIRED_INCLUDES) set(CHECK_INCLUDE_FILES_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}") else() @@ -51,7 +81,7 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE) string(APPEND CMAKE_CONFIGURABLE_FILE_CONTENT "\n\nint main(void){return 0;}\n") configure_file("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in" - "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c" @ONLY) + "${src}" @ONLY) set(_INCLUDE ${INCLUDE}) # remove empty elements if("${_INCLUDE}" MATCHES "^([^;]+);.+;([^;]+)$") @@ -68,7 +98,7 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE) endif() try_compile(${VARIABLE} ${CMAKE_BINARY_DIR} - ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.c + ${src} COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_FLAGS} diff --git a/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-result.txt b/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-stderr.txt b/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-stderr.txt new file mode 100644 index 0000000..36c28f9 --- /dev/null +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at .*/Modules/CheckIncludeFiles.cmake:[0-9]+. \(message\): + No languages listed for LANGUAGE option. + + Supported languages: C, CXX. + +Call Stack \(most recent call first\): + CheckIncludeFilesMissingLanguage.cmake:[0-9]+ \(check_include_files\) + CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage.cmake b/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage.cmake new file mode 100644 index 0000000..59accb0 --- /dev/null +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage.cmake @@ -0,0 +1,3 @@ +enable_language(C) +include(CheckIncludeFiles) +check_include_files("stddef.h;stdlib.h" HAVE_MISSING_ARGUMENT_H LANGUAGE) diff --git a/Tests/RunCMake/CheckModules/CheckIncludeFilesOk.cmake b/Tests/RunCMake/CheckModules/CheckIncludeFilesOk.cmake new file mode 100644 index 0000000..0891ec6 --- /dev/null +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesOk.cmake @@ -0,0 +1,6 @@ +enable_language(C) +enable_language(CXX) +include(CheckIncludeFiles) +check_include_files("stddef.h;stdlib.h" HAVE_STDLIB_H) +check_include_files("stddef.h;stdlib.h" HAVE_STDLIB_H2 LANGUAGE C) +check_include_files("cstddef;cstdlib" HAVE_CSTDLIB_H LANGUAGE CXX) diff --git a/Tests/RunCMake/CheckModules/CheckIncludeFilesOkNoC.cmake b/Tests/RunCMake/CheckModules/CheckIncludeFilesOkNoC.cmake new file mode 100644 index 0000000..a1d2843 --- /dev/null +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesOkNoC.cmake @@ -0,0 +1,4 @@ +enable_language(CXX) +include(CheckIncludeFiles) +check_include_files("cstddef;cstdlib" HAVE_CSTDLIB_H3 LANGUAGE CXX) +check_include_files("cstddef;cstdlib" HAVE_CSTDLIB_H4) diff --git a/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownArgument-result.txt b/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownArgument-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownArgument-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownArgument-stderr.txt b/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownArgument-stderr.txt new file mode 100644 index 0000000..098da79 --- /dev/null +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownArgument-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at .*/Modules/CheckIncludeFiles.cmake:[0-9]+. \(message\): + Unknown arguments: + + FOOBAR + +Call Stack \(most recent call first\): + CheckIncludeFilesUnknownArgument.cmake:[0-9]+ \(check_include_files\) + CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownArgument.cmake b/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownArgument.cmake new file mode 100644 index 0000000..dfc2b93 --- /dev/null +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownArgument.cmake @@ -0,0 +1,3 @@ +enable_language(C) +include(CheckIncludeFiles) +check_include_files("stddef.h;stdlib.h" HAVE_UNKNOWN_ARGUMENT_H FOOBAR) diff --git a/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownLanguage-result.txt b/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownLanguage-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownLanguage-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownLanguage-stderr.txt b/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownLanguage-stderr.txt new file mode 100644 index 0000000..5d4a9ec --- /dev/null +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownLanguage-stderr.txt @@ -0,0 +1,10 @@ +CMake Error at .*/Modules/CheckIncludeFiles.cmake:[0-9]+. \(message\): + Unknown language: + + FOOBAR + + Supported languages: C, CXX. + +Call Stack \(most recent call first\): + CheckIncludeFilesUnknownLanguage.cmake:[0-9]+ \(check_include_files\) + CMakeLists.txt:[0-9]+ \(include\) diff --git a/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownLanguage.cmake b/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownLanguage.cmake new file mode 100644 index 0000000..3a77cf9 --- /dev/null +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownLanguage.cmake @@ -0,0 +1,3 @@ +enable_language(C) +include(CheckIncludeFiles) +check_include_files("stddef.h;stdlib.h" HAVE_UNKNOWN_ARGUMENT_H LANGUAGE FOOBAR) diff --git a/Tests/RunCMake/CheckModules/RunCMakeTest.cmake b/Tests/RunCMake/CheckModules/RunCMakeTest.cmake index 5b4e57e..c5aaa64 100644 --- a/Tests/RunCMake/CheckModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CheckModules/RunCMakeTest.cmake @@ -14,3 +14,9 @@ run_cmake(CheckTypeSizeUnknownArgument) run_cmake(CheckTypeSizeMixedArgs) run_cmake(CheckTypeSizeOkNoC) + +run_cmake(CheckIncludeFilesOk) +run_cmake(CheckIncludeFilesOkNoC) +run_cmake(CheckIncludeFilesMissingLanguage) +run_cmake(CheckIncludeFilesUnknownArgument) +run_cmake(CheckIncludeFilesUnknownLanguage) |