Enable DUNE to append build directory to cmake prefix path
This allows super builds to be less verbose. Currently one hast to append the build directory of each sub-module to the CMAKE_PREFIX_PATH. That's annoying to do when there are many modules. With this MR that will be simplified to just enabling a flag.
Before
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
project(dune-super-build CXX)
# allow dune to see imported targets across modules
set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL ON)
# let 'find_package' know where modules can be found once configured
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR}/dune-common)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR}/dune-geometry)
list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR}/dune-grid)
# include DUNE modules as sub-directories
add_subdirectory(dune-common)
add_subdirectory(dune-geometry)
add_subdirectory(dune-grid)
# use targets from dune modules on cmake targets (e.g. from dune-grid)
add_executable(example example.cc)
target_link_libraries(example PRIVATE Dune::Grid)
After
cmake_minimum_required(VERSION 3.24 FATAL_ERROR)
project(dune-super-build CXX)
# allow dune to see imported targets across modules
set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL ON)
# let DUNE add module build dirs to CMAKE_PREFIX_PATH so that 'find_package' knows where to find modules
set(DUNE_PROJECT_BINARY_DIR_IN_PREFIX_PATH ON)
# include DUNE modules as sub-directories
add_subdirectory(dune-common)
add_subdirectory(dune-geometry)
add_subdirectory(dune-grid)
# use targets from dune modules on cmake targets (e.g. from dune-grid)
add_executable(example example.cc)
target_link_libraries(example PRIVATE Dune::Grid)
Discussion
We need to understand what happens when a module is already installed on the system. Is appending to the CMAKE_PREFIX_PATH the best option that will always take precedence, or are there any other trade offs to consider on this?
Edited by Santiago Ospina De Los Ríos