2013-07-02 16:30:10 +04:00
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
|
|
|
|
project(SystemIncludeDirectories)
|
|
|
|
|
|
|
|
add_library(systemlib systemlib.cpp)
|
|
|
|
target_include_directories(systemlib PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/systemlib")
|
|
|
|
|
|
|
|
add_library(upstream upstream.cpp)
|
|
|
|
target_link_libraries(upstream LINK_PUBLIC systemlib)
|
|
|
|
target_compile_options(upstream PRIVATE -Werror=unused-variable)
|
|
|
|
|
|
|
|
target_include_directories(upstream SYSTEM PUBLIC
|
|
|
|
$<TARGET_PROPERTY:systemlib,INTERFACE_INCLUDE_DIRECTORIES>
|
|
|
|
)
|
|
|
|
|
2015-01-23 01:40:27 +03:00
|
|
|
add_library(config_specific INTERFACE)
|
2015-08-31 23:33:37 +03:00
|
|
|
if(CMAKE_GENERATOR STREQUAL "Xcode")
|
|
|
|
# CMAKE_BUILD_TYPE does not work here for multi-config generators
|
|
|
|
target_include_directories(config_specific SYSTEM INTERFACE
|
|
|
|
"${CMAKE_CURRENT_SOURCE_DIR}/config_specific"
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
set(testConfig ${CMAKE_BUILD_TYPE})
|
|
|
|
target_include_directories(config_specific SYSTEM INTERFACE
|
|
|
|
"$<$<CONFIG:${testConfig}>:${CMAKE_CURRENT_SOURCE_DIR}/config_specific>"
|
|
|
|
)
|
|
|
|
endif()
|
2015-01-23 01:40:27 +03:00
|
|
|
|
2013-07-02 16:30:10 +04:00
|
|
|
add_library(consumer consumer.cpp)
|
2015-01-23 01:40:27 +03:00
|
|
|
target_link_libraries(consumer upstream config_specific)
|
2013-07-02 16:30:10 +04:00
|
|
|
target_compile_options(consumer PRIVATE -Werror=unused-variable)
|
2013-09-18 19:30:55 +04:00
|
|
|
|
|
|
|
add_library(iface IMPORTED INTERFACE)
|
|
|
|
set_property(TARGET iface PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/systemlib_header_only")
|
|
|
|
|
|
|
|
add_library(imported_consumer imported_consumer.cpp)
|
|
|
|
target_link_libraries(imported_consumer iface)
|
|
|
|
target_compile_options(imported_consumer PRIVATE -Werror=unused-variable)
|
|
|
|
|
2014-01-01 18:49:05 +04:00
|
|
|
add_library(imported_consumer2 imported_consumer.cpp)
|
|
|
|
target_link_libraries(imported_consumer2 imported_consumer)
|
|
|
|
target_compile_options(imported_consumer2 PRIVATE -Werror=unused-variable)
|
|
|
|
|
2015-08-09 23:24:34 +03:00
|
|
|
# add a target which has a relative system include
|
|
|
|
add_library(somelib imported_consumer.cpp)
|
|
|
|
target_include_directories(somelib SYSTEM PUBLIC "systemlib_header_only")
|
|
|
|
target_compile_options(somelib PRIVATE -Werror=unused-variable)
|
|
|
|
|
|
|
|
# add a target which consumes a relative system include
|
|
|
|
add_library(otherlib upstream.cpp)
|
|
|
|
target_link_libraries(otherlib PUBLIC somelib)
|
|
|
|
target_compile_options(somelib PRIVATE -Werror=unused-variable)
|
|
|
|
|
2013-09-18 19:30:55 +04:00
|
|
|
macro(do_try_compile error_option)
|
|
|
|
set(TC_ARGS
|
|
|
|
IFACE_TRY_COMPILE_${error_option}
|
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/try_compile_iface" "${CMAKE_CURRENT_SOURCE_DIR}/imported_consumer.cpp"
|
|
|
|
LINK_LIBRARIES iface
|
|
|
|
)
|
|
|
|
if (${error_option} STREQUAL WITH_ERROR)
|
|
|
|
list(APPEND TC_ARGS COMPILE_DEFINITIONS -Werror=unused-variable)
|
|
|
|
endif()
|
|
|
|
try_compile(${TC_ARGS})
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
do_try_compile(NO_ERROR)
|
|
|
|
if (NOT IFACE_TRY_COMPILE_NO_ERROR)
|
|
|
|
message(SEND_ERROR "try_compile failed with imported target.")
|
|
|
|
endif()
|
|
|
|
do_try_compile(WITH_ERROR)
|
|
|
|
if (NOT IFACE_TRY_COMPILE_WITH_ERROR)
|
|
|
|
message(SEND_ERROR "try_compile failed with imported target with error option.")
|
|
|
|
endif()
|