Generated default CMakeLists.txt
- In the
CMakeLists.txt
file generated byduneproject
there are some lines that are hard to understand and not documented:
if(NOT (dune-common_DIR OR dune-common_ROOT OR
"${CMAKE_PREFIX_PATH}" MATCHES ".*dune-common.*"))
string(REPLACE ${CMAKE_PROJECT_NAME} dune-common dune-common_DIR
${PROJECT_BINARY_DIR})
endif()
The meaning is as follows:
- If there is no variable
dune-common_DIR
(ordune-common_ROOT
) is set, and theCMAKE_PREFIX_PATH
list does not contain any directory containing the stringdune-common
- Then guess the build-dir of dune-common by replacing the module name in the module build-dir by the string "dune-common".
- This constructed build-dir is used as directory to find the dune-common package.
This sounds like a wild construction to me and I always wondered why this is actually necessary.
- If we are using
dunecontrol
then thedune-common_DIR
is explicitly passed to all built modules. - If we are not using
dunecontrol
we should pass the directories where to find the modules explicitly instead of wild guessing. (in my opinion)
- The second strange part of the generate
CMakeLists.txt
file is:
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules"
${dune-common_MODULE_PATH})
Here we add the cmake directory of the current dune module and the corresponding directory of dune-common to the search path CMAKE_MODULE_PATH
variable.
- The module path of
dune-common
should be added automatically inside thefind_package
toCMAKE_MODULE_PATH
, because this is what the package exports. - The module specific cmake directory is currently necessary, since automatically the cmake file
Dune<Module>.cmake
is included recursively by all dune modules. I'm hoping to remove this automatic inclusion in the future in favor of an extended find-package description.