MoReFEMSettings.cmake 5.91 KB
Newer Older
1 2 3

message(STATUS "C compiler identifier found to be ${CMAKE_C_COMPILER_ID}; settings (warnings, STL, etc...) will be set accordingly.")

4 5 6 7 8 9 10 11 12 13 14 15

# 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")
endif()

# All --all_load in target_link_libraries of executables if STATIC library are chosen.
16

17
if(LIBRARY_TYPE MATCHES STATIC)
18 19 20 21 22 23 24 25
    if (APPLE)
        set(ALL_LOAD_BEGIN_FLAG "")
        set(ALL_LOAD_END_FLAG "-all_load")

    else()        
        set(ALL_LOAD_BEGIN_FLAG "-Wl,--whole-archive")
        set(ALL_LOAD_END_FLAG "-Wl,--no-whole-archive")
    endif()
26
else()
27 28
    set(ALL_LOAD_BEGIN_FLAG "")
    set(ALL_LOAD_END_FLAG "")
29 30 31 32 33 34 35 36 37
endif()

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


if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)# Add LTO support in non debug mode.
    set(PETSC_SPECIFIC_INCL_DIR ${PETSC_DEBUG_INCL_DIR} )
    set(PETSC_SPECIFIC_LIB_DIR ${PETSC_DEBUG_LIB_DIR} )
38 39 40
    set(BOOST_INCL_DIR ${BOOST_DEBUG_INCL_DIR} )
    set(BOOST_LIB_DIR ${BOOST_DEBUG_LIB_DIR} )    
    add_definitions(-DSELDON_CHECK_BOUNDS -DSELDON_CHECK_DIMENSIONS -DDEBUG=1)    
41 42 43 44
else()
    set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
    set(PETSC_SPECIFIC_INCL_DIR ${PETSC_RELEASE_INCL_DIR} )   
    set(PETSC_SPECIFIC_LIB_DIR ${PETSC_RELEASE_LIB_DIR} ) 
45 46
    set(BOOST_INCL_DIR ${BOOST_RELEASE_INCL_DIR} )   
    set(BOOST_LIB_DIR ${BOOST_RELEASE_LIB_DIR} )     
47 48 49 50 51 52
endif()        
 
add_definitions(-DSELDON_WITH_LAPACK -DSELDON_WITH_BLAS -DSELDON_WITH_COMPILED_LIBRARY)



