Skip to content

[cmake] Require linked libs through find_dependency

Timo Koch requested to merge feature/find-dependency into master

Description

If found, dunecommon will be linked against TBB, Threads, and LAPACK or BLAS. This means that downstream modules need to conditionally find these libs as well to be able to link against Dune::Common. This MR ensures that a call to find_packge(dune-common) in a downstream module will propagate these dependencies via a find_dependency call inside the generated dune-common-config.cmake file.

It is important to note that:

  • This MR is a custom solution for dune-common because the other core modules do not link their main targets against other libraries.
  • This MR is completely backwards compatible because it does not change how dependencies on the macros work.
  • This MR does not replace the Dune<Module>Macros.cmake. If any of TBB, Threads, LAPACK or BLAS is not found, the dependency is not propagated.

Consequence

After this is merged, it will be possible to finally link against Dune::Common without help of the dune build system (keep in mind that this is the primary goal of the CMake modernization in dune). This means that a cmake file like the following one will work out of the box:

cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
project(dune-common-standalone CXX)

# find a build or installed directory with dune-common
find_package(dune-common REQUIRED)

# compile a simple executable with some dune-common utilities (e.g. FieldVector, MPIHelper, ParameterTree, etc.)
add_executable(dune-common-standalone dune-common-standalone.cc)

# linking against Dune::Common is enough to use dune-common (i.e. no need of 'dune_projec' or any other dune build system stuff)
target_link_libraries(dune-common-standalone PRIVATE Dune::Common)

This MR comes with a test that checks that this works meaning that the CI will break if the code above breaks for some reason.

Ok, but how about other modules?

Similar changes to this one may be needed on those modules that link their main targets against external dependencies (e.g. dune-uggrid with MPI). However, all of the other core modules do not link against other external libraries. This means that stand alone CMake will also work out of the box for them once their targets and the targets on all their upstream modules are correctly setup (e.g. with !1355 (merged)).


  • Add Changelog
  • Squash commits
Edited by Santiago Ospina De Los Ríos

Merge request reports

Loading