summaryrefslogtreecommitdiffstats
path: root/Tests/CMakeCommands/target_include_directories/CMakeLists.txt
blob: d5d4970ca17c34ae1e3a42c5838c6f04385548ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
cmake_minimum_required(VERSION 3.5)

project(target_include_directories)

file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/privateinclude")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/privateinclude/privateinclude.h" "#define PRIVATEINCLUDE_DEFINE\n")

file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/publicinclude")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/publicinclude/publicinclude.h" "#define PUBLICINCLUDE_DEFINE\n")

file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/interfaceinclude")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/interfaceinclude/interfaceinclude.h" "#define INTERFACEINCLUDE_DEFINE\n")

file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/poison")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/poison/common.h" "#error Should not be included\n")

file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/cure")
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/cure/common.h" "#define CURE_DEFINE\n")

add_executable(target_include_directories
  "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp"
)
target_include_directories(target_include_directories
  PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/privateinclude"
  PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/publicinclude"
  INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/interfaceinclude"
)

target_include_directories(target_include_directories
  PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/poison"
)
target_include_directories(target_include_directories
  BEFORE PUBLIC "$<$<STREQUAL:$<TARGET_PROPERTY:target_include_directories,TYPE>,EXECUTABLE>:${CMAKE_CURRENT_BINARY_DIR}/cure>"
)

# Has no effect because the target type is not SHARED_LIBRARY:
target_include_directories(target_include_directories
  BEFORE PUBLIC "$<$<STREQUAL:$<TARGET_PROPERTY:target_include_directories,TYPE>,SHARED_LIBRARY>:${CMAKE_CURRENT_BINARY_DIR}/poison>"
)

add_executable(consumer
  "${CMAKE_CURRENT_SOURCE_DIR}/consumer.cpp"
)

target_sources(consumer PRIVATE
  "${CMAKE_CURRENT_SOURCE_DIR}/consumer.c"
)
target_include_directories(consumer
  PRIVATE
    $<$<COMPILE_LANGUAGE:CXX>:${CMAKE_CURRENT_SOURCE_DIR}/cxx_only>
    $<$<COMPILE_LANGUAGE:C>:${CMAKE_CURRENT_SOURCE_DIR}/c_only>
)
if(CMAKE_GENERATOR MATCHES "Visual Studio|Xcode")
  target_compile_definitions(consumer
    PRIVATE TEST_LANG_DEFINES_FOR_VISUAL_STUDIO_OR_XCODE
  )
endif()

target_include_directories(consumer
  PRIVATE
    $<TARGET_PROPERTY:target_include_directories,INTERFACE_INCLUDE_DIRECTORIES>
    relative_dir
    relative_dir/$<TARGET_PROPERTY:NAME>
)

# Test no items
target_include_directories(consumer
  PRIVATE
)
target_include_directories(consumer
  BEFORE PRIVATE
)
target_include_directories(consumer
  SYSTEM BEFORE PRIVATE
)
target_include_directories(consumer
  SYSTEM PRIVATE
)

include_directories(${CMAKE_CURRENT_BINARY_DIR})
add_library(imp UNKNOWN IMPORTED)
get_target_property(_res imp INCLUDE_DIRECTORIES)
if (_res)
  message(SEND_ERROR "include_directories populated the INCLUDE_DIRECTORIES target property")
endif()

# Test selecting lexicographically-later header of same name via include order.
# Xcode 'USE_HEADERMAP = YES' breaks this.
add_library(same STATIC same.c same_one/same.h same_two/same.h)
target_include_directories(same PRIVATE same_two)