53 54 55 56 57 58 59 60 61 62
if(${CMAKE_C_COMPILER_ID} STREQUAL "AppleClang" OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
    add_cxx_compiler_flag("-Weverything")
    add_cxx_compiler_flag("-Wno-c++98-compat")
    add_cxx_compiler_flag("-Wno-c++98-compat-pedantic")
    add_cxx_compiler_flag("-Wno-padded")
    add_cxx_compiler_flag("-Wno-exit-time-destructors")
    add_cxx_compiler_flag("-Wno-global-constructors")
    add_cxx_compiler_flag("-Wno-documentation")
    add_cxx_compiler_flag("-Wno-documentation-unknown-command")
    add_cxx_compiler_flag("-Wno-undefined-func-template")
63
    add_cxx_compiler_flag("-Wno-c++1z-extensions")
GILLES Sebastien's avatar
GILLES Sebastien committed
64
    
65
    if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
66
        add_definitions(-D_LIBCPP_DEBUG2=0) # Additional checks such as index out of bounds in vectors in libc++; might 
67 68 69
                                            # be removed at any point from libc++.
    endif()
    
70 71
    # Convenient macro to tag LLVM clang; useful as some warnings needs to be suppressed only for this more recent version of clang.
    if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
GILLES Sebastien's avatar
GILLES Sebastien committed
72
        add_cxx_compiler_flag("-Wno-unused-template")
73 74 75
        add_definitions(-DMOREFEM_LLVM_CLANG)
    endif()
    
76 77 78
    # GOMP is required when sanitizer is used for gcc, but is not known is macOS hence this variable.
    set(MOREFEM_GOMP_DEPENDENCY "")
    
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
elseif(${CMAKE_C_COMPILER_ID} STREQUAL "GNU")    
    add_cxx_compiler_flag("-Wall")
    add_cxx_compiler_flag("-Wextra")
    #add_cxx_compiler_flag("-Wpedantic") Can't be activated because of third-party error; pragma doesn't work to disable it only for third party.
    add_cxx_compiler_flag("-Wcast-align")
    add_cxx_compiler_flag("-Wcast-qual")
    add_cxx_compiler_flag("-Wconversion")
    add_cxx_compiler_flag("-Wdisabled-optimization")
    add_cxx_compiler_flag("-Wfloat-equal")
    add_cxx_compiler_flag("-Wformat=2")
    add_cxx_compiler_flag("-Wformat-nonliteral")
    add_cxx_compiler_flag("-Wformat-security")
    add_cxx_compiler_flag("-Wformat-y2k")
    add_cxx_compiler_flag("-Wimport")
    add_cxx_compiler_flag("-Winit-self")
    # add_cxx_compiler_flag("-Winline") Tag destructor defined with = default as inline...
    add_cxx_compiler_flag("-Winvalid-pch")
    add_cxx_compiler_flag("-Wmissing-field-initializers")
    add_cxx_compiler_flag("-Wmissing-format-attribute")
    add_cxx_compiler_flag("-Wmissing-include-dirs")
99
#    add_cxx_compiler_flag("-Wmissing-noreturn") False positive...
100 101 102 103 104 105 106 107 108 109 110 111
    add_cxx_compiler_flag("-Wpacked")
    add_cxx_compiler_flag("-Wpointer-arith")
    add_cxx_compiler_flag("-Wredundant-decls")
    # add_cxx_compiler_flag("-Wshadow") g++ shadow is too cumbersome: can't name function argument same as a method for instance...
    add_cxx_compiler_flag("-Wstack-protector")
    add_cxx_compiler_flag("-Wstrict-aliasing=2")
    add_cxx_compiler_flag("-Wswitch-enum")
    add_cxx_compiler_flag("-Wunreachable-code")
    add_cxx_compiler_flag("-Wunused")
    add_cxx_compiler_flag("-Wunused-parameter")
    add_cxx_compiler_flag("-Wvariadic-macros")
    add_cxx_compiler_flag("-Wwrite-strings")
112 113 114 115
    
    # GOMP is required when sanitizer is used for gcc, but is not known is macOS hence this variable.
    set(MOREFEM_GOMP_DEPENDENCY "-lgomp")
    
116 117 118 119
else()
    message(FATAL_ERROR "Sorry, your compiler family wasn't recognized. If CMake has updated its flag, please modify the cmake/Compiler.cmake file in MoReFEM accoerdingly. See CMAKE_LANG_COMPILER_ID in CMake tutorial to find out the valid options.")
endif()

120

121
set(MOREFEM_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/MoReFEM)
122 123 124 125 126

set(MOREFEM_INSTALL_DIR_EXE ${MOREFEM_INSTALL_DIR}/bin)
set(MOREFEM_INSTALL_DIR_LIB ${MOREFEM_INSTALL_DIR}/lib)
set(MOREFEM_INSTALL_DIR_INCL ${MOREFEM_INSTALL_DIR}/include)
set(MOREFEM_INSTALL_DIR_CMAKE ${MOREFEM_INSTALL_DIR}/cmake)
127 128 129 130 131 132

if (BUILD_MOREFEM_UNIQUE_LIBRARY)
    set(MOREFEM_MAIN_LIBS MoReFEM)
else()
    set(MOREFEM_MAIN_LIBS MoReFEM_utilities MoReFEM_core MoReFEM_geometry MoReFEM_felt MoReFEM_param MoReFEM_op MoReFEM_param_instances MoReFEM_op_instances MoReFEM_formulation_solver MoReFEM_model)
endif()