Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp blt_convert_to_system_includes #671

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.code-workspace
*.swp
79 changes: 61 additions & 18 deletions cmake/BLTInstallableMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -428,37 +428,80 @@ endmacro(blt_add_target_compile_flags)


##------------------------------------------------------------------------------
## blt_convert_to_system_includes(TARGET <target>)
## blt_convert_to_system_includes(TARGETS [<target>...]
adayton1 marked this conversation as resolved.
Show resolved Hide resolved
## [QUIET]
## [INTRANSITIVE])
##
## Converts existing interface includes to system interface includes.
##------------------------------------------------------------------------------
macro(blt_convert_to_system_includes)
set(options)
function(blt_convert_to_system_includes)
set(options INTRANSITIVE QUIET)
adayton1 marked this conversation as resolved.
Show resolved Hide resolved
set(singleValuedArgs TARGET)
set(multiValuedArgs)
set(multiValuedArgs TARGETS)

## parse the arguments to the macro
cmake_parse_arguments(arg
"${options}" "${singleValuedArgs}" "${multiValuedArgs}" ${ARGN})
"${options}" "${singleValuedArgs}" "${multiValuedArgs}" ${ARGN})

if(DEFINED arg_TARGETS)
message(WARNING "TARGET is a deprecated parameter for the blt_convert_to_system_includes macro.")
list(APPEND arg_TARGETS ${arg_TARGET})
endif()

if(NOT DEFINED arg_TARGET)
message(FATAL_ERROR "TARGET is a required parameter for the blt_convert_to_system_includes macro.")
if(NOT DEFINED arg_TARGETS)
message(FATAL_ERROR "TARGETS is a required parameter for the blt_convert_to_system_includes macro.")
endif()

if(NOT ${arg_QUIET})
foreach(_target ${arg_TARGETS})
if(NOT TARGET ${_target})
message(WARNING "${_target} does not exist!")
endif()
endforeach()
endif()

# PGI does not support -isystem
if(NOT "${CMAKE_CXX_COMPILER_ID}" STREQUAL "PGI")
get_target_property(_include_dirs ${arg_TARGET} INTERFACE_INCLUDE_DIRECTORIES)
# Don't copy if the target had no include directories
if(_include_dirs)
# Clear previous value in INTERFACE_INCLUDE_DIRECTORIES so it is not doubled
# by target_include_directories
set_property(TARGET ${arg_TARGET} PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
target_include_directories(${arg_TARGET} SYSTEM INTERFACE ${_include_dirs})
endif()
endif()
foreach(_target ${arg_TARGETS})
adayton1 marked this conversation as resolved.
Show resolved Hide resolved
if(TARGET ${_target})
adayton1 marked this conversation as resolved.
Show resolved Hide resolved
if(NOT ${arg_INTRANSITIVE})
get_target_property(_interface_link_libs
${_target}
INTERFACE_LINK_LIBRARIES)

unset(_include_dirs)
endmacro()

# Don't recurse if the target had no interface link libraries
if(_interface_link_libs)
# TODO: Warn if interface link library is not a target?
blt_convert_to_system_includes(TARGETS ${_interface_link_libs})
endif()

unset(_interface_link_libs)
endif()

get_target_property(_interface_include_dirs
${_target}
INTERFACE_INCLUDE_DIRECTORIES)

# Don't update properties if the target had no interface include directories
if(_interface_include_dirs)
# Clear previous value in INTERFACE_INCLUDE_DIRECTORIES
# so it is not doubled by target_include_directories
set_target_properties(${_target}
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES)

target_include_directories(${_target}
SYSTEM
INTERFACE
${_interface_include_dirs})
endif()

unset(_interface_include_dirs)
endif()
endforeach()
endif()
endfunction(blt_convert_to_system_includes)


##------------------------------------------------------------------------------
Expand Down
9 changes: 6 additions & 3 deletions docs/api/utility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,17 @@ blt_convert_to_system_includes

.. code-block:: cmake

blt_convert_to_system_includes(TARGET <target>)
blt_convert_to_system_includes(TARGETS [<target>...]
[QUIET]
[INTRANSITIVE])

Converts existing interface includes to system interface includes.
Warns if a target does not exist unless ``QUIET`` is specified.
Recurses through interface link libraries unless ``INTRANSITIVE`` is specified.

.. code-block:: cmake
:caption: **Example**
:linenos:

## convert to system includes for the foo target
blt_convert_to_system_includes(TARGET foo)
blt_convert_to_system_includes(TARGETS foo)