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

4 5 6 7

# ===================================================================================================================
# Include a file with default setting. Some of them might be overriden by command line, such as the C or C++ compiler.
# ===================================================================================================================
8
if(NOT SETTINGS_FILE)
9
    message(FATAL_ERROR "-DSETTINGS_FILE must be present in the command line and point to a file that specify the paths and settings to use in the build. Examples are given in cmake/Settings folder; feel free to copy and adapt them to your needs.")
10 11
endif()

12
include(${SETTINGS_FILE})
13 14


15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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()


31 32 33 34 35
# ===================================================================================================================
# 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.
# ===================================================================================================================

36 37 38 39 40 41 42 43
# From http://cmake.3232098.n2.nabble.com/Default-value-for-CMAKE-BUILD-TYPE-td7550756.html#a7550797
# Set a default build type if none was specified
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message(STATUS "Setting build type to 'Debug' as none was specified.")
  set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
  # Set the possible values of build type for cmake-gui
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
    "MinSizeRel" "RelWithDebInfo")
44
endif()
45

46
set(MOREFEM_INSTALL_DIR ${MOREFEM_INSTALL_DIR}/${CMAKE_BUILD_TYPE})
47
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_LIST_DIR}/cmake)
48
# Set C and CXX compilers from the values read in the setting file. Might be overridden in command line.
49 50 51 52 53 54 55 56

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()
57

58 59 60 61

# ===================================================================================================================
# Set project.
# ===================================================================================================================
62
project( "MoReFEM_CMAKE")
63

64
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
65

66 67
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
68
set(CMAKE_CXX_EXTENSIONS OFF) # I want c++17, not gnu++17.
69

70
include(CustomCommands)
71

72
# All --all_load in target_link_libraries of executables if STATIC library are chosen.
73 74 75 76 77 78 79
    
if(LIBRARY_TYPE MATCHES STATIC)
    set(ALL_LOAD_FLAG "-all_load")
else()
    set(ALL_LOAD_FLAG "")
endif()

80 81
MESSAGE("Generated with config types: ${CMAKE_CONFIGURATION_TYPES}")

82
include(Compiler)
83

84 85 86
# Add LTO support in non debug mode.
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)
87 88 89
    set(PETSC_SPECIFIC_INCL_DIR ${PETSC_DEBUG_INCL_DIR} )
    set(PETSC_SPECIFIC_LIB_DIR ${PETSC_DEBUG_LIB_DIR} )
    add_definitions(-DSELDON_CHECK_BOUNDS -DSELDON_CHECK_DIMENSIONS -DDEBUG=1)
90 91
else()
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
92 93
    set(PETSC_SPECIFIC_INCL_DIR ${PETSC_RELEASE_INCL_DIR} )   
    set(PETSC_SPECIFIC_LIB_DIR ${PETSC_RELEASE_LIB_DIR} ) 
94
endif()        
95

96
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/Sources /
97
                    ${CMAKE_CURRENT_SOURCE_DIR}/Sources/ThirdParty/Source/Tclap/include /
98 99
                    ${CMAKE_CURRENT_SOURCE_DIR}/Sources/ThirdParty/Source/Ops /
                    ${CMAKE_CURRENT_SOURCE_DIR}/Sources/ThirdParty/Source/Seldon /
100 101
                    ${OPEN_MPI_INCL_DIR} /
                    ${PETSC_GENERAL_INCL_DIR} /
102
                    ${PETSC_SPECIFIC_INCL_DIR} /
103 104 105 106 107
                    ${PARMETIS_INCL_DIR} /
                    ${LUA_INCL_DIR} /
                    ${BOOST_INCL_DIR}                    
                    )

108
add_definitions(-DOPS_WITH_EXCEPTION)
109
add_definitions(-DSELDON_WITH_LAPACK -DSELDON_WITH_BLAS -DSELDON_WITH_COMPILED_LIBRARY)
110

111 112 113

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++)")
114
morefem_find_library(LIB_PETSC "petsc" ${PETSC_SPECIFIC_LIB_DIR} "Petsc")
115 116 117 118
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")
119

120 121 122 123 124 125
if(BLAS_CUSTOM_LINKER)
    set(LIB_BLAS ${BLAS_LIB})    
else()
    morefem_find_library(LIB_BLAS ${BLAS_LIB} ${BLAS_LIB_DIR} "Blas library.")
endif()

126 127 128
if (PHILLIPS_DIR)
    morefem_find_library(LIB_PHILLIPS "pfa_border_distance_interface" ${PHILLIPS_DIR} "Phillips library")
endif()
129

130 131 132 133
set(MOREFEM_COMMON_DEP
    ${LIB_OPEN_MPI}
    ${LIB_OPEN_MPI_CXX}
    ${LIB_PETSC} 
134
    ${LIB_PARMETIS}     
135 136
    ${LIB_BOOST_FILESYSTEM} 
    ${LIB_BOOST_SYSTEM}                      
137
    ${LIB_BLAS}
138 139
)

140 141
set(MOREFEM_INSTALL_DIR_EXE ${MOREFEM_INSTALL_DIR}/bin)
set(MOREFEM_INSTALL_DIR_LIB ${MOREFEM_INSTALL_DIR}/lib)
142
set(MOREFEM_INSTALL_DIR_INCL ${MOREFEM_INSTALL_DIR}/include)
143
set(MOREFEM_INSTALL_DIR_CMAKE ${MOREFEM_INSTALL_DIR}/cmake)
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164

######################################################
# Settings to make shared library work correctly
######################################################

#SET(CMAKE_INSTALL_RPATH "/Volumes/Data/sebastien/Morefem/CMake/lib")
set(CMAKE_MACOSX_RPATH True)

# use, i.e. don't skip the full RPATH for the build tree
set(CMAKE_SKIP_BUILD_RPATH  False)

# when building, don't use the install RPATH already
# (but later on when installing)
set(CMAKE_BUILD_WITH_INSTALL_RPATH False) 

set(CMAKE_INSTALL_RPATH "${MOREFEM_INSTALL_DIR}/lib")

# add the automatically determined parts of the RPATH
# which point to directories outside the build tree to the install RPATH
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH True)

165

166 167 168
######################################################
# Walk through Sources directory to find all sources to build.
######################################################
169
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/Sources)
170
      
171 172