<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<div class="moz-cite-prefix">Hi,<br>
I am aware that the intended usage of dune is via
dunecontrol/dunemodule, still i shortly want to share my current
approach/attempt with cmake and the provided
dune-**module**-config.cmake files.<br>
Maybe it is of use for anyone else. Hence ill just post part of my
project CMakeList.txt file. I used a very basic setup with only
dune-alugrid in sequential mode. all modules are 2.4 from git.<br>
<br>
First I get all the include and library information from the
**-config.cmake (they are stored in dune-***/build-cmake for each
of the modules) files from all the dune modules i depend on.<br>
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Source Code Pro';font-size:11.0pt;"><span style="color:#808080;">#========================================================
</span><span style="color:#808080;"># CHECK FOR DUNE, i.e. load the cmake-config files for each module
</span><span style="color:#808080;">#========================================================
</span><span style="color:#cc7832;font-weight:bold;">foreach</span>(<span style="color:#6a8759;">module common istl localfunctions geometry grid alugrid</span>)
message(<span style="color:#6a8759;">STATUS "Searching for dune-${module}"</span>)
set(<span style="color:#6a8759;">"dune-${module}_DIR" "${DUNE_ROOT}/dune-${module}/build-cmake"</span>)
find_package(<span style="color:#6a8759;">dune-${module} 2.4 REQUIRED</span>)
<span style="color:#cc7832;font-weight:bold;">if</span>(<span style="color:#6a8759;">${dune-${module}_FOUND}</span>)
include_directories(<span style="color:#6a8759;">${dune-${module}_INCLUDE_DIRS}</span>)
<span style="color:#cc7832;font-weight:bold;">endif</span>()
message(<span style="color:#6a8759;">STATUS "Found Dune:" ${dune-${module}_LIBRARIES}</span>)
message(<span style="color:#6a8759;">STATUS "Found Dune:" ${dune-${module}_INCLUDE_DIRS}</span>)
<span style="color:#cc7832;font-weight:bold;">endforeach</span>()</pre>
The nice thing here: the config files set up the dependencies of
the targets and export them. E.g. (from my
dune-grid/build-cmake/dune-grid-targets.cmake)<br>
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Source Code Pro';font-size:11.0pt;"><meta http-equiv="content-type" content="text/html; charset=windows-1252">add_library(<span style="color:#6a8759;">dunegrid STATIC IMPORTED</span>)
#...
set_target_properties(<span style="color:#6a8759;">dunegrid PROPERTIES
</span><span style="color:#6a8759;"> IMPORTED_LINK_INTERFACE_LANGUAGES_NOCONFIG "CXX"
</span><span style="color:#6a8759;"> IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG "dunegeometry;dunecommon" <<<< HERE dune-grid states that it is supposed to be linked together with dunegeometry and dunecommon
</span><span style="color:#6a8759;"> IMPORTED_LOCATION_NOCONFIG "/home/mrueckl/dune-2.4/dune-grid/build-cmake/lib/libdunegrid.a"
</span><span style="color:#6a8759;"> </span>)</pre>
Now if one links against one such exported targets, cmake
automatically determines the upstream's libraries dependencies.<br>
Hence compiling a target which depends e.g. on alugrid is easy as:<br>
<meta http-equiv="content-type" content="text/html;
charset=windows-1252">
<pre style="background-color:#2b2b2b;color:#a9b7c6;font-family:'Source Code Pro';font-size:11.0pt;"><span style="color:#cc7832;font-weight:bold;">if</span>(<span style="color:#6a8759;">${dune-alugrid_FOUND}</span>)
add_executable(<span style="color:#6a8759;">alu-gridgen alu-gridgen.cc</span>)
target_link_libraries(<span style="color:#6a8759;">alu-gridgen dunealugrid ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_IOSTREAMS_LIBRARY}</span>)
<span style="color:#cc7832;font-weight:bold;">endif</span>()</pre>
What remains is including a proper "config.h" file in the
executable to compile (here alu-gridgen.cc) for this i just used
the config.h from dune-alugrid.<br>
<br>
HtH Martin<br>
<br>
@cmake experts: I think the config.h include could be omitted if
the ***config.cmake files set appropriate defines. Something like
"moving the config.h.cmake into the ***config.cmake file". Any
ideas?<br>
<br>
@dune devs:<br>
For the above approach to work, i had to do two modifications on
my dune***targets.cmake files<br>
#1 i had to add "gfortran" to
IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG for dune-common.
otherwise i got undefined references from liblapack.so<br>
#2 i had to add "dunegrid" to INTERFACE_LINK_LIBRARIES for
dune-alugrid. otherwise cmake did not pull in the dependencies of
dune-alugrid's upstream modules.<br>
If this is a bug (which i think it is, since otherwise everything
worked really well) i can submit an issue to gitlab.<br>
</div>
</body>
</html>