Skip to content

Commit e4a8131

Browse files
authored
Merge pull request #56 from cpp-best-practices/include_directories_system
2 parents f375bfb + 369a80f commit e4a8131

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,14 @@ Named String:
120120

121121
## `target_link_system_libraries` function
122122

123-
A very useful function that accepts the same arguments as `target_link_libraries` while marking their include directories as "SYSTEM", which suppresses their warnings. This helps in enabling `WARNINGS_AS_ERRORS` for your own source code.
123+
A function that accepts the same arguments as `target_link_libraries`. It has the following features:
124+
125+
- The include directories of the library are included as `SYSTEM` to suppress their warnings. This helps in enabling `WARNINGS_AS_ERRORS` for your own source code.
126+
- For installation of the package, the includes are considered to be at `${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}`.
124127

125128
## `target_include_system_directories` function
126129

127-
Similar to `target_include_directories`, but it suppresses the warnings. It is useful if you want to include some external directories directly.
130+
A function that accepts the same arguments as `target_include_directories`. It has the above mentioned features of `target_link_system_libraries`
128131

129132
## `target_link_cuda` function
130133

src/SystemLink.cmake

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@ function(target_include_system_directories target)
1010

1111
foreach(scope IN ITEMS INTERFACE PUBLIC PRIVATE)
1212
foreach(lib_include_dirs IN LISTS ARG_${scope})
13-
if(MSVC)
13+
if(NOT MSVC)
1414
# system includes do not work in MSVC
1515
# awaiting https://gitlab.kitware.com/cmake/cmake/-/issues/18272#
1616
# awaiting https://gitlab.kitware.com/cmake/cmake/-/issues/17904
17-
target_include_directories(${target} ${scope} ${lib_include_dirs})
17+
set(_SYSTEM SYSTEM)
18+
endif()
19+
if(${scope} STREQUAL "INTERFACE" OR ${scope} STREQUAL "PUBLIC")
20+
target_include_directories(
21+
${target}
22+
${_SYSTEM}
23+
${scope}
24+
"$<BUILD_INTERFACE:${lib_include_dirs}>"
25+
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}>")
1826
else()
1927
target_include_directories(
2028
${target}
21-
SYSTEM
29+
${_SYSTEM}
2230
${scope}
2331
${lib_include_dirs})
2432
endif()
@@ -39,7 +47,7 @@ function(
3947
if(lib_include_dirs)
4048
target_include_system_directories(${target} ${scope} ${lib_include_dirs})
4149
else()
42-
message(STATUS "${lib} library does not have the INTERFACE_INCLUDE_DIRECTORIES property.")
50+
message(TRACE "${lib} library does not have the INTERFACE_INCLUDE_DIRECTORIES property.")
4351
endif()
4452
endif()
4553
endfunction()

0 commit comments

Comments
 (0)