Skip to content
Snippets Groups Projects
Select Git revision
  • 0684b39e8e8a36a6537ee6ae0a073270b339910b
  • develop default protected
  • feature/kinetic-schemes
  • feature/reconstruction
  • feature/local-dt-fsi
  • feature/composite-scheme-sources
  • feature/composite-scheme-other-fluxes
  • feature/serraille
  • feature/variational-hydro
  • feature/composite-scheme
  • hyperplastic
  • feature/polynomials
  • feature/gks
  • feature/implicit-solver-o2
  • feature/coupling_module
  • feature/implicit-solver
  • feature/merge-local-dt-fsi
  • master protected
  • feature/escobar-smoother
  • feature/hypoelasticity-clean
  • feature/hypoelasticity
  • v0.5.0 protected
  • v0.4.1 protected
  • v0.4.0 protected
  • v0.3.0 protected
  • v0.2.0 protected
  • v0.1.0 protected
  • Kidder
  • v0.0.4 protected
  • v0.0.3 protected
  • v0.0.2 protected
  • v0 protected
  • v0.0.1 protected
33 results

CMakeLists.txt

Blame
    • Stéphane Del Pino's avatar
      0684b39e
      Improve version numbering management · 0684b39e
      Stéphane Del Pino authored
      - allow to define version numbers such as a.b.c(-suffix), where the optional
        suffix parameter may be for instance rc2, beta3 or so...
      
      - deduce the suffix-less release number (a.b.c) since cmake does not support
        release number suffixes...
      
      - improve git-tag matching mechanism. One now searches for the nearest tag that
        matches 'v[0-9]*' and checks if it corresponds to the current release
        number. This allows to define annotate tags that are not related to version
        tags. The only constrain is that such tags must not match 'v[0-9]*'
      0684b39e
      History
      Improve version numbering management
      Stéphane Del Pino authored
      - allow to define version numbers such as a.b.c(-suffix), where the optional
        suffix parameter may be for instance rc2, beta3 or so...
      
      - deduce the suffix-less release number (a.b.c) since cmake does not support
        release number suffixes...
      
      - improve git-tag matching mechanism. One now searches for the nearest tag that
        matches 'v[0-9]*' and checks if it corresponds to the current release
        number. This allows to define annotate tags that are not related to version
        tags. The only constrain is that such tags must not match 'v[0-9]*'
    CMakeLists.txt 7.23 KiB
    cmake_minimum_required (VERSION 3.4)
    
    # CMake utils
    list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
    
    # Forbids in-source builds
    include(CheckNotInSources)
    
    #------------------------------------------------------
    #----------------- Main configuration -----------------
    #------------------------------------------------------
    
    # custom variable allowing to define version suffixes such as -rc*, -beta*, ...
    set(PASTIS_VERSION "0.3.0")
    
    # deduce PASTIS_SHORT_VERSION using regex
    string(REGEX MATCH "^[0-9]+\.[0-9]+\.[0-9]+" PASTIS_SHORT_VERSION ${PASTIS_VERSION})
    if("${PASTIS_SHORT_VERSION}" STREQUAL "")
      message(FATAL_ERROR "Unable to compute short version from PASTIS_VERSION=${PASTIS_VERSION}")
    endif()
    
    # set project version as PASTIS_SHORT_VERSION
    project (Pastis VERSION ${PASTIS_SHORT_VERSION})
    
    #------------------------------------------------------
    
    set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
    
    #------------------------------------------------------
    
    set(PASTIS_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
    set(PASTIS_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
    
    # Add new build types
    message("* Adding build types...")
    set(CMAKE_CXX_FLAGS_COVERAGE
      "-g -Wall -O0 --coverage"
      CACHE STRING "Flags used by the C++ compiler during coverage builds."
      FORCE )
    set(CMAKE_C_FLAGS_COVERAGE
      "-g -Wall -O0 --coverage"
      CACHE STRING "Flags used by the C compiler during coverage builds."
      FORCE )
    set(CMAKE_EXE_LINKER_FLAGS_COVERAGE
      "--coverage"
      CACHE STRING "Flags used for linking binaries during coverage builds."
      FORCE )
    set(CMAKE_SHARED_LINKER_FLAGS_COVERAGE
      "--coverage"
      CACHE STRING "Flags used by the shared libraries linker during coverage builds."
      FORCE )
    mark_as_advanced(
      CMAKE_CXX_FLAGS_COVERAGE
      CMAKE_C_FLAGS_COVERAGE
      CMAKE_EXE_LINKER_FLAGS_COVERAGE
      CMAKE_SHARED_LINKER_FLAGS_COVERAGE )
    
    if(CMAKE_BUILD_TYPE)
      string(REGEX MATCH "(Debug|Release|RelWithDebInfo|MinSizeRel|Coverage)" VALID_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
      if(NOT VALID_BUILD_TYPE)
        message(FATAL_ERROR "Invalid CMAKE_BUILD_TYPE: '${CMAKE_BUILD_TYPE}'")
      endif()
    endif()
    
    # Default build type is RelWIthDebInfo
    if(NOT CMAKE_BUILD_TYPE)
      set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
          "Choose the type of build: Debug Release RelWithDebInfo MinSizeRel Coverage."
          FORCE)
    endif()
    
    #------------------------------------------------------
    
    # Checks if compiler version is compatible with Pastis sources
    set(GNU_CXX_MIN_VERSION "7.0.0")
    set(CLANG_CXX_MIN_VERSION "5.0.0")
    
    # Pastis default compiler flags
    set(PASTIS_CXX_FLAGS "${PASTIS_CXX_FLAGS} -Wall -Wextra")
    
    if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
      if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${GNU_CXX_MIN_VERSION}")
        message(FATAL_ERROR "Pastis build requires at least g++-${GNU_CXX_MIN_VERSION}")
      endif()
    elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
      if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "${CLANG_CXX_MIN_VERSION}")
        message(FATAL_ERROR "Pastis build requires at least llvm/clang ++-${CLANG_CXX_MIN_VERSION}")
      endif()
      set(PASTIS_CXX_FLAGS "${PASTIS_CXX_FLAGS} -Wsign-compare -Wunused -Wunused-member-function -Wunused-private-field")
    endif()
    
    
    #------------------------------------------------------
    
    # setting Kokkos defaults to OpenMP when available
    include(FindOpenMP)
    if(${OPENMP_FOUND})
      set(KOKKOS_ENABLE_OPENMP ON CACHE BOOL "")
    endif()
    
    # do not build ETI by default
    set(KOKKOS_ENABLE_EXPLICIT_INSTANTIATION OFF CACHE BOOL "")
    
    # do not use Kokkos deprecated code
    set(KOKKOS_ENABLE_DEPRECATED_CODE OFF CACHE BOOL "")
    
    # Kokkos compiler flags
    add_subdirectory(${PASTIS_SOURCE_DIR}/packages/kokkos)
    include_directories(SYSTEM ${Kokkos_INCLUDE_DIRS_RET})
    include(GetKokkosCompilerFlags)
    
    # do not pollute compilation with Kokkos internal warnings
    set_target_properties(kokkos PROPERTIES COMPILE_FLAGS "-w")
    
    # sets Kokkos debug flags when non release build
    if (CMAKE_BUILD_TYPE MATCHES "Release")
      set (KOKKOS_ENABLE_DEBUG OFF)
    else()
      set (KOKKOS_ENABLE_DEBUG ON)
    endif()
    
    # C++ 17 flags
    if(${CMAKE_VERSION} VERSION_LESS "3.8.0")
      message(WARNING "Please consider to switch to CMake >= 3.8")
      set(PASTIS_CXX_FLAGS "${PASTIS_CXX_FLAGS}  -std=gnu++1z")
      if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
        set(PASTIS_CXX_FLAGS "${PASTIS_CXX_FLAGS}  -Wno-c++17-extensions")
      endif()
    else()
      set(CMAKE_CXX_STANDARD "17")
    endif()
    
    # Compiler flags
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PASTIS_CXX_FLAGS}")
    
    # Add debug mode for Standard C++ library
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_GLIBCXX_DEBUG -D_LIBCPP_DEBUG=1 ${PASTIS_CXX_FLAGS}")
    set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -D_GLIBCXX_DEBUG -D_LIBCPP_DEBUG=1 ${PASTIS_CXX_FLAGS}")
    
    #------------------------------------------------------
    
    # Rang (colors? Useless thus necessary!)
    include_directories(${PASTIS_SOURCE_DIR}/packages/rang/include)
    
    # CLI11
    include_directories(${PASTIS_SOURCE_DIR}/packages/CLI11/include)
    
    # Pastis src
    add_subdirectory(src)
    
    include_directories(src)
    include_directories(src/algebra)
    include_directories(src/mesh)
    include_directories(src/output)
    include_directories(src/utils)
    include_directories(src/scheme)
    
    # Pastis tests
    
    set(CATCH_MODULE_PATH "${PASTIS_SOURCE_DIR}/packages/Catch2")
    set(CATCH_INCLUDE_PATH "${CATCH_MODULE_PATH}/single_include/catch2")
    
    include("${CATCH_MODULE_PATH}/contrib/ParseAndAddCatchTests.cmake")
    add_subdirectory("${CATCH_MODULE_PATH}")
    
    add_subdirectory(tests)
    enable_testing()
    
    # unit tests coverage
    
    if("${CMAKE_BUILD_TYPE}" STREQUAL "Coverage")
      find_program(GCOVR gcovr)
      if(NOT GCOVR)
        message(FATAL_ERROR "gcovr not found, cannot perform coverage.")
      endif()
    
      if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
        string(REPLACE "clang++" "llvm-cov" LLVM_COV "${CMAKE_CXX_COMPILER}")
        if(NOT EXISTS "${LLVM_COV}")
          message(FATAL_ERROR "could not find ${LLVM_COV}, cannot perform coverage (using g++ for coverage is recommended).")
        endif()
    
        set(GCOVR_EXTRA "--gcov-executable=${LLVM_COV} gcov")
      endif()
    
      set (GCOVR_EXCLUDE
        -e "${PASTIS_SOURCE_DIR}/src/main.cpp"
        -e "${PASTIS_SOURCE_DIR}/src/utils/BacktraceManager.cpp"
        -e "${PASTIS_SOURCE_DIR}/src/utils/BacktraceManager.hpp"
        )
    
      set(GCOVR_OPTIONS --object-directory="${PASTIS_BINARY_DIR}" -r "${PASTIS_SOURCE_DIR}/src" ${GCOVR_EXCLUDE} ${GCOVR_EXTRA})
    
      add_custom_target(run_unit_tests
        ALL
        COMMAND ${CMAKE_CTEST_COMMAND} -j ${PROCESSOR_COUNT}
        DEPENDS unit_tests pastis
        COMMENT "Executing unit tests."
        )
    
      add_custom_target(coverage
        ALL
        COMMAND ${GCOVR} ${GCOVR_OPTIONS}
        DEPENDS run_unit_tests
        COMMENT "Running gcovr to build coverage report."
        )
    
      add_custom_target(coverage-report
        ALL
        COMMAND ${CMAKE_COMMAND} -E remove_directory "${PASTIS_BINARY_DIR}/coverage"
        COMMAND ${CMAKE_COMMAND} -E make_directory "${PASTIS_BINARY_DIR}/coverage"
        COMMAND ${GCOVR} ${GCOVR_OPTIONS} --delete --html --html-details -o "${PASTIS_BINARY_DIR}/coverage/index.html"
        DEPENDS coverage
        COMMENT "Building coverage html report."
        WORKING_DIRECTORY "${PASTIS_BINARY_DIR}"
        )
    
    endif()
    
    # -----------------------------------------------------
    
    link_libraries("-rdynamic")
    
    # ------------------- Source files --------------------
    # Pastis binary
    add_executable(
      pastis
      src/main.cpp)
    
    # Libraries
    target_link_libraries(
      pastis
      kokkos
      PastisUtils
      PastisMesh)