Skip to content

Provide a cmake utility dune_default_include_directories

Summary

This MR adds a cmake macro dune_default_include_directories that allows to set target include-directories that are common to dune modules directly. It is a helper macro to simplify configuration of module targets. Additionally, this MR removes the need for global include_directory commands in dune_project that can be controlled by a policy flag.

Usage

In your main CMakeLists.txt you can add default include-directories on a given target, e.g.

# Create a target
dune_add_library(dunecommon EXPORT_NAME Common NAMESPACE Dune::)
# set include directories
dune_default_include_directories(dunecommon PUBLIC)

The scope PUBLIC can also be replaced by PRIVATE or INTERFACE.

If the target is a module library, one can omit the global include_directory command and instead rely on the target propagation of include-dir properties. To deactivate the global includes, you can set the dune policy DP_DEFAULT_INCLUDE_DIRS to "NEW":

# after the include of DuneMacros and before calling dune_project()
dune_policy(SET DP_DEFAULT_INCLUDE_DIRS NEW)

This will deactivate the displayed warning about unset policies and will remove the <module>_INCLUDE_DIRS variable from the <module>_config.cmake file.

If you don't want to set the include directories explicitly and prefer the old behavior, you can also set

dune_policy(SET DP_DEFAULT_INCLUDE_DIRS OLD)

to silence the warning.

Discussion

  • If the include-dirs are moved to the target, it can be removed from the global environment. Additionally, the variable <module>_INCLUDE_DIRS is removed from the <module>-config.cmake file. The is a trick to not set this automatically after find_package(<module>) is called. IMHO, the find_package should not change the environment automatically.
  • The NEW behavior is not enforced. Only when we release dune 2.12 it will be the default behavior.
  • Having include-directories on imported targets make these automatically to "SYSTEM" includes. This means that warnings in code from these libraries are not shown anymore. We have to find a way to change this. In cmake >= 3.25 we can add EXPORT_NO_SYSTEM, see https://cmake.org/cmake/help/latest/prop_tgt/EXPORT_NO_SYSTEM.html (solution: use NO_SYSTEM_FROM_IMPORTED on dune libraries)

Close #332 (closed)

Edited by Simon Praetorius

Merge request reports

Loading