CMakeLists.txt 10 KB
Newer Older
gsell's avatar
gsell committed
1
cmake_minimum_required (VERSION 3.1)
gsell's avatar
gsell committed
2
project (OPAL VERSION 2.1.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 10
message (PACKAGE_VERSION=${PACKAGE_VERSION})

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
gsell's avatar
gsell committed
15
	)
gsell's avatar
gsell committed
16
endif ()
17

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

gsell's avatar
gsell committed
20 21 22
message ("Build type is: " ${CMAKE_BUILD_TYPE})
message ("Host OS System: ${CMAKE_HOST_SYSTEM}")
message ("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 ("The C++ compiler identification is: ${CMAKE_CXX_COMPILER_ID}")
message ("The C++ compiler version is: ${CMAKE_CXX_COMPILER_VERSION}")
message ("The MPI C++ compiler is: ${MPI_CXX_COMPILER}")
message ("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)

gsell's avatar
gsell committed
44
add_definitions (-DNOCTAssert)
45

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

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

54 55 56
option (USE_STATIC_LIBRARIES "Link with static libraries if available" ON)
if (NOT ${USE_STATIC_LIBRARIES})
    add_compile_options (-fPIE -fPIC)
57
    add_link_options (-pie)
58
endif ()
59

60
# compiler dependent flags
adelmann's avatar
adelmann committed
61
message ("The underlying C++ compiler ID is: ${CMAKE_CXX_COMPILER_ID}")
62
if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
63
    add_compile_options ("-diag-disable 383")
adelmann's avatar
adelmann committed
64
    add_compile_options ("-diag-disable 981")
frey_m's avatar
frey_m committed
65
    if (ENABLE_OpenMP)
66 67
	add_compile_options (-openmp)
    endif ()
68

69
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
70
    add_compile_options (-Warray-bounds-pointer-arithmetic)
71 72
    # Increase template depth for boost
    add_compile_options (-ftemplate-depth=1024)
73 74
    # get rid of linking warning with boost. Looks like that boost
    # is using this visibility setting.
gsell's avatar
gsell committed
75 76
    add_compile_options (-fvisibility=hidden)
    add_compile_options (-fvisibility-inlines-hidden)
77
    # Allow overloaded virtual functions (instances to be fixed in OPAL)
78
    #add_compile_options (-Wno-overloaded-virtual)
frey_m's avatar
frey_m committed
79
    if (ENABLE_OpenMP)
80
	add_compile_options (-fopenmp)
81
    endif ()
82 83
    # Not 100% clear why we need this. But without we get warning while
    # linking with HDF5
gsell's avatar
gsell committed
84
    add_link_options (-Wl,-no_compact_unwind)
frey_m's avatar
frey_m committed
85

86
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
87
    if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "4.7.3")
88
        message (FATAL_ERROR "To build OPAL you need GCC version 4.7.3 or greater")
89
    endif ()
90
    # Warning flags, -Wno-unused-local-typedefs is needed for boost versions below 1.59
91
    add_compile_options (-Wno-unused-local-typedefs -Werror=unused-variable)
92

frey_m's avatar
frey_m committed
93
    if (ENABLE_OpenMP)
94 95
        add_compile_options (-fopenmp)
    endif ()
frey_m's avatar
frey_m committed
96

97
else ()
gsell's avatar
gsell committed
98
    message ("Unknown C++ compiler. Please use the GNU or Intel compiler, if you are having problems.")
99 100
endif ()

101
enable_language (Fortran OPTIONAL)
102
message ("Fortran compilers: ${CMAKE_Fortran_COMPILER_NAMES}")
103
if (CMAKE_Fortran_COMPILER)
104 105 106
    message ("The Fortran compiler identification is: ${CMAKE_Fortran_COMPILER_ID}")
    message ("The Fortran compiler version is: ${CMAKE_Fortran_COMPILER_VERSION}")
    message ("The Fortran compiler is: ${CMAKE_Fortran_COMPILER}")
107 108 109 110
    if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
        set (Fortran_LIBS "-lgfortran")
    endif ()
else ()
111
    message ("No Fortran compiler found (optional)")
112
    if (ENABLE_AMR)
113
	message (FATAL_ERROR "AMR is enabled but no Fortran compiler found!")
114
    endif ()
gsell's avatar
gsell committed
115
endif ()
116

117
find_package (H5Hut REQUIRED)
gsell's avatar
gsell committed
118

119 120 121
if (USE_STATIC_LIBRARIES)
    set (HDF5_USE_STATIC_LIBRARIES ON)
endif ()
122 123
find_package (HDF5 REQUIRED)
message ("Found HDF5 libraries: ${HDF5_C_LIBRARIES}")
gsell's avatar
gsell committed
124

125 126
find_package (GSL REQUIRED)
message ("Found gsl libraries: ${GSL_LIBRARIES}")
127

gsell's avatar
gsell committed
128
set (BOOSTROOT $ENV{BOOST_DIR})
129 130 131
if (USE_STATIC_LIBRARIES)
    set (Boost_USE_STATIC_LIBS ON)
endif ()
132 133
set (Boost_USE_MULTITHREADED OFF)
set (Boost_USE_STATIC_RUNTIME OFF)
134
find_package (Boost 1.60.0
135
    REQUIRED COMPONENTS chrono filesystem iostreams regex serialization system timer)
136 137 138
message ("Found Boost include dir: ${Boost_INCLUDE_DIR}")
message ("Found Boost library dir: ${Boost_LIBRARY_DIR}")
message ("Found Boost libraries: ${Boost_LIBRARIES}")
139
include_directories (SYSTEM ${Boost_INCLUDE_DIRS})
140

gsell's avatar
gsell committed
141 142
option (ENABLE_DKS "Enable DKS" OFF)
if (ENABLE_DKS)
gsell's avatar
gsell committed
143
    find_package (DKS 1.1.1 REQUIRED HINTS $ENV{DKS_PREFIX} $ENV{DKS_DIR} $ENV{DKS})
gsell's avatar
gsell committed
144
    set (DKS_VERSION_OPAL \"${DKS_VERSION}\")
gsell's avatar
gsell committed
145 146 147
    message ("Found DKS version: ${DKS_VERSION}")
    message ("Found DKS library: ${DKS_LIBRARY}")
    message ("Found DKS include dir: ${DKS_INCLUDE_DIR}")
148
    add_definitions(-DDKS_MPI)
149

gsell's avatar
gsell committed
150
    ### OpenCL compiler flags ###
gsell's avatar
gsell committed
151
    #add_compile_options (-lOpenCL -pthread -DDKS_OPENCL)
152

gsell's avatar
gsell committed
153
    ### CUDA compiler flags ###
154
    add_definitions(-DDKS_CUDA)
155

gsell's avatar
gsell committed
156
    ### if any accelerator enabled set flag to use DKS ###
157
    add_definitions(-DIPPL_DKS -DIPPL_DKS_CUDA -DOPAL_DKS)
158

gsell's avatar
gsell committed
159
endif ()
160

gsell's avatar
gsell committed
161 162 163 164
# 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
165
    add_definitions (-DWITH_UNIT_TESTS)
gsell's avatar
gsell committed
166
endif ()
167

gsell's avatar
gsell committed
168
option (ENABLE_AMR "Enable AMReX based AMR solver" OFF)
169
if (ENABLE_AMR)
gsell's avatar
gsell committed
170 171
    message ("Enable AMR_SOLVER    " ${ENABLE_AMR})
    enable_language (Fortran)
172

gsell's avatar
gsell committed
173 174
    find_package (AMReX CONFIG REQUIRED
        HINTS $ENV{AMREX_HOME}/cmake $ENV{AMREX_DIR}/cmake $ENV{AMREX_PREFIX}/cmake)
175

gsell's avatar
gsell committed
176 177 178 179
    message ("Found AMReX include dir: ${AMREX_INCLUDE_DIR}")
    message ("Found AMReX library dir: ${AMREX_LIBRARY_DIR}")
    message ("Found AMReX libraries: ${AMREX_LIBRARIES}")
    message ("Found AMReX Fortran links: ${AMREX_EXTRA_Fortran_LINK_LINE}")
180
    echo_amrex_config_options()
181

182
    add_definitions(${AMREX_DEFINES})
183
    add_definitions(-DENABLE_AMR)
gsell's avatar
gsell committed
184
endif ()
frey_m's avatar
frey_m committed
185

gsell's avatar
gsell committed
186 187
option (ENABLE_AMR_MG_SOLVER "Enable AMR MG solver" OFF)
option (ENABLE_SAAMG_SOLVER "Enable iteartive SA-AMG-PCG self field solver" OFF)
gsell's avatar
gsell committed
188 189 190 191 192 193 194 195
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.
    message ("Enable SAAMG_SOLVER: " ${ENABLE_SAAMG_SOLVER})
    message ("Enable AMR_MG_SOLVER: " ${ENABLE_AMR_MG_SOLVER})
196

gsell's avatar
gsell committed
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217
    find_package (Trilinos REQUIRED HINTS $ENV{TRILINOS_PREFIX} $ENV{TRILINOS_DIR} $ENV{TRILINOS})

    message ("Found Trilinos: ${Trilinos_DIR}")
    message ("      Trilinos version: ${Trilinos_VERSION}")
    message ("      Trilinos package list: ${Trilinos_PACKAGE_LIST}")
    message ("      Trilinos libraries: ${Trilinos_LIBRARIES}")
    message ("      Trilinos TPL libraries: ${Trilinos_TPL_LIBRARIES}")

    if (NOT ${MPI_CXX_COMPILER} STREQUAL ${Trilinos_CXX_COMPILER} )
        message ("Compiler mismatch:")
        message ("        Trilinos was compiled with:")
        message ("            ${Trilinos_C_COMPILER}")
        message ("            ${Trilinos_CXX_COMPILER}")
        message ("            ${Trilinos_Fortran_COMPILER}")
        message ("        You are using:")
        message ("            ${CMAKE_C_COMPILER}")
        message ("            ${CMAKE_CXX_COMPILER}")
        message ("            ${CMAKE_Fortran_COMPILER}")
        message (FATAL_ERROR  "")
    endif ()
endif ()
frey_m's avatar
frey_m committed
218

219 220 221 222 223 224 225
option (ENABLE_OPAL_FEL "Enable OPAL FEL" OFF)
if (ENABLE_OPAL_FEL)
    message ("Enable OPAL FEL: " ${ENABLE_OPAL_FEL})
    find_package (MITHRA MODULE REQUIRED)
    add_DEFINITIONS (-DOPAL_FEL)
endif()

gsell's avatar
gsell committed
226 227 228 229 230
option (DBG_SCALARFIELD "Enable dump of scalar field rho_m" OFF)
if (DBG_SCALARFIELD)
    message ("\nWrite scalar rho_m field is enabled ")
    add_DEFINITIONS (-DDBG_SCALARFIELD)
endif ()
231

gsell's avatar
gsell committed
232 233
option (DBG_STENCIL "Dump stencil of iterative solver in matlab format" OFF)
if (DBG_STENCIL)
234
    MESSAGE ("\nWrite stencil is enabled ")
235
    ADD_DEFINITIONS(-DDBG_STENCIL)
gsell's avatar
gsell committed
236
endif ()
237

gsell's avatar
gsell committed
238 239
option (NO_FIELD_ASSIGN_OPTIMIZATION "Disable compiler optimization of IPPL field assignment" OFF)
if (NO_FIELD_ASSIGN_OPTIMIZATION)
240
    MESSAGE ("\nCompiler will not try to optimize field assignment")
241
    ADD_DEFINITIONS(-DdontOPTIMIZE_FIELD_ASSIGNMENT)
gsell's avatar
gsell committed
242
endif ()
gsell's avatar
gsell committed
243

244 245
option (ENABLE_DOXYDOC "compile Doxygen documentation" OFF)

gsell's avatar
gsell committed
246 247 248 249
include (FindGit)
if (GIT_FOUND)
    set (OPAL_WC_REVISION 0)
    execute_PROCESS(
kraus's avatar
kraus committed
250 251 252
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        COMMAND git rev-parse HEAD
        OUTPUT_VARIABLE GIT_OUT OUTPUT_STRIP_TRAILING_WHITESPACE
gsell's avatar
gsell committed
253
        )
gsell's avatar
gsell committed
254 255 256 257 258
    set (OPAL_WC_REVISION \"${GIT_OUT}\")
else ()
    message ("could not find git")
    set (OPAL_WC_REVISION \"\")
endif ()
kraus's avatar
kraus committed
259

gsell's avatar
gsell committed
260 261 262 263
add_subdirectory (ippl)
add_subdirectory (optimizer)
add_subdirectory (src)
add_subdirectory (tools)
264

gsell's avatar
gsell committed
265 266 267
if (BUILD_OPAL_UNIT_TESTS)
    add_subdirectory (tests)
endif ()
268

269
# make variables visible in other CMakeLists files
gsell's avatar
gsell committed
270
set (OPAL_CXX_FLAGS ${OPAL_CXX_FLAGS}
gsell's avatar
gsell committed
271 272
    CACHE INTERNAL "" FORCE
    )
gsell's avatar
gsell committed
273
set (OPAL_LIBS ${OPAL_LIBS}
gsell's avatar
gsell committed
274 275
    CACHE INTERNAL "" FORCE
    )
276 277 278

# configure file
configure_file (
gsell's avatar
gsell committed
279 280 281
    ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config_install.cmake
    )
282 283

install (
gsell's avatar
gsell committed
284 285 286 287
    FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config_install.cmake
    DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME}"
    RENAME ${PROJECT_NAME}Config.cmake
    )
gsell's avatar
gsell committed
288
  
gsell's avatar
gsell committed
289
# vi: set et ts=4 sw=4 sts=4:
gsell's avatar
gsell committed
290
  
gsell's avatar
gsell committed
291
# Local Variables:
gsell's avatar
gsell committed
292
# mode: cmake
gsell's avatar
gsell committed
293
# cmake-tab-width: 4
gsell's avatar
gsell committed
294
# indent-tabs-mode: nil
295
# require-final-newline: nil
296
# End: