1 cmake_minimum_required (VERSION 2.6)
4 cmake_policy(SET CMP0129 NEW)
7 project(IncludeDirectories)
8 if (((CMAKE_C_COMPILER_ID STREQUAL GNU AND CMAKE_C_COMPILER_VERSION VERSION_GREATER 4.4)
9 OR (CMAKE_C_COMPILER_ID STREQUAL Clang AND NOT "x${CMAKE_CXX_SIMULATE_ID}" STREQUAL "xMSVC")
10 OR CMAKE_C_COMPILER_ID STREQUAL NVHPC
11 OR CMAKE_C_COMPILER_ID STREQUAL AppleClang
12 OR CMAKE_C_COMPILER_ID STREQUAL LCC
13 OR ("x${CMAKE_C_COMPILER_ID}" STREQUAL "xMSVC" AND
14 CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL "19.29.30036.3"))
15 AND (CMAKE_GENERATOR STREQUAL "Unix Makefiles"
16 OR CMAKE_GENERATOR STREQUAL "Ninja"
17 OR (CMAKE_GENERATOR STREQUAL "Xcode" AND NOT XCODE_VERSION VERSION_LESS 6.0)
18 OR CMAKE_GENERATOR MATCHES "Visual Studio"))
19 if ("x${CMAKE_C_COMPILER_ID}" STREQUAL "xMSVC")
20 set(run_sys_includes_test 1)
22 include(CheckCXXCompilerFlag)
23 check_cxx_compiler_flag(-Wunused-variable run_sys_includes_test)
24 if(run_sys_includes_test)
25 # The Bullseye wrapper appears to break the -isystem effect.
26 execute_process(COMMAND ${CMAKE_CXX_COMPILER} --version OUTPUT_VARIABLE out ERROR_VARIABLE out)
27 if("x${out}" MATCHES "Bullseye")
28 set(run_sys_includes_test 0)
32 if (run_sys_includes_test)
33 add_subdirectory(SystemIncludeDirectories)
34 add_subdirectory(SystemIncludeDirectoriesPerLang)
38 file(WRITE ${CMAKE_BINARY_DIR}/Flags/Flags.h
41 file(WRITE ${CMAKE_BINARY_DIR}/IncDir/IncDir.h
44 file(WRITE ${CMAKE_BINARY_DIR}/SrcProp/SrcProp.h
47 file(WRITE ${CMAKE_BINARY_DIR}/TarProp/TarProp.h
51 # default to testing with full path
52 # some compilers can not handle the escape for directories
53 # with spaces in them.
54 set(USE_FULLPATH TRUE)
56 set(USE_FULLPATH FALSE)
59 string(APPEND CMAKE_CXX_FLAGS " \"-I${CMAKE_BINARY_DIR}/Flags\"")
61 string(APPEND CMAKE_CXX_FLAGS " -IFlags")
64 include_directories(${CMAKE_BINARY_DIR}/IncDir)
66 set_source_files_properties(main.cpp PROPERTIES COMPILE_FLAGS
67 "\"-I${CMAKE_BINARY_DIR}/SrcProp\"")
69 set_source_files_properties(main.cpp PROPERTIES COMPILE_FLAGS
73 add_executable(IncludeDirectories main.cpp)
76 set_target_properties(IncludeDirectories
77 PROPERTIES COMPILE_FLAGS "\"-I${CMAKE_BINARY_DIR}/TarProp\"")
79 set_target_properties(IncludeDirectories
80 PROPERTIES COMPILE_FLAGS "-ITarProp")
83 # Test escaping of special characters in include directory paths.
84 set(special_chars "~@&{}()!'")
85 if(NOT CMAKE_GENERATOR MATCHES "(Unix|MinGW|MSYS) Makefiles")
86 # when compiler is used for dependencies, special characters for make are not escaped
87 string(APPEND special_chars "%")
89 if(NOT CMAKE_GENERATOR STREQUAL "Watcom WMake")
90 # Watcom seems to have no way to encode these characters.
91 string(APPEND special_chars "#=[]")
93 if(NOT (MINGW AND CMAKE_GENERATOR MATCHES "(Unix|MSYS) Makefiles"))
94 # FIXME: Dependencies work but command-line generation does not handle '$'.
95 string(APPEND special_chars "$")
97 if(NOT CMAKE_GENERATOR MATCHES "(Borland|NMake) Makefiles")
98 # NMake and Borland seem to have no way to encode a single '^'.
99 string(APPEND special_chars "^")
101 if(NOT CMAKE_GENERATOR MATCHES "Visual Studio 9 2008|Watcom WMake")
102 # The vcproj format separates values with ','.
103 string(APPEND special_chars ",")
105 if(NOT WIN32 AND NOT CYGWIN)
106 string(APPEND special_chars "*?<>")
108 set(special_dir "${CMAKE_CURRENT_BINARY_DIR}/special-${special_chars}-include")
109 file(WRITE "${special_dir}/SpecialDir.h" "#define SPECIAL_DIR_H\n")
110 target_include_directories(IncludeDirectories PRIVATE "${special_dir}")
111 target_compile_definitions(IncludeDirectories PRIVATE INCLUDE_SPECIAL_DIR)
113 if(MAKE_SUPPORTS_SPACES)
114 set(special_space_dir "${CMAKE_CURRENT_BINARY_DIR}/special-space ${special_chars}-include")
115 file(WRITE "${special_space_dir}/SpecialSpaceDir.h" "#define SPECIAL_SPACE_DIR_H\n")
116 target_include_directories(IncludeDirectories PRIVATE "${special_space_dir}")
117 target_compile_definitions(IncludeDirectories PRIVATE INCLUDE_SPECIAL_SPACE_DIR)
120 add_library(ordertest ordertest.cpp)
121 target_include_directories(ordertest SYSTEM PUBLIC SystemIncludeDirectories/systemlib)
122 target_include_directories(ordertest PUBLIC SystemIncludeDirectories/userlib)
124 add_library(ordertest2 ordertest.cpp)
125 target_include_directories(ordertest2 SYSTEM PRIVATE SystemIncludeDirectories/systemlib)
126 target_link_libraries(ordertest2 PRIVATE ordertest2_userlib)
127 add_library(ordertest2_userlib INTERFACE IMPORTED)
128 target_include_directories(ordertest2_userlib INTERFACE SystemIncludeDirectories/userlib)
129 set_property(TARGET ordertest2_userlib PROPERTY IMPORTED_NO_SYSTEM 1)
131 add_subdirectory(StandardIncludeDirectories)
132 add_subdirectory(TargetIncludeDirectories)
134 set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR}")
135 get_property(propContent DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
136 if (NOT propContent STREQUAL "${CMAKE_BINARY_DIR}")
137 message(SEND_ERROR "Setting DIRECTORY property failed.")
139 set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
140 get_property(propContentAfter DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
141 if (NOT propContentAfter STREQUAL "")
142 message(SEND_ERROR "Clearing DIRECTORY property failed.")
145 add_library(empty_entry_test SHARED empty.cpp)
146 set_target_properties(empty_entry_test PROPERTIES INCLUDE_DIRECTORIES "")
147 include_directories(/one/two
151 get_target_property(incs empty_entry_test INCLUDE_DIRECTORIES)
152 if (NOT incs STREQUAL ";/one/two")
153 message(SEND_ERROR "Empty include_directories entry was not ignored.")
156 if(NOT CMAKE_GENERATOR STREQUAL "Xcode" AND NOT CMAKE_GENERATOR MATCHES "Ninja")
157 add_subdirectory(CMP0021)