Skip to content

Commit

Permalink
Headers from dependencies are no longer marked as system, except from…
Browse files Browse the repository at this point in the history
… overlayed workspaces
  • Loading branch information
poggenhans authored and keroe committed May 7, 2021
1 parent 7e2cfc8 commit a8f3a7a
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmake/mrt_cmake_modules-macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ if(DEFINED MRT_CLANG_TIDY_FLAGS)
endif()
unset(MRT_CLANG_TIDY_FLAGS)

# Disable that all dependant packages are treated as "system" packages (suppressing all warnings from there).
# We later add the "system" explicitly to all include dirs of parent workspaces.
set(CMAKE_NO_SYSTEM_FROM_IMPORTED YES)

# construct the mrt_sanitizer_lib_flags and mrt_sanitizer_exe_flags target based on the configuation in the MRT_SANITIZER variable
if(NOT TARGET ${PROJECT_NAME}_sanitizer_lib_flags AND NOT TARGET ${PROJECT_NAME}_sanitizer_exe_flags)
add_library(${PROJECT_NAME}_sanitizer_lib_flags INTERFACE)
Expand Down Expand Up @@ -107,6 +111,32 @@ set(${PROJECT_NAME}_PYTHON_API_TARGET "") # contains the list of python api targ
set(${PROJECT_NAME}_GENERATED_LIBRARIES "") # the list of library targets built and installed by the tools
set(${PROJECT_NAME}_MRT_TARGETS "") # list of all public installable targets created by the functions here

# this function determines all includes directories that belong to parent workspaces (including the ros installation).
# we later mark all of these directories as system directories so that warnings from these headers are hidden.
# It is important to maintain the order of CMAKE_INSTALL_PREFIX so that the include order matches the order in which workspaces are overlayed.
function(_get_parent_workspace_include_dirs outdir)
# Assuming the parent directory of the install dir is the workspace.
# Not the best assumption but it works (in the worst case we mark too much headers as "system")
get_filename_component(current_workspace ${CMAKE_INSTALL_PREFIX} DIRECTORY)

set(workspace_include_dirs)
foreach(workspace ${CMAKE_PREFIX_PATH})
string(FIND ${workspace} ${current_workspace} _is_current_workspace)
if(NOT ${_is_current_workspace} EQUAL -1)
continue()
endif()
foreach(_include_dir ${mrt_EXPORT_INCLUDE_DIRS})
string(FIND ${_include_dir} ${workspace} _pos)
if(NOT ${_pos} EQUAL -1)
list(APPEND workspace_include_dirs ${_include_dir})
endif()
endforeach()
endforeach()
set(${outdir}
${workspace_include_dirs}
PARENT_SCOPE)
endfunction()

# define rosparam/rosinterface_handler macro for compability. Macros will be overriden by the actual macros defined by the packages, if existing.
macro(generate_ros_parameter_files)
# handle pure dynamic reconfigure files
Expand Down Expand Up @@ -277,6 +307,11 @@ function(mrt_add_links target)
target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${include}>)
endif()
endforeach()
# mark all include include dirs from parent workspaces as "system" (silence warnings from these)
_get_parent_workspace_include_dirs(workspace_include_dirs)
if(workspace_include_dirs)
target_include_directories(${target} SYSTEM AFTER PRIVATE ${workspace_include_dirs})
endif()
else()
# set the include dir for installation and dependent targets.
foreach(include ${${PROJECT_NAME}_LOCAL_INCLUDE_DIRS})
Expand Down

0 comments on commit a8f3a7a

Please sign in to comment.