#################################################### # # # SpecMiCP : CMakeLists.txt # # # #################################################### project(specmicp) cmake_minimum_required(VERSION 3.2) # CMake Options # ============= # For an explanation of the options see the INSTALL file option( SPECMICP_USE_OPENMP "Use OpenMP for parallelisation" ON ) option( SPECMICP_NO_DEBUG "Disable SpecMiCP assert" OFF ) option( SPECMICP_BUILD_STATIC "Build static libraries" OFF ) option( SPECMICP_BUILD_EXAMPLE "Build the examples" ON ) option( SPECMICP_BENCHMARK "Build benchmark" OFF ) option( SPECMICP_TEST "Enable testing" ON ) option( SPECMICP_BINARIES_USE_STATIC "Executables use static libraries" OFF ) # PGO sequence option( SPECMICP_PROFILE_GENERATE "Generate profile for PGO optimization" OFF ) option( SPECMICP_PROFILE_USE "Use profile for PGO optimization" OFF ) # LTO optimization option( SPECMICP_LTO "Use link time optimization" OFF ) option( SPECMICP_LD_GOLD "Use GNU gold linker" ON ) # the following is only a debug options for developpers # This options turns on the finite difference jacobian in specmicp system option( SPECMICP_DEBUG_EQUATION_FD_JACOBIAN "Use a finite difference jacobian" OFF ) # global variables # ================ set(SPECMICP_VERSION 0.0.4) # External Package # ================ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) # OpenMP #------- # not required but recommended in release mode if(SPECMICP_USE_OPENMP) find_package(OpenMP) if (OPENMP_FOUND) set(SPECMICP_HAVE_OPENMP ON) endif(OPENMP_FOUND) endif() # Eigen # ----- find_package(Eigen3 REQUIRED) # This module comes from the Eigen3 Package include_directories(${EIGEN3_INCLUDE_DIR}) message(STATUS "Eigen3 version ${EIGEN3_VERSION}") # check eigen version # this check is necessary to avoid problem in the transition 3.2->3.3 if(${EIGEN3_VERSION} VERSION_LESS 3.2.90) set(HAVE_EIGEN_VERSION_LT_3_3 ON) add_definitions(-DHAVE_EIGEN_VERSION_LT_3_3) endif() find_package(Eigen3Unsupported) if(EIGEN3_UNSUPPORTED_FOUND) add_definitions(-DEIGEN3_UNSUPPORTED_FOUND) include_directories(${EIGEN3_UNSUPPORTED_INCLUDE_DIR}) endif(EIGEN3_UNSUPPORTED_FOUND) # Yaml-cpp # -------- # YAML-cpp library is required and used by all modules for configuration # and data storage # YAML-CPP does not provide a CMake find module. # Instead, we use pkgconfig include(FindPkgConfig) pkg_check_modules(YAML REQUIRED yaml-cpp>=0.5) include_directories(${YAML_INCLUDE_DIRS}) link_directories(${YAML_LIBRARY_DIRS}) # HDF5 # ---- # HDF5 is required and used by all modules for output # # Only the C serial API is used find_package(HDF5 REQUIRED COMPONENTS C) include_directories(${HDF5_C_INCLUDE_DIR}) # libc functions required # ----------------------- # note : most of this functions are required by specmicp_common/filesystem.cpp # just a friendly warning if(NOT UNIX) message(WARNING "Not tested on non linux platform ! Probably won't work") endif() include(CheckIncludeFile) include(CheckFunctionExists) # just a quick macro to check if a required include exist macro(check_required_include name var) CHECK_INCLUDE_FILE( ${name} ${var} ) if (NOT ${var}) message(SEND_ERROR "Missing required include ${name}") endif() endmacro(check_required_include) check_required_include( "string.h" HAVE_STRING_H ) check_required_include( "dirent.h" HAVE_DIRENT_H ) check_required_include( "unistd.h" HAVE_UNISTD_H ) check_required_include( "sys/stat.h" HAVE_SYS_STAT_H ) check_required_include( "limits.h" HAVE_LIMITS_H ) check_required_include( "stdlib.h" HAVE_STDLIB_H ) # These includes are optional CHECK_INCLUDE_FILE( "sys/time.h" HAVE_TIME_H ) CHECK_INCLUDE_FILE( "sys/resource.h" HAVE_RESOURCE_H ) if (${HAVE_TIME_H} AND ${HAVE_RESOURCE_H}) CHECK_FUNCTION_EXISTS("getrusage" SPECMICP_HAVE_GETRUSAGE) endif() CHECK_FUNCTION_EXISTS( "secure_getenv" SPECMICP_HAVE_SECURE_GETENV ) # Build Mode # ========== # sanitizer # --------- # to check memory, undefined behavior and all... include(ASanitizer) include(UBSanitizer) # compilation flags # ============================================================================ # require C++11 standard by default # note : these cmake features require CMake >= 3.2 set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Some more flags # Check corresponding cmake files for more detail # Gold Linker # ------------ include(gold_linker) # PGO optimization # ---------------- include(pg_optimization) # Symbols visibility # ------------------ include(visibility_flag) # Link time optimization # ---------------------- include(lto) # set the flags # ------------- if (OPENMP_FOUND) SET( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") endif() # let's be pedantic in DEBUG mode, it's always fun SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -pedantic") # always best to check what we do... message(STATUS "C++ flags : ${CMAKE_CXX_FLAGS}") # Directories ######################################################################### # use gnu coding standards include(GNUInstallDirs) # the libraries install dir set( LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_FULL_LIBDIR} CACHE PATH "Installation directory for libraries" ) # the static libraries install dir set( STATIC_LIBRARY_INSTALL_DIR ${CMAKE_INSTALL_FULL_LIBDIR} CACHE PATH "Installation directory for static libraries" ) # Binaries # -------- set( BIN_INSTALL_DIR ${CMAKE_INSTALL_FULL_BINDIR} CACHE PATH "Installation directory for the programs" ) # include #-------- set( INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_FULL_INCLUDEDIR} CACHE PATH "Installation directory for the headers" ) # share #------ set( SHARE_INSTALL_DIR "${CMAKE_INSTALL_FULL_DATADIR}/specmicp/" CACHE PATH "Installation directory for the miscalleneous files..." ) mark_as_advanced( LIBRARY_INSTALL_DIR STATIC_LIBRARY_INSTALL_DIR BIN_INSTALL_DIR INCLUDE_INSTALL_DIR SHARE_INSTALL_DIR ) # CPP API : SpecMiCP / ReactMiCP ######################################################################### # the main source directory - the c++ api set(SPECMICP_CPP_API ${CMAKE_CURRENT_SOURCE_DIR}/src) include_directories( ${SPECMICP_CPP_API} ) add_subdirectory( ${SPECMICP_CPP_API} ) # the necessary libraries to link to set( SPECMICP_LIBS # just speciation solver specmicp specmicp_database specmicp_common ${YAML_LIBRARIES} ) set( REACTMICP_LIBS # reactive transport solver reactmicp dfpm ${SPECMICP_LIBS} ) # static versions set( SPECMICP_STATIC_LIBS specmicp_static specmicp_database_static specmicp_common_static ${YAML_LIBRARIES} ) set( REACTMICP_STATIC_LIBS reactmicp_static dfpm_static ${SPECMICP_STATIC_LIBS} ) # Databases ######################################################################### add_subdirectory( data ) # Documentation ######################################################################### # "common" documentation # ----------------------- set( DOCS_LIST ${CMAKE_CURRENT_SOURCE_DIR}/README.md ${CMAKE_CURRENT_SOURCE_DIR}/INSTALL ${CMAKE_CURRENT_SOURCE_DIR}/COPYING ) add_custom_target(docs SOURCES ${DOCS_LIST}) install(FILES ${DOCS_LIST} DESTINATION ${SHARE_INSTALL_DIR} ) # scripts # -------- add_subdirectory( scripts ) # Doxygen documentation # --------------------- add_subdirectory( doc ) # Tests ######################################################################### if( SPECMICP_TEST ) enable_testing(true) endif() add_subdirectory( tests ) # Examples ######################################################################### add_subdirectory( examples ) # Benchmark ######################################################################## if (SPECMICP_BENCHMARK) add_subdirectory( benchmark ) endif() # Docker ######################################################################## add_subdirectory( docker )