CMakeLists.txt 1.57 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

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>
)

add_library(consumer consumer.cpp)
target_link_libraries(consumer upstream)
target_compile_options(consumer PRIVATE -Werror=unused-variable)
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47

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)

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()