mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 05:26:58 +08:00
Tests/IncludeDirectories: support MSVC in system include tests
This commit is contained in:
@@ -3,17 +3,24 @@ project(IncludeDirectories)
|
|||||||
|
|
||||||
if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4)
|
if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4)
|
||||||
OR (CMAKE_C_COMPILER_ID STREQUAL Clang AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
|
OR (CMAKE_C_COMPILER_ID STREQUAL Clang AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
|
||||||
OR CMAKE_C_COMPILER_ID STREQUAL AppleClang)
|
OR CMAKE_C_COMPILER_ID STREQUAL AppleClang
|
||||||
|
OR ("x${CMAKE_C_COMPILER_ID}" STREQUAL "xMSVC" AND
|
||||||
|
CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "19.29.30036.3" AND
|
||||||
|
NOT CMAKE_GENERATOR MATCHES "Visual Studio")) # No support for VS generators yet.
|
||||||
AND (CMAKE_GENERATOR STREQUAL "Unix Makefiles"
|
AND (CMAKE_GENERATOR STREQUAL "Unix Makefiles"
|
||||||
OR CMAKE_GENERATOR STREQUAL "Ninja"
|
OR CMAKE_GENERATOR STREQUAL "Ninja"
|
||||||
OR (CMAKE_GENERATOR STREQUAL "Xcode" AND NOT XCODE_VERSION VERSION_LESS 6.0)))
|
OR (CMAKE_GENERATOR STREQUAL "Xcode" AND NOT XCODE_VERSION VERSION_LESS 6.0)))
|
||||||
include(CheckCXXCompilerFlag)
|
if ("x${CMAKE_C_COMPILER_ID}" STREQUAL "xMSVC")
|
||||||
check_cxx_compiler_flag(-Wunused-variable run_sys_includes_test)
|
set(run_sys_includes_test 1)
|
||||||
if(run_sys_includes_test)
|
else ()
|
||||||
# The Bullseye wrapper appears to break the -isystem effect.
|
include(CheckCXXCompilerFlag)
|
||||||
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE out ERROR_VARIABLE out)
|
check_cxx_compiler_flag(-Wunused-variable run_sys_includes_test)
|
||||||
if("x${out}" MATCHES "Bullseye")
|
if(run_sys_includes_test)
|
||||||
set(run_sys_includes_test 0)
|
# The Bullseye wrapper appears to break the -isystem effect.
|
||||||
|
execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE out ERROR_VARIABLE out)
|
||||||
|
if("x${out}" MATCHES "Bullseye")
|
||||||
|
set(run_sys_includes_test 0)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
if (run_sys_includes_test)
|
if (run_sys_includes_test)
|
||||||
|
@@ -7,7 +7,11 @@ add_library(systemlib systemlib.cpp)
|
|||||||
target_include_directories(systemlib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/systemlib")
|
target_include_directories(systemlib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/systemlib")
|
||||||
|
|
||||||
function (apply_error_flags target)
|
function (apply_error_flags target)
|
||||||
target_compile_options(${target} PRIVATE -Werror=unused-variable)
|
if (MSVC)
|
||||||
|
target_compile_options(${target} PRIVATE /we4101)
|
||||||
|
else ()
|
||||||
|
target_compile_options(${target} PRIVATE -Werror=unused-variable)
|
||||||
|
endif ()
|
||||||
endfunction ()
|
endfunction ()
|
||||||
|
|
||||||
add_library(upstream upstream.cpp)
|
add_library(upstream upstream.cpp)
|
||||||
@@ -65,7 +69,11 @@ macro(do_try_compile error_option)
|
|||||||
LINK_LIBRARIES iface
|
LINK_LIBRARIES iface
|
||||||
)
|
)
|
||||||
if (${error_option} STREQUAL WITH_ERROR)
|
if (${error_option} STREQUAL WITH_ERROR)
|
||||||
list(APPEND TC_ARGS COMPILE_DEFINITIONS -Werror=unused-variable)
|
if (MSVC)
|
||||||
|
list(APPEND TC_ARGS COMPILE_DEFINITIONS /we4101)
|
||||||
|
else ()
|
||||||
|
list(APPEND TC_ARGS COMPILE_DEFINITIONS -Werror=unused-variable)
|
||||||
|
endif ()
|
||||||
endif()
|
endif()
|
||||||
try_compile(${TC_ARGS})
|
try_compile(${TC_ARGS})
|
||||||
endmacro()
|
endmacro()
|
||||||
|
@@ -7,14 +7,14 @@ set_target_properties(c_interface PROPERTIES
|
|||||||
INTERFACE_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_SOURCE_DIR}>"
|
INTERFACE_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_SOURCE_DIR}>"
|
||||||
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_SOURCE_DIR}>"
|
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_SOURCE_DIR}>"
|
||||||
)
|
)
|
||||||
target_compile_options(c_interface INTERFACE "$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=unused-variable>")
|
target_compile_options(c_interface INTERFACE "$<$<COMPILE_LANG_AND_ID:C,GNU,Clang>:-Werror=unused-variable>;$<$<COMPILE_LANG_AND_ID:C,MSVC>:/we4101>")
|
||||||
|
|
||||||
add_library(cxx_interface INTERFACE)
|
add_library(cxx_interface INTERFACE)
|
||||||
set_target_properties(cxx_interface PROPERTIES
|
set_target_properties(cxx_interface PROPERTIES
|
||||||
INTERFACE_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/cxx_system_include>"
|
INTERFACE_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/cxx_system_include>"
|
||||||
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/cxx_system_include>"
|
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "$<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/cxx_system_include>"
|
||||||
)
|
)
|
||||||
target_compile_options(cxx_interface INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang>:-Werror=unused-variable>")
|
target_compile_options(cxx_interface INTERFACE "$<$<COMPILE_LANG_AND_ID:CXX,GNU,Clang>:-Werror=unused-variable>;$<$<COMPILE_LANG_AND_ID:C,MSVC>:/we4101>")
|
||||||
|
|
||||||
# The C header must come before the C++ header for this test to smoke out the
|
# The C header must come before the C++ header for this test to smoke out the
|
||||||
# failure. The order of sources is how CMake determines the include cache
|
# failure. The order of sources is how CMake determines the include cache
|
||||||
|
Reference in New Issue
Block a user