CMakeLists.txt 5.39 KB
Newer Older
1 2 3
# A minimum version for cmake command is required.
cmake_minimum_required(VERSION 3.8)

4
# TODO Add check whether the provided value is valid.
5 6 7 8 9 10 11 12 13 14 15 16


# ===================================================================================================================
# Include a file with default setting. Some of them might be overriden by command line, such as the C or C++ compiler.
# ===================================================================================================================
if(NOT PATH_FILE)
    message(FATAL_ERROR "-DPATH_FILE must be present in the command line and point to a file that specify the paths and settings to use in the build. A default one is defined in cmake/Paths.cmake; feel free to copy and adapt it to your needs.")
endif()

include(${PATH_FILE})


17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
if(MOREFEM_CHECK_UPDATE_GHOSTS_CALL_RELEVANCE)
    message("ADDING FLAG MOREFEM_CHECK_UPDATE_GHOSTS_CALL_RELEVANCE")
    add_definitions(-DMOREFEM_CHECK_UPDATE_GHOSTS_CALL_RELEVANCE)
endif()

if(MOREFEM_EXTENDED_TIME_KEEP)
    message("ADDING FLAG MOREFEM_EXTENDED_TIME_KEEP")
    add_definitions(-DMOREFEM_EXTENDED_TIME_KEEP)
endif()

if(MOREFEM_CHECK_NAN_AND_INF)
    message("ADDING FLAG MOREFEM_CHECK_NAN_AND_INF")
    add_definitions(-DMOREFEM_CHECK_NAN_AND_INF)
endif()


33 34 35 36 37
# ===================================================================================================================
# Set some values in the path file that night be overridden by cache variables.
# WARNING: all those calls must occur BEFORE the call to project, so that overriding remains possible.
# ===================================================================================================================

38
# From https://cmake.org/pipermail/cmake/2008-September/023808.html
39
# Ensure if the user doesn't specify arenything in command line debug is chosen (CMake default is no optimization and no debug symbol, which is rather useless).
40 41 42 43 44 45 46 47 48
if(DEFINED CMAKE_BUILD_TYPE)
   set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of
build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug
Release RelWithDebInfo MinSizeRel.")
else()
   set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build,
options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release
RelWithDebInfo MinSizeRel.")
endif()
49

50
# Set C and CXX compilers from the values read in the setting file. Might be overridden in command line.
51 52 53 54 55 56 57 58

if (NOT DEFINED CMAKE_C_COMPILER)
    set(CMAKE_C_COMPILER ${MPI_CC})
endif()

if (NOT DEFINED CMAKE_CXX_COMPILER)
    set(CMAKE_CXX_COMPILER ${MPI_CXX})
endif()
59

60 61 62 63

# ===================================================================================================================
# Set project.
# ===================================================================================================================
64
project( "MoReFEM_CMAKE")
65

66
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
67

68

69 70 71
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
72 73 74

set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

75
MESSAGE("Module path: ${CMAKE_MODULE_PATH}")
76 77

include(CustomCommands)
78 79


80

81 82 83 84 85 86 87 88 89 90
# All --all_load in target_link_libraries of executables if STATIC library are chose.
    
if(LIBRARY_TYPE MATCHES STATIC)
    set(ALL_LOAD_FLAG "-all_load")
else()
    set(ALL_LOAD_FLAG "")
endif()

#MESSAGE("ALL_LOAD_FLAG: ${ALL_LOAD_FLAG}")

91 92
MESSAGE("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")

93 94
include(compiler)

95 96 97 98 99 100
# Add LTO support in non debug mode.
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
else()
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()        
101

102
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Sources /
103
                    ${CMAKE_CURRENT_SOURCE_DIR}/Sources/ThirdParty/Source/Tclap/include /
104 105 106 107 108 109 110 111 112 113
                    ${OPS_DIR} /
                    ${SELDON_DIR} /
                    ${OPEN_MPI_INCL_DIR} /
                    ${PETSC_GENERAL_INCL_DIR} /
                    ${PETSC_DEBUG_INCL_DIR} /
                    ${PARMETIS_INCL_DIR} /
                    ${LUA_INCL_DIR} /
                    ${BOOST_INCL_DIR}                    
                    )

114 115 116
# TO complete for release mode! (see SCons)
add_definitions(-DOPS_WITH_EXCEPTION)
add_definitions(-DSELDON_WITH_LAPACK -DSELDON_WITH_LAPACK  -DSELDON_WITH_BLAS -DSELDON_WITH_COMPILED_LIBRARY -DSELDON_CHECK_BOUNDS -DSELDON_CHECK_DIMENSIONS)
117

118 119 120 121 122 123 124 125

morefem_find_library(LIB_OPEN_MPI "mpi" ${OPEN_MPI_LIB_DIR} "Openmpi")
morefem_find_library(LIB_OPEN_MPI_CXX "mpi_cxx" ${OPEN_MPI_LIB_DIR} "Openmpi (C++)")
morefem_find_library(LIB_PETSC "petsc" ${PETSC_DEBUG_LIB_DIR} "Petsc")
morefem_find_library(LIB_PARMETIS "parmetis" ${PARMETIS_LIB_DIR} "Parmetis")
morefem_find_library(LIB_LUA "lua" ${LUA_LIB_DIR} "Lua")
morefem_find_library(LIB_BOOST_FILESYSTEM "boost_filesystem" ${BOOST_LIB_DIR} "Boost filesystem")
morefem_find_library(LIB_BOOST_SYSTEM "boost_system" ${BOOST_LIB_DIR} "Boost system")
126

127 128 129 130 131 132
if(BLAS_CUSTOM_LINKER)
    set(LIB_BLAS ${BLAS_LIB})    
else()
    morefem_find_library(LIB_BLAS ${BLAS_LIB} ${BLAS_LIB_DIR} "Blas library.")
endif()

133 134 135
if (PHILLIPS_DIR)
    morefem_find_library(LIB_PHILLIPS "pfa_border_distance_interface" ${PHILLIPS_DIR} "Phillips library")
endif()
136

137 138 139 140 141 142 143 144
set(MOREFEM_COMMON_DEP
    ${LIB_OPEN_MPI}
    ${LIB_OPEN_MPI_CXX}
    ${LIB_PETSC} 
    ${LIB_PARMETIS} 
    ${LIB_LUA} 
    ${LIB_BOOST_FILESYSTEM} 
    ${LIB_BOOST_SYSTEM}                      
145
    ${LIB_BLAS}
146 147 148
)


149 150
add_subdirectory(Sources)
      
151 152