From 7669695a74959dbad7c801facea4c7428875ffc3 Mon Sep 17 00:00:00 2001 From: David Adam Date: Wed, 8 Nov 2017 23:01:42 +0800 Subject: CheckIncludeFiles: extend to allow a LANGUAGE argument Allows CheckIncludeFiles to work for C or C++. --- Modules/CheckIncludeFiles.cmake | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/Modules/CheckIncludeFiles.cmake b/Modules/CheckIncludeFiles.cmake index bef11a5..3b43d28 100644 --- a/Modules/CheckIncludeFiles.cmake +++ b/Modules/CheckIncludeFiles.cmake @@ -12,13 +12,16 @@ # # :: # -# CHECK_INCLUDE_FILES("" ) +# CHECK_INCLUDE_FILES("" [LANGUAGE ]) # # Check if the given ```` list may be included together # in a ``C`` source file and store the result in an internal cache # entry named ````. Specify the ```` argument # as a :ref:`;-list ` of header file names. # +# If LANGUAGE is set, the specified compiler will be used to perform the +# check. Acceptable values are C and CXX. +# # The following variables may be set before calling this macro to modify # the way the check is run: # @@ -37,6 +40,29 @@ 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") + endif() + elseif("x${ARGN}" MATCHES "^xLANGUAGE;([a-zA-Z]+)$") + set(_lang "${CMAKE_MATCH_1}") + 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 +77,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 +94,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} -- cgit v0.12 From ea1bb90270357ecd033c11c941b83e76e6d1525b Mon Sep 17 00:00:00 2001 From: David Adam Date: Sat, 11 Nov 2017 23:02:08 +0800 Subject: CheckIncludeFiles: add unit tests --- .../CheckModules/CheckIncludeFilesMissingLanguage-result.txt | 1 + .../CheckModules/CheckIncludeFilesMissingLanguage-stderr.txt | 8 ++++++++ .../CheckModules/CheckIncludeFilesMissingLanguage.cmake | 3 +++ Tests/RunCMake/CheckModules/CheckIncludeFilesOk.cmake | 6 ++++++ Tests/RunCMake/CheckModules/CheckIncludeFilesOkNoC.cmake | 4 ++++ .../CheckModules/CheckIncludeFilesUnknownArgument-result.txt | 1 + .../CheckModules/CheckIncludeFilesUnknownArgument-stderr.txt | 8 ++++++++ .../CheckModules/CheckIncludeFilesUnknownArgument.cmake | 3 +++ .../CheckModules/CheckIncludeFilesUnknownLanguage-result.txt | 1 + .../CheckModules/CheckIncludeFilesUnknownLanguage-stderr.txt | 10 ++++++++++ .../CheckModules/CheckIncludeFilesUnknownLanguage.cmake | 3 +++ Tests/RunCMake/CheckModules/RunCMakeTest.cmake | 6 ++++++ 12 files changed, 54 insertions(+) create mode 100644 Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-result.txt create mode 100644 Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-stderr.txt create mode 100644 Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage.cmake create mode 100644 Tests/RunCMake/CheckModules/CheckIncludeFilesOk.cmake create mode 100644 Tests/RunCMake/CheckModules/CheckIncludeFilesOkNoC.cmake create mode 100644 Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownArgument-result.txt create mode 100644 Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownArgument-stderr.txt create mode 100644 Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownArgument.cmake create mode 100644 Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownLanguage-result.txt create mode 100644 Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownLanguage-stderr.txt create mode 100644 Tests/RunCMake/CheckModules/CheckIncludeFilesUnknownLanguage.cmake 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..4b31dbd --- /dev/null +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-stderr.txt @@ -0,0 +1,8 @@ +CMake Error at .*/Modules/CheckIncludeFiles.cmake:[0-9]+. \(message\): + Unknown arguments: + + LANGUAGE + +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) -- cgit v0.12 From c860999213fcf6114084688cad7b8e70264401cc Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 14 Nov 2017 09:07:38 -0500 Subject: Help: Add notes for topic 'CheckIncludeFiles-language-CXX' --- Help/release/dev/CheckIncludeFiles-language-CXX.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Help/release/dev/CheckIncludeFiles-language-CXX.rst 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. -- cgit v0.12 From 1f1c2a9fdf84e1fb6f3399f7f30ad8b7c8d8669d Mon Sep 17 00:00:00 2001 From: David Adam Date: Fri, 24 Nov 2017 15:34:54 +0800 Subject: CheckIncludeFiles: clean up documentation of new features --- Modules/CheckIncludeFiles.cmake | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Modules/CheckIncludeFiles.cmake b/Modules/CheckIncludeFiles.cmake index 3b43d28..1a217b3 100644 --- a/Modules/CheckIncludeFiles.cmake +++ b/Modules/CheckIncludeFiles.cmake @@ -6,7 +6,7 @@ # ----------------- # # 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 # @@ -15,12 +15,14 @@ # CHECK_INCLUDE_FILES("" [LANGUAGE ]) # # Check if the given ```` 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 ````. Specify the ```` argument # as a :ref:`;-list ` of header file names. # # If LANGUAGE is set, the specified compiler will be used to perform the -# check. Acceptable values are C and CXX. +# 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: -- cgit v0.12 From b31d5e1dfdea5abcf95de05baf7b0e53cc18937a Mon Sep 17 00:00:00 2001 From: David Adam Date: Fri, 24 Nov 2017 15:50:14 +0800 Subject: CheckIncludeFiles: improve warning for missing argument --- Modules/CheckIncludeFiles.cmake | 8 +++++--- .../CheckModules/CheckIncludeFilesMissingLanguage-stderr.txt | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Modules/CheckIncludeFiles.cmake b/Modules/CheckIncludeFiles.cmake index 1a217b3..347231c 100644 --- a/Modules/CheckIncludeFiles.cmake +++ b/Modules/CheckIncludeFiles.cmake @@ -49,12 +49,14 @@ macro(CHECK_INCLUDE_FILES INCLUDE VARIABLE) elseif(CMAKE_CXX_COMPILER_LOADED) set(_lang CXX) else() - message(FATAL_ERROR "CHECK_INCLUDE_FILES needs either C or CXX language enabled") + 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}") + 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") + message(FATAL_ERROR "Unknown arguments:\n ${ARGN}\n") endif() if(_lang STREQUAL "C") diff --git a/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-stderr.txt b/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-stderr.txt index 4b31dbd..36c28f9 100644 --- a/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-stderr.txt +++ b/Tests/RunCMake/CheckModules/CheckIncludeFilesMissingLanguage-stderr.txt @@ -1,7 +1,7 @@ CMake Error at .*/Modules/CheckIncludeFiles.cmake:[0-9]+. \(message\): - Unknown arguments: + No languages listed for LANGUAGE option. - LANGUAGE + Supported languages: C, CXX. Call Stack \(most recent call first\): CheckIncludeFilesMissingLanguage.cmake:[0-9]+ \(check_include_files\) -- cgit v0.12