Commit ba657c66 authored by Lukas Riedel's avatar Lukas Riedel

Update CMake build configuration

* Define a custom target for HDF5.
  - Link to dependent libraries.
  - Add CPP definition for parallel setup explicitly.
  - Remove runtime check for parallel HDF5 in 'dorie-rfg'.
* Set CMP0074 to NEW to allow usage of <Package>_ROOT variables.
* Link all dependencies to executables when calling DorieTesting
  CMake macros.
* Do not check for FFTW3.
  - Check is performed by dune-randomfield already, which also
    registers the lib to DUNE_LIBS.
  - Remove FindFFTW3.cmake.
* Raise minimum required CMake version to Ubuntu Bionic, v3.10.
* Use lowercase name `muparser` consistently.
* Update installation instructions for building HDF5 from source
  (MPI support dropped by Homebrew)
* Use `dune_target_link_libraries` for DUNE_LIBS only.
parent 813ec064
cmake_minimum_required(VERSION 2.8.12)
project(dorie CXX)
cmake_minimum_required(VERSION 3.10)
project(dorie C CXX)
# set build type
if(NOT CMAKE_BUILD_TYPE)
......
......@@ -103,6 +103,9 @@ by CI tests.
#### Step-by-step Instructions
These instructions are suitable for a clean **Ubuntu** or **macOS** setup. The main difference between the two systems is the package manager. Debian-based systems have the APT manager already built in. On Mac, we recommend installing [Homebrew](http://brew.sh/). If you prefer to use [MacPorts](https://www.macports.org/), you need to check if some of the packages require different installation options than displayed here.
Manual installations on macOS require installing HDF5 from source. This can
be tricky, but the following instructions should work on a clean system.
If you installed [Anaconda](https://conda.io/docs/user-guide/install/download.html) on your machine, you don't need to install Python or Pip. Simply skip these packages when using the package managers for installing the software. However, notice the warnings when compiling DORiE below!
1. **macOS** users need to start by installing the Apple Command Line Tools by executing
......@@ -125,10 +128,33 @@ If you installed [Anaconda](https://conda.io/docs/user-guide/install/download.ht
**macOS:**
brew update
brew install cmake doxygen gcc libpng open-mpi muparser \
brew install cmake doxygen fftw gcc libpng open-mpi muparser \
pkg-config python3 superlu yaml-cpp
brew install hdf5 --with-mpi
brew install fftw --with-mpi
2. **macOS only:** Install HDF5 with MPI support from source.
1. Download an archive of the
[HDF5 source code](https://www.hdfgroup.org/downloads/hdf5/source-code/),
and extract it.
2. Enter the extracted folder. In there, create a `build` directory, and
enter it:
mkdir build && cd build
3. Configure your build. If you followed the instructions above, the
OpenMPI C compiler is reachable via the command `mpicc`. If not, you have
to specify a full path to it. Use the option `prefix` to specify where
you want the package to be installed. This should *not* be a
system-reserved path like `/usr/local`, and *not* be located in a
sub-directory of the source code. Execute the configuration script:
./../configure CC=mpicc --prefix=<hdf5-path> --enable-parallel
4. Build and install the library:
make && make install
3. The parallel linear solver of DORiE can make use of the ParMETIS package. If you want to run DORiE in parallel on multiple processes, additionally install METIS and ParMETIS:
......@@ -158,11 +184,18 @@ If you installed [Anaconda](https://conda.io/docs/user-guide/install/download.ht
If you installed software into paths not appended to your `PATH` variable, you will have to add `CMAKE_FLAGS` to the call to make sure that CMake finds all packages. Alternatively, you can add a custom options file. See the [DUNE Installation Instructions](https://dune-project.org/doc/installation/) for details. CMake will throw an error if required packages are not found.
**Warning:** Anacoda supplies its own version of HDF5 which is typically found first by CMake. If you have Anaconda installed on your machine, add
If you installed HDF5 from source (all macOS users) or use Anaconda,
specify the path to your HDF5 installation by using the `HDF5_ROOT`
variable. On Ubuntu, add the path to the APT package,
-DHDF5_ROOT=/usr/
and on macOS, add
HDF5_ROOT=/usr/local
-DHDF5_ROOT=<hdf5-path>
to the `CMAKE_FLAGS` in the call to `dunecontrol` above.
to the `CMAKE_FLAGS` in the above command, replacing `<hdf5-path>` with the
path chosen as installation prefix when configuring HDF5.
#### Experimental Features
The local operator implementing Richards equation's discretization supports
......
# find all required packages
FIND_PACKAGE (HDF5 REQUIRED)
# These macros check for the following packages, yielding the respective
# targets
#
# HDF5 ... hdf5
# yaml-cpp ... yaml-cpp
# muparser ... muparser::muparser
#
# All of these are required an will be autmatically linked to executables when
# using the DorieTesting CMake macros.
# Add CMake policy stack
cmake_policy(PUSH)
# Allow using `<Package>_ROOT` on CMake >3.12
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
# HDF5
set(HDF5_PREFER_PARALLEL TRUE)
find_package (HDF5 REQUIRED COMPONENTS C)
if(NOT HDF5_IS_PARALLEL)
message(SEND_ERROR "Parallel HDF5 must be installed!")
endif()
add_definitions(-DHDF5_PARALLEL)
FIND_PACKAGE (FFTW REQUIRED)
FIND_PACKAGE (SuperLU REQUIRED)
FIND_PACKAGE (MPI REQUIRED)
# Define a target because the CMake module does not
add_library(hdf5 INTERFACE IMPORTED GLOBAL)
# TODO: Use `target_XXX` functions after raising CMake requirements
# Sanitize the definitions because we cannot use the proper CMake function...
string(REPLACE -D "" HDF5_DEFINITIONS "${HDF5_DEFINITIONS}")
# Set properties directly because of a bug in CMake 3.10
set_target_properties(hdf5 PROPERTIES
INTERFACE_LINK_LIBRARIES "${HDF5_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${HDF5_INCLUDE_DIRS}"
INTERFACE_COMPILE_DEFINITIONS "${HDF5_DEFINITIONS};H5_HAVE_PARALLEL")
# yaml-cpp
find_package (yaml-cpp 0.5.2 REQUIRED)
FIND_PACKAGE (muparser REQUIRED)
FIND_PACKAGE (METIS)
FIND_PACKAGE (ParMETIS)
# muparser
find_package (muparser REQUIRED)
include_directories(${FFTW_INCLUDES}
${HDF5_INCLUDE_DIRS}
${YAML_CPP_INCLUDE_DIR})
# Report the DUNE libs
message (STATUS "DUNE Libraries: ${DUNE_LIBS}")
list (APPEND DUNE_LIBS
${FFTW_LIBRARIES}
${HDF5_LIBRARIES}
${YAML_CPP_LIBRARIES}
muparser::muparser)
MESSAGE(STATUS "DUNE Libraries: ${DUNE_LIBS}")
# Remove CMake policy stack
cmake_policy(POP)
# Add DORiE testing functions
include(DorieTesting)
......@@ -53,6 +53,9 @@ endfunction()
# tests within DORiE and adds flags for coverage reports. Notice that
# `dune_add_test` requires more parameters than this function alone.
#
# The registered executable is automatically linked to the libraries DORiE
# DORiE depends on.
#
# Use this function exactly like `dune_add_test`.
#
function(dorie_add_unit_test)
......@@ -75,6 +78,8 @@ function(dorie_add_unit_test)
endif()
# add to build target and employ compile options
target_link_libraries(${UNIT_TEST_TARGET}
muparser::muparser hdf5 yaml-cpp spdlog)
add_coverage_links(${UNIT_TEST_TARGET})
add_dependencies(build_unit_tests ${UNIT_TEST_TARGET})
endfunction()
......@@ -129,6 +134,9 @@ endfunction()
# Use this function like `dune_add_system_test`, considering the options
# given above.
#
# When registering a new executable (`TARGET` is not specified), this
# executable will be linked to the libraries DORiE depends on.
#
function(dorie_add_metaini_test)
set(OPTIONS UNIT_TEST)
set(SINGLE TARGET METAINI SCRIPT BASENAME CREATED_TARGETS)
......@@ -177,9 +185,16 @@ function(dorie_add_metaini_test)
SCRIPT ${SYSTEM_TEST_SCRIPT}
CREATED_TARGETS created_targets
)
# report created targets to parent scope
set(${SYSTEM_TEST_CREATED_TARGETS} ${created_targets} PARENT_SCOPE)
# Link to dependencies
if(NOT SYSTEM_TEST_TARGET)
target_link_libraries(${created_targets}
muparser::muparser hdf5 yaml-cpp spdlog)
endif()
# add dependencies and flags
if(SYSTEM_TEST_UNIT_TEST)
add_coverage_links(${created_targets})
......
# - Find the FFTW library
#
# Usage:
# find_package(FFTW [REQUIRED] [QUIET] )
#
# It sets the following variables:
# FFTW_FOUND ... true if fftw is found on the system
# FFTW_LIBRARIES ... full path to fftw library
# FFTW_INCLUDES ... fftw include directory
#
# The following variables will be checked by the function
# FFTW_USE_STATIC_LIBS ... if true, only static libraries are found
# FFTW_ROOT ... if set, the libraries are exclusively searched
# under this path
# FFTW_LIBRARY ... fftw library to use
# FFTW_INCLUDE_DIR ... fftw include directory
#
#If environment variable FFTWDIR is specified, it has same effect as FFTW_ROOT
if( NOT FFTW_ROOT AND ENV{FFTWDIR} )
set( FFTW_ROOT $ENV{FFTWDIR} )
endif()
# Check if we can use PkgConfig
find_package(PkgConfig)
#Determine from PKG
if( PKG_CONFIG_FOUND AND NOT FFTW_ROOT )
pkg_check_modules( PKG_FFTW QUIET "fftw3" )
endif()
#Check whether to search static or dynamic libs
set( CMAKE_FIND_LIBRARY_SUFFIXES_SAV ${CMAKE_FIND_LIBRARY_SUFFIXES} )
if( FFTW_ROOT )
#find libs
find_library(
FFTW_LIB
NAMES "fftw3"
PATHS ${FFTW_ROOT}
PATH_SUFFIXES "lib" "lib64"
NO_DEFAULT_PATH
)
find_library(
FFTWF_LIB
NAMES "fftw3_mpi"
PATHS ${FFTW_ROOT}
PATH_SUFFIXES "lib" "lib64"
NO_DEFAULT_PATH
)
find_library(
FFTWL_LIB
NAMES "fftw3l"
PATHS ${FFTW_ROOT}
PATH_SUFFIXES "lib" "lib64"
NO_DEFAULT_PATH
)
#find includes
find_path(
FFTW_INCLUDES
NAMES "fftw3.h"
PATHS ${FFTW_ROOT}
PATH_SUFFIXES "include"
NO_DEFAULT_PATH
)
else()
find_library(
FFTW_LIB
NAMES "fftw3"
PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
)
find_library(
FFTWF_LIB
NAMES "fftw3_mpi"
PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
)
find_library(
FFTWL_LIB
NAMES "fftw3l"
PATHS ${PKG_FFTW_LIBRARY_DIRS} ${LIB_INSTALL_DIR}
)
find_path(
FFTW_INCLUDES
NAMES "fftw3.h"
PATHS ${PKG_FFTW_INCLUDE_DIRS} ${INCLUDE_INSTALL_DIR}
)
endif( FFTW_ROOT )
set(FFTW_LIBRARIES ${FFTWF_LIB} ${FFTW_LIB})
if(FFTWL_LIB)
set(FFTW_LIBRARIES ${FFTWL_LIB} ${FFTW_LIBRARIES})
endif()
set( CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SAV} )
MESSAGE(STATUS "Found FFTW library: ${FFTW_LIBRARIES}")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FFTW DEFAULT_MSG
FFTW_INCLUDES FFTW_LIBRARIES)
mark_as_advanced(FFTW_INCLUDES FFTW_LIBRARIES)
# - Find the muParser library
# Find the muparser library
#
# Usage:
# find_package(muParser [REQUIRED] [QUIET] )
# find_package(muparser [REQUIRED] [QUIET] )
#
# Hints may be given by the (environment) variables
# MUPARSER_ROOT ... Path to the installation library
# muparser_ROOT ... Path to the installation library
#
# It sets the following variables:
# MUPARSER_FOUND ... true if muParser is found on the system
# MUPARSER_LIBRARIES ... full path to muParser library
# MUPARSER_INCLUDES ... muParser include directory
# muparser_FOUND ... true if muparser is found on the system
# muparser_LIBRARIES ... full path to muparser library
# muparser_INCLUDES ... muparser include directory
#
# It defines the following targets:
# muparser::muparser ... muparser library to link against
#
find_library(MUPARSER_LIBRARY
NAMES muparser muparserd
HINTS ${MUPARSER_ROOT} ENV MUPARSER_ROOT
find_library(muparser_LIBRARY
NAMES muparser muparserd
HINTS ${muparser_ROOT} ENV muparser_ROOT
)
find_path(MUPARSER_INCLUDE_DIR
muParserDef.h
HINTS ${MUPARSER_ROOT} ENV MUPARSER_ROOT
find_path(muparser_INCLUDE_DIR
muParserDef.h
HINTS ${muparser_ROOT} ENV muparser_ROOT
)
mark_as_advanced(MUPARSER_INCLUDE_DIR MUPARSER_LIBRARY)
mark_as_advanced(muparser_INCLUDE_DIR muparser_LIBRARY)
find_package_handle_standard_args(MUPARSER
DEFAULT_MSG
MUPARSER_LIBRARY MUPARSER_INCLUDE_DIR)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(muparser
DEFAULT_MSG
muparser_LIBRARY muparser_INCLUDE_DIR)
if (MUPARSER_FOUND)
set(MUPARSER_LIBRARIES ${MUPARSER_LIBRARY} )
set(MUPARSER_INCLUDES ${MUPARSER_INCLUDE_DIR} )
if (muparser_FOUND)
set(muparser_LIBRARIES ${muparser_LIBRARY} )
set(muparser_INCLUDES ${muparser_INCLUDE_DIR} )
# add the target
add_library(muparser::muparser SHARED IMPORTED)
set_target_properties(muparser::muparser
PROPERTIES IMPORTED_LOCATION ${MUPARSER_LIBRARIES}
INTERACE_INCLUDE_DIRECTORIES ${MUPARSER_INCLUDES}
PROPERTIES IMPORTED_LOCATION ${muparser_LIBRARIES}
INTERACE_INCLUDE_DIRECTORIES ${muparser_INCLUDES}
)
endif()
add_executable("dorie-rfg" dorie-rfg.cc)
dune_target_link_libraries(dorie-rfg ${DUNE_LIBS})
\ No newline at end of file
add_executable(dorie-rfg dorie-rfg.cc)
dune_target_link_libraries(dorie-rfg ${DUNE_LIBS})
......@@ -56,11 +56,6 @@ int main(int argc, char** argv)
DUNE_THROW(Dune::IOError,"No parameter file specified!");
const std::string inifilename = argv[1];
#if !(HDF5_PARALLEL)
if (helper.size() > 1)
DUNE_THROW(Dune::Exception,"Parallel HDF5 library is needed to run in parallel");
#endif
// Read ini file
Dune::ParameterTree inifile;
Dune::ParameterTreeParser ptreeparser;
......
......@@ -4,16 +4,19 @@ if(dune-testtools_FOUND)
add_subdirectory("test")
endif()
add_executable("richards" richards.cc)
dune_target_link_libraries(richards dorie-richards ${DUNE_LIBS} spdlog)
add_executable(richards richards.cc)
dune_target_link_libraries(richards ${DUNE_LIBS})
target_link_libraries(richards
dorie-richards spdlog muparser::muparser hdf5 yaml-cpp)
add_executable("transport" transport.cc)
dune_target_link_libraries(transport dorie-richards ${DUNE_LIBS} spdlog)
dune_target_link_libraries(transport dorie-transport ${DUNE_LIBS} spdlog)
add_executable(transport transport.cc)
dune_target_link_libraries(transport ${DUNE_LIBS})
target_link_libraries(transport
dorie-richards dorie-transport spdlog muparser::muparser hdf5 yaml-cpp)
add_custom_target("dorie" DEPENDS richards transport)
# enable setting operator scheme from config file
if(EXPERIMENTAL_DG_FEATURES)
target_compile_definitions("dorie" PUBLIC -DEXPERIMENTAL_DG_FEATURES)
endif()
\ No newline at end of file
endif()
......@@ -7,13 +7,9 @@ file(COPY scaling.h5
# scaling adapter test
dorie_add_unit_test(SOURCES test-simulation-base.cc NAME test-simulation-base)
target_link_libraries(ut-test-simulation-base spdlog)
dorie_add_unit_test(SOURCES test-grid-function-container.cc NAME test-grid-function-container)
target_link_libraries(ut-test-grid-function-container spdlog)
dorie_add_unit_test(SOURCES test-interpolators.cc NAME test-interpolators)
target_link_libraries(ut-test-interpolators spdlog)
dorie_add_unit_test(SOURCES test-scaling-adapters.cc NAME test-scaling-adapters)
target_link_libraries(ut-test-scaling-adapters spdlog)
# grid creator test
dorie_add_metaini_test(
......@@ -23,7 +19,6 @@ dorie_add_metaini_test(
METAINI test-grid-creation.mini.in
CREATED_TARGETS gc_target
)
target_link_libraries(${gc_target} spdlog)
configure_file(test-grid-creation-global.mini.in test-grid-creation-global.mini)
dune_add_system_test(
......@@ -44,7 +39,6 @@ dorie_add_metaini_test(
METAINI test-initial-condition.mini.in
CREATED_TARGETS ic_target
)
target_link_libraries(${ic_target} spdlog)
# parameterization and scaling test
dorie_add_metaini_test(
......@@ -54,7 +48,6 @@ dorie_add_metaini_test(
METAINI test-parameterization.mini.in
CREATED_TARGETS param_target
)
target_link_libraries(${param_target} spdlog)
dorie_add_metaini_test(
UNIT_TEST
......@@ -63,7 +56,6 @@ dorie_add_metaini_test(
METAINI test-parameterization-scaled.mini.in
CREATED_TARGETS param_target
)
target_link_libraries(${param_target} spdlog)
add_custom_target(test-parameterization
COMMAND ctest --output-on-failure --tests-regex ^.+test-parameterization.+$
......@@ -86,4 +78,4 @@ dune_add_test(
MPI_RANKS 2
TIMEOUT 30
CMD_ARGS ${CMAKE_CURRENT_BINARY_DIR}/gc_files_0003.ini
)
\ No newline at end of file
)
......@@ -64,7 +64,6 @@ dorie_add_metaini_test(
METAINI mass_conservation.mini.in
SCRIPT dune_execute.py
)
target_link_libraries(${mc_target} spdlog)
add_custom_target(test_mass_conservation
COMMAND ctest --output-on-failure --tests-regex ^.+mass-conservation.+$
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment