CMakeLists.txt 9.82 KB
Newer Older
gsell's avatar
gsell committed
1
cmake_minimum_required (VERSION 3.1)
2
project (OPAL VERSION 2.3.0)
3 4 5
set (PROJECT_BUGREPORT opal@lists.psi.ch)

string (REGEX REPLACE "\\.([0-9])\\." ".0\\1." PACKAGE_VERSION ${PROJECT_VERSION})
gsell's avatar
gsell committed
6 7
string (REGEX REPLACE "\\.([0-9])$" ".0\\1" PACKAGE_VERSION ${PACKAGE_VERSION})
string (REGEX REPLACE "\\." "" PACKAGE_VERSION ${PACKAGE_VERSION})
gsell's avatar
gsell committed
8

9
message (STATUS PACKAGE_VERSION=${PACKAGE_VERSION})
10

gsell's avatar
gsell committed
11
if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
12
    set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
13 14
        "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
        FORCE
15
        )
gsell's avatar
gsell committed
16
endif ()
17

gsell's avatar
gsell committed
18
cmake_host_system_information (RESULT HOSTNAME QUERY HOSTNAME)
19

20 21 22
message (STATUS "Build type is: " ${CMAKE_BUILD_TYPE})
message (STATUS "Host OS System: ${CMAKE_HOST_SYSTEM}")
message (STATUS "Hostname: ${HOSTNAME}")
23

24
# Select flags.
gsell's avatar
gsell committed
25 26 27
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g ")
set (CMAKE_CXX_FLAGS_RELEASE "-O3")
set (CMAKE_CXX_FLAGS_DEBUG  "-O0 -g")
gsell's avatar
gsell committed
28

29
# Resolve all library dependencies
gsell's avatar
gsell committed
30
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules")
31

32
find_package (MPI REQUIRED)
33 34 35 36
message (STATUS "The C++ compiler identification is: ${CMAKE_CXX_COMPILER_ID}")
message (STATUS "The C++ compiler version is: ${CMAKE_CXX_COMPILER_VERSION}")
message (STATUS "The MPI C++ compiler is: ${MPI_CXX_COMPILER}")
message (STATUS "The underlying C++ compiler is: ${CMAKE_CXX_COMPILER}")
37

gsell's avatar
gsell committed
38
option (ENABLE_OpenMP "Use hybrid parallelism MPI-OpenMP" OFF)
frey_m's avatar
frey_m committed
39

40 41 42 43
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)

44
# Disable compile time assert (used by IPPL)
gsell's avatar
gsell committed
45
add_definitions (-DNOCTAssert)
46

gsell's avatar
gsell committed
47
add_compile_options (-Wall)
48 49
add_compile_options (-Wunused)
add_compile_options (-Wextra)
50
add_compile_options (-Werror)
51 52 53

add_compile_options (-funroll-loops)
add_compile_options (-fstrict-aliasing)
gsell's avatar
gsell committed
54

55 56 57 58 59
# An error in Trilinos/12.18.1 causes
# -Waggressive-loop-optimizations with -O3 optimization.
# See issue 587 and corresponding merge request 415.
add_compile_options (-fno-aggressive-loop-optimizations)

60 61 62
option (USE_STATIC_LIBRARIES "Link with static libraries if available" ON)
if (NOT ${USE_STATIC_LIBRARIES})
    add_compile_options (-fPIE -fPIC)
63
    add_link_options (-pie)
64
endif ()
65

66
# compiler dependent flags
67
message (STATUS "The underlying C++ compiler ID is: ${CMAKE_CXX_COMPILER_ID}")
68
if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
69
    add_compile_options ("-diag-disable 383")
adelmann's avatar
adelmann committed
70
    add_compile_options ("-diag-disable 981")
frey_m's avatar
frey_m committed
71
    if (ENABLE_OpenMP)
gsell's avatar
gsell committed
72
        add_compile_options (-openmp)
73
        add_link_options (-openmp)
74
    endif ()
75

76
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
77
    add_compile_options (-Warray-bounds-pointer-arithmetic)
78 79
    # Increase template depth for boost
    add_compile_options (-ftemplate-depth=1024)
80 81
    # get rid of linking warning with boost. Looks like that boost
    # is using this visibility setting.
gsell's avatar
gsell committed
82 83
    add_compile_options (-fvisibility=hidden)
    add_compile_options (-fvisibility-inlines-hidden)
84
    # Allow overloaded virtual functions (instances to be fixed in OPAL)
85
    #add_compile_options (-Wno-overloaded-virtual)
frey_m's avatar
frey_m committed
86
    if (ENABLE_OpenMP)
gsell's avatar
gsell committed
87
        add_compile_options (-fopenmp)
88
        add_link_options (-fopenmp)
89
    endif ()
frey_m's avatar
frey_m committed
90

91
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
92
    if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "4.7.3")
93
        message (FATAL_ERROR "To build OPAL you need GCC version 4.7.3 or greater")
94
    endif ()
95
    # Warning flags
96

frey_m's avatar
frey_m committed
97
    if (ENABLE_OpenMP)
gsell's avatar
gsell committed
98
        add_compile_options (-fopenmp)
99
        add_link_options (-fopenmp)
100
    endif ()
frey_m's avatar
frey_m committed
101

102
else ()
103
    message (STATUS "Unknown C++ compiler. Please use the GNU or Intel compiler, if you are having problems.")
104 105
endif ()

106
enable_language (Fortran OPTIONAL)
107
message (STATUS "Fortran compilers: ${CMAKE_Fortran_COMPILER_NAMES}")
108
if (CMAKE_Fortran_COMPILER)
109 110 111
    message (STATUS "The Fortran compiler identification is: ${CMAKE_Fortran_COMPILER_ID}")
    message (STATUS "The Fortran compiler version is: ${CMAKE_Fortran_COMPILER_VERSION}")
    message (STATUS "The Fortran compiler is: ${CMAKE_Fortran_COMPILER}")
112 113 114
    if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
        set (Fortran_LIBS "-lgfortran")
    endif ()
115 116 117
    # CMake issue. Missing library libmpi_mpifh in MPI_Fortran_LINRARIES.
    # See issue 587 and corresponding merge request 415.
    set (Fortran_LIBS "${Fortran_LIBS} -lmpi_mpifh")
118
else ()
119
    message (STATUS "No Fortran compiler found (optional)")
120
    if (ENABLE_AMR)
121
        message (FATAL_ERROR "AMR is enabled but no Fortran compiler found!")
122
    endif ()
gsell's avatar
gsell committed
123
endif ()
124

125
find_package (H5Hut REQUIRED)
gsell's avatar
gsell committed
126

127 128 129
if (USE_STATIC_LIBRARIES)
    set (HDF5_USE_STATIC_LIBRARIES ON)
endif ()
130
find_package (HDF5 REQUIRED)
131
message (STATUS "Found HDF5 libraries: ${HDF5_C_LIBRARIES}")
gsell's avatar
gsell committed
132

133
find_package (GSL REQUIRED)
134
message (STATUS "Found gsl libraries: ${GSL_LIBRARIES}")
135

gsell's avatar
gsell committed
136
set (BOOSTROOT $ENV{BOOST_DIR})
137 138 139
if (USE_STATIC_LIBRARIES)
    set (Boost_USE_STATIC_LIBS ON)
endif ()
140 141
set (Boost_USE_MULTITHREADED OFF)
set (Boost_USE_STATIC_RUNTIME OFF)
142
find_package (Boost 1.66.0
143
    REQUIRED COMPONENTS chrono filesystem iostreams regex serialization system timer)
144 145 146
message (STATUS "Found Boost include dir: ${Boost_INCLUDE_DIR}")
message (STATUS "Found Boost library dir: ${Boost_LIBRARY_DIR}")
message (STATUS "Found Boost libraries: ${Boost_LIBRARIES}")
147
include_directories (SYSTEM ${Boost_INCLUDE_DIRS})
148

gsell's avatar
gsell committed
149 150 151 152
# Handle options
option (BUILD_OPAL_UNIT_TESTS "Unit tests" OFF)
if (BUILD_OPAL_UNIT_TESTS)
    find_package (GTest REQUIRED HINT $ENV{GTEST_PREFIX})
gsell's avatar
gsell committed
153
    add_definitions (-DWITH_UNIT_TESTS)
gsell's avatar
gsell committed
154
endif ()
155

gsell's avatar
gsell committed
156
option (ENABLE_AMR "Enable AMReX based AMR solver" OFF)
157
if (ENABLE_AMR)
158
    message (STATUS "Enable AMR_SOLVER    " ${ENABLE_AMR})
gsell's avatar
gsell committed
159
    enable_language (Fortran)
160

gsell's avatar
gsell committed
161 162
    find_package (AMReX CONFIG REQUIRED
        HINTS $ENV{AMREX_HOME}/cmake $ENV{AMREX_DIR}/cmake $ENV{AMREX_PREFIX}/cmake)
163

164 165 166 167
    message (STATUS "Found AMReX include dir: ${AMREX_INCLUDE_DIR}")
    message (STATUS "Found AMReX library dir: ${AMREX_LIBRARY_DIR}")
    message (STATUS "Found AMReX libraries: ${AMREX_LIBRARIES}")
    message (STATUS "Found AMReX Fortran links: ${AMREX_EXTRA_Fortran_LINK_LINE}")
168
    echo_amrex_config_options()
169

170
    add_definitions(${AMREX_DEFINES})
171
    add_definitions(-DENABLE_AMR)
gsell's avatar
gsell committed
172
endif ()
frey_m's avatar
frey_m committed
173

gsell's avatar
gsell committed
174
option (ENABLE_AMR_MG_SOLVER "Enable AMR MG solver" OFF)
175
option (ENABLE_SAAMG_SOLVER "Enable iterative SA-AMG-PCG self field solver" OFF)
gsell's avatar
gsell committed
176 177 178 179 180 181
if (ENABLE_SAAMG_SOLVER OR ENABLE_AMR_MG_SOLVER)
    #
    # :FIXME: We have to add checks whether the required Trilinos modules
    #         are available. If there are problems of any kind with this
    #         configuration, either fix it in a general way or build your
    #         Trilinos. Host specific should be avoided in almost any case.
182 183
    message (STATUS "Enable SAAMG_SOLVER: " ${ENABLE_SAAMG_SOLVER})
    message (STATUS "Enable AMR_MG_SOLVER: " ${ENABLE_AMR_MG_SOLVER})
184

gsell's avatar
gsell committed
185 186
    find_package (Trilinos REQUIRED HINTS $ENV{TRILINOS_PREFIX} $ENV{TRILINOS_DIR} $ENV{TRILINOS})

187 188 189 190 191
    message (STATUS "Found Trilinos: ${Trilinos_DIR}")
    message (STATUS "      Trilinos version: ${Trilinos_VERSION}")
    message (STATUS "      Trilinos package list: ${Trilinos_PACKAGE_LIST}")
    message (STATUS "      Trilinos libraries: ${Trilinos_LIBRARIES}")
    message (STATUS "      Trilinos TPL libraries: ${Trilinos_TPL_LIBRARIES}")
gsell's avatar
gsell committed
192 193

    if (NOT ${MPI_CXX_COMPILER} STREQUAL ${Trilinos_CXX_COMPILER} )
194 195 196 197 198 199 200 201 202
        message (WARNING "Compiler mismatch:")
        message (WARNING "        Trilinos was compiled with:")
        message (WARNING "            ${Trilinos_C_COMPILER}")
        message (WARNING "            ${Trilinos_CXX_COMPILER}")
        message (WARNING "            ${Trilinos_Fortran_COMPILER}")
        message (WARNING "        You are using:")
        message (WARNING "            ${CMAKE_C_COMPILER}")
        message (WARNING "            ${CMAKE_CXX_COMPILER}")
        message (WARNING "            ${CMAKE_Fortran_COMPILER}")
gsell's avatar
gsell committed
203 204 205
        message (FATAL_ERROR  "")
    endif ()
endif ()
frey_m's avatar
frey_m committed
206

207 208
option (ENABLE_OPAL_FEL "Enable OPAL FEL" OFF)
if (ENABLE_OPAL_FEL)
209
    message (STATUS "Enable OPAL FEL: " ${ENABLE_OPAL_FEL})
210
    find_package (MITHRA MODULE REQUIRED)
211
    add_definitions (-DOPAL_FEL)
212 213
endif()

gsell's avatar
gsell committed
214 215
option (DBG_SCALARFIELD "Enable dump of scalar field rho_m" OFF)
if (DBG_SCALARFIELD)
216 217
    message (STATUS "Write scalar rho_m field is enabled ")
    add_definitions (-DDBG_SCALARFIELD)
gsell's avatar
gsell committed
218
endif ()
219

gsell's avatar
gsell committed
220 221
option (DBG_STENCIL "Dump stencil of iterative solver in matlab format" OFF)
if (DBG_STENCIL)
222 223
    message (STATUS "Write stencil is enabled ")
    add_definitions(-DDBG_STENCIL)
gsell's avatar
gsell committed
224
endif ()
225

gsell's avatar
gsell committed
226 227
option (NO_FIELD_ASSIGN_OPTIMIZATION "Disable compiler optimization of IPPL field assignment" OFF)
if (NO_FIELD_ASSIGN_OPTIMIZATION)
228 229
    message (STATUS "Compiler will not try to optimize field assignment")
    add_definitions(-DdontOPTIMIZE_FIELD_ASSIGNMENT)
gsell's avatar
gsell committed
230
endif ()
gsell's avatar
gsell committed
231

232 233
option (ENABLE_DOXYDOC "compile Doxygen documentation" OFF)

gsell's avatar
gsell committed
234 235 236 237 238 239 240 241 242 243 244 245
add_custom_target(always_rebuild ALL
    DEPENDS
    src/OPALrevision.h
    )

add_custom_command(
    OUTPUT src/OPALrevision.h
    COMMAND ./gen_OPALrevision
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
    DEPENDS
    always_rebuild
    )
kraus's avatar
kraus committed
246

gsell's avatar
gsell committed
247 248 249 250
add_subdirectory (ippl)
add_subdirectory (optimizer)
add_subdirectory (src)
add_subdirectory (tools)
251

gsell's avatar
gsell committed
252 253 254
if (BUILD_OPAL_UNIT_TESTS)
    add_subdirectory (tests)
endif ()
255

256
# make variables visible in other CMakeLists files
gsell's avatar
gsell committed
257
set (OPAL_CXX_FLAGS ${OPAL_CXX_FLAGS}
gsell's avatar
gsell committed
258 259
    CACHE INTERNAL "" FORCE
    )
gsell's avatar
gsell committed
260
set (OPAL_LIBS ${OPAL_LIBS}
gsell's avatar
gsell committed
261 262
    CACHE INTERNAL "" FORCE
    )
263 264 265

# configure file
configure_file (
gsell's avatar
gsell committed
266 267 268
    ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config_install.cmake
    )
269 270

install (
gsell's avatar
gsell committed
271 272 273 274
    FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config_install.cmake
    DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME}"
    RENAME ${PROJECT_NAME}Config.cmake
    )
275

gsell's avatar
gsell committed
276
# vi: set et ts=4 sw=4 sts=4:
277

gsell's avatar
gsell committed
278
# Local Variables:
gsell's avatar
gsell committed
279
# mode: cmake
gsell's avatar
gsell committed
280
# cmake-tab-width: 4
gsell's avatar
gsell committed
281
# indent-tabs-mode: nil
282
# require-final-newline: nil
283
# End: