[Dune] dune & cmake

Martin Rückl mrueckl at physik.hu-berlin.de
Mon Apr 11 18:08:47 CEST 2016


Hi,
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.
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.

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.

#========================================================
# CHECK FOR DUNE, i.e. load the cmake-config files for each module
#========================================================
foreach(module common istl localfunctions geometry grid alugrid)
     message(STATUS "Searching for dune-${module}")
     set("dune-${module}_DIR" "${DUNE_ROOT}/dune-${module}/build-cmake")
     find_package(dune-${module} 2.4 REQUIRED)
     if(${dune-${module}_FOUND})
         include_directories(${dune-${module}_INCLUDE_DIRS})
     endif()
     message(STATUS "Found Dune:" ${dune-${module}_LIBRARIES})
     message(STATUS "Found Dune:" ${dune-${module}_INCLUDE_DIRS})
endforeach()

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)

add_library(dunegrid STATIC IMPORTED)
#...
set_target_properties(dunegrid PROPERTIES
   IMPORTED_LINK_INTERFACE_LANGUAGES_NOCONFIG "CXX"
   IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG "dunegeometry;dunecommon" <<<< HERE dune-grid states that it is supposed to be linked  together with dunegeometry and dunecommon
   IMPORTED_LOCATION_NOCONFIG "/home/mrueckl/dune-2.4/dune-grid/build-cmake/lib/libdunegrid.a"
   )

Now if one links against one such exported targets, cmake automatically 
determines the upstream's libraries dependencies.
Hence compiling a target which depends e.g. on alugrid is easy as:

if(${dune-alugrid_FOUND})
     add_executable(alu-gridgen alu-gridgen.cc)
     target_link_libraries(alu-gridgen dunealugrid ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_IOSTREAMS_LIBRARY})
endif()

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.

HtH Martin

@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?

@dune devs:
For the above approach to work, i had to do two modifications on my 
dune***targets.cmake files
#1 i had to add "gfortran" to IMPORTED_LINK_INTERFACE_LIBRARIES_NOCONFIG 
for dune-common. otherwise i got undefined references from liblapack.so
#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.
If this is a bug (which i think it is, since otherwise everything worked 
really well) i can submit an issue to gitlab.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20160411/bbbafea7/attachment.htm>


More information about the Dune mailing list