From a61ae3fb8017a297bd3f3efc447a1f1f29619bdf Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 17 Apr 2018 13:12:01 -0400 Subject: CheckIncludeFiles: Honor CMAKE_REQUIRED_LIBRARIES Other check modules honor this variable, so include file checks should too. Add policy `CMP0075` to enable the behavior in a compatible way. This change was originally made by commit v3.11.0-rc1~108^2 (CheckIncludeFiles: Honor CMAKE_REQUIRED_LIBRARIES, 2017-12-24) but it was reverted by commit v3.11.1~9^2 (Revert "CheckIncludeFiles: Honor CMAKE_REQUIRED_LIBRARIES", 2018-04-04) because the behavior change could affect checks in existing projects in an incompatible way. Fixes: #9514 --- Modules/CheckIncludeFile.cmake | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'Modules/CheckIncludeFile.cmake') diff --git a/Modules/CheckIncludeFile.cmake b/Modules/CheckIncludeFile.cmake index e5554c448a..24bc349640 100644 --- a/Modules/CheckIncludeFile.cmake +++ b/Modules/CheckIncludeFile.cmake @@ -27,6 +27,8 @@ # list of macros to define (-DFOO=bar) # ``CMAKE_REQUIRED_INCLUDES`` # list of include directories +# ``CMAKE_REQUIRED_LIBRARIES`` +# A list of libraries to link. See policy :policy:`CMP0075`. # ``CMAKE_REQUIRED_QUIET`` # execute quietly without messages # @@ -55,14 +57,39 @@ macro(CHECK_INCLUDE_FILE INCLUDE VARIABLE) string(APPEND CMAKE_C_FLAGS " ${ARGV2}") endif() + set(_CIF_LINK_LIBRARIES "") + if(CMAKE_REQUIRED_LIBRARIES) + cmake_policy(GET CMP0075 _CIF_CMP0075 + PARENT_SCOPE # undocumented, do not use outside of CMake + ) + if("x${_CIF_CMP0075}x" STREQUAL "xNEWx") + set(_CIF_LINK_LIBRARIES LINK_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES}) + elseif("x${_CIF_CMP0075}x" STREQUAL "xOLDx") + elseif(NOT _CIF_CMP0075_WARNED) + set(_CIF_CMP0075_WARNED 1) + message(AUTHOR_WARNING + "Policy CMP0075 is not set: Include file check macros honor CMAKE_REQUIRED_LIBRARIES. " + "Run \"cmake --help-policy CMP0075\" for policy details. " + "Use the cmake_policy command to set the policy and suppress this warning." + "\n" + "CMAKE_REQUIRED_LIBRARIES is set to:\n" + " ${CMAKE_REQUIRED_LIBRARIES}\n" + "For compatibility with CMake 3.11 and below this check is ignoring it." + ) + endif() + unset(_CIF_CMP0075) + endif() + try_compile(${VARIABLE} ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFile.c COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} + ${_CIF_LINK_LIBRARIES} CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILE_FLAGS} "${CHECK_INCLUDE_FILE_C_INCLUDE_DIRS}" OUTPUT_VARIABLE OUTPUT) + unset(_CIF_LINK_LIBRARIES) if(${ARGC} EQUAL 3) set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS_SAVE}) -- cgit v1.2.1