Commit 9be9ae1d authored by Praetorius, Simon's avatar Praetorius, Simon

modern cmake

parent 77862e92
cmake_minimum_required(VERSION 3.1) cmake_minimum_required(VERSION 3.13)
project(amdis LANGUAGES CXX VERSION 0.2) project(amdis LANGUAGES CXX VERSION 0.2)
#find dune-common and set the module path #find dune-common and set the module path
...@@ -11,8 +11,9 @@ include(DuneMacros) ...@@ -11,8 +11,9 @@ include(DuneMacros)
# start a dune project with information from dune.module # start a dune project with information from dune.module
dune_project() dune_project()
dune_add_library(amdis)
dune_enable_all_packages(MODULE_LIBRARIES amdis fmt) add_dune_all_flags(amdis)
target_link_dune_default_libraries(amdis)
add_subdirectory("amdis") add_subdirectory("amdis")
add_subdirectory("bin") add_subdirectory("bin")
...@@ -21,9 +22,30 @@ add_subdirectory("examples" EXCLUDE_FROM_ALL) ...@@ -21,9 +22,30 @@ add_subdirectory("examples" EXCLUDE_FROM_ALL)
add_subdirectory("libs") add_subdirectory("libs")
add_subdirectory("test") add_subdirectory("test")
target_link_libraries(amdis fmt) dune_target_link_libraries(amdis fmt)
target_compile_options(amdis PUBLIC "-Wall" "-Wpedantic") target_compile_options(amdis PUBLIC "-Wall" "-Wpedantic")
if (MTL_FOUND)
dune_target_link_libraries(amdis MTL::MTL)
target_compile_definitions(amdis PUBLIC ENABLE_MTL)
endif (MTL_FOUND)
if (HYPRE_FOUND)
dune_target_link_libraries(amdis HYPRE::HYPRE)
target_compile_definitions(amdis PUBLIC ENABLE_HYPRE)
endif(HYPRE_FOUND)
if (EIGEN3_FOUND)
dune_target_link_libraries(amdis Eigen3::Eigen)
target_compile_definitions(amdis PUBLIC ENABLE_EIGEN)
endif (EIGEN3_FOUND)
if (PETSc_FOUND)
dune_target_link_libraries(amdis PETSc::PETSc)
target_compile_definitions(amdis PUBLIC ENABLE_PETSC)
endif (PETSc_FOUND)
option(ENABLE_ALL_WARNINGS "enable all meaningful warnings" OFF) option(ENABLE_ALL_WARNINGS "enable all meaningful warnings" OFF)
if (ENABLE_ALL_WARNINGS) if (ENABLE_ALL_WARNINGS)
target_compile_options(amdis PUBLIC "-Wextra" "-Wnon-virtual-dtor" target_compile_options(amdis PUBLIC "-Wextra" "-Wnon-virtual-dtor"
...@@ -31,5 +53,6 @@ if (ENABLE_ALL_WARNINGS) ...@@ -31,5 +53,6 @@ if (ENABLE_ALL_WARNINGS)
"-Woverloaded-virtual" "-Wconversion") "-Woverloaded-virtual" "-Wconversion")
endif (ENABLE_ALL_WARNINGS) endif (ENABLE_ALL_WARNINGS)
# finalize the dune project, e.g. generating config.h etc. # finalize the dune project, e.g. generating config.h etc.
finalize_dune_project(GENERATE_CONFIG_H_CMAKE) finalize_dune_project(GENERATE_CONFIG_H_CMAKE)
#install headers #install headers
dune_library_add_sources(amdis SOURCES target_sources(amdis PRIVATE
AdaptInfo.cpp AdaptInfo.cpp
AdaptInstationary.cpp AdaptInstationary.cpp
AdaptStationary.cpp AdaptStationary.cpp
......
...@@ -10,7 +10,7 @@ namespace AMDiS ...@@ -10,7 +10,7 @@ namespace AMDiS
{ {
/// Establishes an environment for sequential and parallel AMDiS programs /// Establishes an environment for sequential and parallel AMDiS programs
/** /**
* This object initializes the MPI environement, parses initfiles and may * This object initializes the MPI environment, parses initfiles and may
* initialize other external libraries. It is constructed with the program * initialize other external libraries. It is constructed with the program
* commandline arguments. In its destruction, the MPI environment is finalized. * commandline arguments. In its destruction, the MPI environment is finalized.
* In the vast majority of AMDiS programs, an instance of Environment should * In the vast majority of AMDiS programs, an instance of Environment should
......
dune_library_add_sources(amdis target_sources(amdis PRIVATE
SOURCES
Filesystem.cpp Filesystem.cpp
String.cpp String.cpp
) )
......
dune_library_add_sources(amdis target_sources(amdis PRIVATE
SOURCES
FileWriterBase.cpp FileWriterBase.cpp
) )
......
dune_library_add_sources(amdis target_sources(amdis PRIVATE
SOURCES
PreconCreator.cpp PreconCreator.cpp
SolverCreator.cpp) SolverCreator.cpp)
......
dune_library_add_sources(amdis target_sources(amdis PRIVATE
SOURCES
Preconditioners.cpp Preconditioners.cpp
Solvers.cpp) Solvers.cpp)
......
...@@ -24,27 +24,19 @@ endif (NOT BACKEND) ...@@ -24,27 +24,19 @@ endif (NOT BACKEND)
if (BACKEND STREQUAL "MTL" OR BACKEND STREQUAL "MTL4") if (BACKEND STREQUAL "MTL" OR BACKEND STREQUAL "MTL4")
find_package(MTL REQUIRED) find_package(MTL REQUIRED)
set(AMDIS_HAS_MTL TRUE) set(AMDIS_HAS_MTL TRUE)
message(STATUS " Found MTL, version: ${MTL_VERSION}")
dune_register_package_flags(LIBRARIES MTL::MTL COMPILE_DEFINITIONS "ENABLE_MTL=1")
find_package(HYPRE) find_package(HYPRE)
if (HYPRE_FOUND) set(AMDIS_HAS_HYPRE ${HYPRE_FOUND})
set(AMDIS_HAS_HYPRE TRUE)
dune_register_package_flags(LIBRARIES HYPRE::HYPRE COMPILE_DEFINITIONS "ENABLE_HYPRE=1")
endif(HYPRE_FOUND)
elseif (BACKEND STREQUAL "EIGEN" OR BACKEND STREQUAL "EIGEN3") elseif (BACKEND STREQUAL "EIGEN" OR BACKEND STREQUAL "EIGEN3")
find_package(Eigen3 REQUIRED 3.3.5) find_package(Eigen3 REQUIRED 3.3.5)
set(AMDIS_HAS_EIGEN TRUE) set(AMDIS_HAS_EIGEN TRUE)
if (EIGEN3_FOUND) message(STATUS " Found Eigen3, version: ${Eigen3_VERSION}")
message(STATUS " Found Eigen3, version: ${Eigen3_VERSION}")
dune_register_package_flags(LIBRARIES Eigen3::Eigen COMPILE_DEFINITIONS "ENABLE_EIGEN=1")
endif (EIGEN3_FOUND)
elseif (BACKEND STREQUAL "PETSC") elseif (BACKEND STREQUAL "PETSC")
find_package(PETSc REQUIRED) find_package(PETSc REQUIRED)
if (PETSc_FOUND) set(AMDIS_HAS_PETSC TRUE)
set(AMDIS_HAS_PETSC TRUE)
dune_register_package_flags(LIBRARIES PETSc::PETSc COMPILE_DEFINITIONS "ENABLE_PETSC=1")
endif (PETSc_FOUND)
elseif (BACKEND STREQUAL "ISTL") elseif (BACKEND STREQUAL "ISTL")
if (NOT dune-istl_FOUND) if (NOT dune-istl_FOUND)
message(FATAL_ERROR "Need dune-istl, MTL, PETSc, or Eigen3 as linear algebra backend. Change flag BACKEND!") message(FATAL_ERROR "Need dune-istl, MTL, PETSc, or Eigen3 as linear algebra backend. Change flag BACKEND!")
...@@ -52,6 +44,3 @@ elseif (BACKEND STREQUAL "ISTL") ...@@ -52,6 +44,3 @@ elseif (BACKEND STREQUAL "ISTL")
else () else ()
message(FATAL_ERROR "BACKEND must be one of MTL, EIGEN, PETSC, ISTL") message(FATAL_ERROR "BACKEND must be one of MTL, EIGEN, PETSC, ISTL")
endif () endif ()
set(DUNE_CUSTOM_PKG_CONFIG_SECTION "set(BACKEND \"${BACKEND}\")")
\ No newline at end of file
...@@ -15,31 +15,21 @@ ...@@ -15,31 +15,21 @@
# Author: Simon Praetorius <simon.praetorius@tu-dresden.de> # Author: Simon Praetorius <simon.praetorius@tu-dresden.de>
mark_as_advanced(HYPRE_FOUND HYPRE_INCLUDE_DIR HYPRE_LIBRARIES)
find_path(HYPRE_INCLUDE_DIR HYPRE.h find_path(HYPRE_INCLUDE_DIR HYPRE.h
PATHS PATHS
/opt/software/hypre /opt/software
${HYPRE_DIR} ${HYPRE_ROOT} ${HYPRE_DIR} ENV HYPRE_DIR
ENV HYPRE_DIR ENV HYPRE_ROOT
ENV EBROOTHYPRE ENV EBROOTHYPRE
PATH_SUFFIXES PATH_SUFFIXES
hypre include include/hypre hypre)
NO_DEFAULT_PATH)
find_path(HYPRE_INCLUDE_DIR HYPRE.h
PATH_SUFFIXES hypre include include/hypre)
find_library(HYPRE_LIBRARY HYPRE find_library(HYPRE_LIBRARY HYPRE
PATHS PATHS
/opt/software/hypre /opt/software
${HYPRE_DIR} ${HYPRE_ROOT} ${HYPRE_DIR} ENV HYPRE_DIR
ENV HYPRE_DIR ENV HYPRE_ROOT
ENV EBROOTHYPRE ENV EBROOTHYPRE
PATH_SUFFIXES PATH_SUFFIXES
lib hypre)
NO_DEFAULT_PATH)
find_library(HYPRE_LIBRARY HYPRE
PATH_SUFFIXES lib)
if (HYPRE_LIBRARY) if (HYPRE_LIBRARY)
set(HYPRE_LIBRARIES ${HYPRE_LIBRARY}) set(HYPRE_LIBRARIES ${HYPRE_LIBRARY})
...@@ -56,9 +46,12 @@ if (HYPRE_LIBRARY) ...@@ -56,9 +46,12 @@ if (HYPRE_LIBRARY)
endforeach() endforeach()
endif (HYPRE_LIBRARY) endif (HYPRE_LIBRARY)
mark_as_advanced(HYPRE_FOUND HYPRE_INCLUDE_DIR HYPRE_LIBRARIES)
include(FindPackageHandleStandardArgs) include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HYPRE find_package_handle_standard_args(HYPRE
REQUIRED_VARS HYPRE_INCLUDE_DIR HYPRE_LIBRARIES REQUIRED_VARS
HYPRE_INCLUDE_DIR HYPRE_LIBRARIES
) )
# text for feature summary # text for feature summary
......
...@@ -15,18 +15,16 @@ ...@@ -15,18 +15,16 @@
# Author: Simon Praetorius <simon.praetorius@tu-dresden.de> # Author: Simon Praetorius <simon.praetorius@tu-dresden.de>
mark_as_advanced(MTL_FOUND MTL_COMPILE_DEFINITIONS MTL_INCLUDE_DIR) mark_as_advanced(MTL_COMPILE_DEFINITIONS MTL_INCLUDE_DIR)
find_path(MTL_INCLUDE_DIR boost/numeric/mtl/mtl.hpp find_path(MTL_INCLUDE_DIR boost/numeric/mtl/mtl.hpp
PATHS HINTS
/opt/software/mtl /opt/software
/opt/sources/mtl /opt/sources
/opt/development/mtl /opt/development
${MTL_DIR} ${MTL_ROOT}
ENV MTL_DIR ENV MTL_ROOT
ENV EBROOTMTL ENV EBROOTMTL
PATH_SUFFIXES PATH_SUFFIXES
include mtl mtl4
) )
set(MTL_COMPILE_DEFINITIONS MTL_ASSERT_FOR_THROW=1) set(MTL_COMPILE_DEFINITIONS MTL_ASSERT_FOR_THROW=1)
...@@ -46,15 +44,17 @@ set_package_properties("MTL" PROPERTIES ...@@ -46,15 +44,17 @@ set_package_properties("MTL" PROPERTIES
if(MTL_FOUND AND NOT TARGET MTL::MTL) if(MTL_FOUND AND NOT TARGET MTL::MTL)
add_library(MTL::MTL INTERFACE IMPORTED) add_library(MTL::MTL INTERFACE IMPORTED)
find_package(SuiteSparse QUIET) find_package(SuiteSparse COMPONENTS UMFPACK)
if (SuiteSparse_FOUND) if (SuiteSparse_UMFPACK_FOUND)
list(APPEND MTL_COMPILE_DEFINITIONS "MTL_HAS_UMFPACK") list(APPEND MTL_COMPILE_DEFINITIONS "MTL_HAS_UMFPACK")
endif (SuiteSparse_FOUND) target_link_libraries(MTL::MTL INTERFACE SuiteSparse::UMFPACK)
endif ()
find_package(HYPRE QUIET) find_package(HYPRE)
if (HYPRE_FOUND) if (HYPRE_FOUND)
list(APPEND MTL_COMPILE_DEFINITIONS "MTL_HAS_HYPRE") list(APPEND MTL_COMPILE_DEFINITIONS "MTL_HAS_HYPRE")
endif (HYPRE_FOUND) target_link_libraries(MTL::MTL INTERFACE HYPRE::HYPRE)
endif ()
set_target_properties(MTL::MTL PROPERTIES set_target_properties(MTL::MTL PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${MTL_INCLUDE_DIR}" INTERFACE_INCLUDE_DIRECTORIES "${MTL_INCLUDE_DIR}"
......
if (NOT amdis_FOUND)
# Whether this module is installed or not
set(amdis_INSTALLED @MODULE_INSTALLED@)
# Settings specific to the module
@amdis_INIT@
@PACKAGE_INIT@
#report other information
set_and_check(amdis_PREFIX "${PACKAGE_PREFIX_DIR}")
set_and_check(amdis_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@")
set(amdis_CXX_FLAGS "@CMAKE_CXX_FLAGS@")
set(amdis_CXX_FLAGS_DEBUG "@CMAKE_CXX_FLAGS_DEBUG@")
set(amdis_CXX_FLAGS_MINSIZEREL "@CMAKE_CXX_FLAGS_MINSIZEREL@")
set(amdis_CXX_FLAGS_RELEASE "@CMAKE_CXX_FLAGS_RELEASE@")
set(amdis_CXX_FLAGS_RELWITHDEBINFO "@CMAKE_CXX_FLAGS_RELWITHDEBINFO@")
set(amdis_LIBRARIES "@DUNE_MODULE_LIBRARIES@")
set(amdis_DEPENDS "@amdis_DEPENDS@")
set(amdis_SUGGESTS "@amdis_SUGGESTS@")
set_and_check(amdis_MODULE_PATH "@PACKAGE_DUNE_INSTALL_MODULEDIR@")
list(APPEND CMAKE_MODULE_PATH ${dune-common_MODULE_PATH})
list(APPEND CMAKE_MODULE_PATH ${amdis_MODULE_PATH})
# import the target
if (amdis_LIBRARIES)
get_filename_component(_dir "${CMAKE_CURRENT_LIST_FILE}" PATH)
include("${_dir}/amdis-targets.cmake")
endif ()
set(BACKEND @BACKEND@)
include(CMakeFindDependencyMacro)
if (@MTL_FOUND@)
set(MTL_INCLUDE_DIR @MTL_INCLUDE_DIR@ CACHE PATH "")
find_dependency(MTL)
endif ()
if (@HYPRE_FOUND@)
set(HYPRE_INCLUDE_DIR @HYPRE_INCLUDE_DIR@ CACHE PATH "")
set(HYPRE_LIBRARY @HYPRE_LIBRARY@ CACHE FILEPATH "")
find_dependency(HYPRE)
endif ()
if (@Eigen3_FOUND@)
find_dependency(Eigen3 @Eigen3_VERSION@)
endif ()
if (@PETSc_FOUND@)
find_dependency(PETSc)
endif ()
endif (NOT amdis_FOUND)
...@@ -16,12 +16,11 @@ if (NOT EXISTS "${PROJECT_SOURCE_DIR}/libs/fmt/CMakeLists.txt") ...@@ -16,12 +16,11 @@ if (NOT EXISTS "${PROJECT_SOURCE_DIR}/libs/fmt/CMakeLists.txt")
message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.")
endif() endif()
dune_add_library(fmt SOURCES
dune_library_add_sources(fmt SOURCES
fmt/src/format.cc fmt/src/format.cc
fmt/src/posix.cc fmt/src/posix.cc
) )
target_compile_features(fmt PRIVATE cxx_std_17)
target_include_directories(fmt PUBLIC target_include_directories(fmt PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/libs/fmt/include>) $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/libs/fmt/include>)
...@@ -34,4 +33,4 @@ install(FILES ...@@ -34,4 +33,4 @@ install(FILES
fmt/include/fmt/printf.h fmt/include/fmt/printf.h
fmt/include/fmt/ranges.h fmt/include/fmt/ranges.h
fmt/include/fmt/time.h fmt/include/fmt/time.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fmt) DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/fmt)
\ No newline at end of file
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