CMakeLists.txt 11.7 KB
Newer Older
gsell's avatar
gsell committed
1
cmake_minimum_required (VERSION 3.1)
gsell's avatar
gsell committed
2 3
project (OPAL)
set (OPAL_VERSION_MAJOR 1)
gsell's avatar
gsell committed
4
SET (OPAL_VERSION_MINOR 9.0)
5 6 7 8
set (PACKAGE \"opal\")
set (PACKAGE_BUGREPORT \"opal@lists.psi.ch\")
set (PACKAGE_NAME \"OPAL\")
set (PACKAGE_TARNAME \"opal\")
9
set (PACKAGE_VERSION "${OPAL_VERSION_MAJOR}.${OPAL_VERSION_MINOR}")
10
set (PACKAGE_VERSION_STR "\"${PACKAGE_VERSION}\"")
gsell's avatar
gsell committed
11 12 13
string (REGEX REPLACE "\\.([0-9])\\." ".0\\1." PACKAGE_VERSION ${PACKAGE_VERSION})
string (REGEX REPLACE "\\.([0-9])$" ".0\\1" PACKAGE_VERSION ${PACKAGE_VERSION})
string (REGEX REPLACE "\\." "" PACKAGE_VERSION ${PACKAGE_VERSION})
gsell's avatar
gsell committed
14

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

gsell's avatar
gsell committed
22
cmake_host_system_information (RESULT HOSTNAME QUERY HOSTNAME)
23

gsell's avatar
gsell committed
24 25 26
message ("Build type is: " ${CMAKE_BUILD_TYPE})
message ("Host OS System: ${CMAKE_HOST_SYSTEM}")
message ("Hostname:  ${HOSTNAME}")
27

28
# Select flags.
gsell's avatar
gsell committed
29 30 31
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
32

33
# Resolve all library dependencies
gsell's avatar
gsell committed
34
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules")
35

36
find_package (MPI REQUIRED)
37 38 39 40
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}")
41

frey_m's avatar
frey_m committed
42
OPTION (ENABLE_OpenMP "Use hybrid parallelism MPI-OpenMP" OFF)
frey_m's avatar
frey_m committed
43

44 45 46 47 48 49
set (CMAKE_CXX_STANDARD 11)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)

add_compile_options (-Wall)

50 51
# compiler dependent flags
if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
gsell's avatar
gsell committed
52
    add_compile_options (-diag-disable 383 -diag-disable 981)
frey_m's avatar
frey_m committed
53
    if (ENABLE_OpenMP)
54 55
	add_compile_options (-openmp)
    endif ()
56

57
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
gsell's avatar
gsell committed
58
<<<<<<< HEAD
gsell's avatar
gsell committed
59
    add_compile_options (-Werror -Wsign-compare -Wunused-variable -Warray-bounds -DIPPL_RESTRICT_BUG)
gsell's avatar
gsell committed
60
=======
61 62
    add_compile_options (-Werror -Wsign-compare -Wunused-variable -Warray-bounds)
    add_definitions(-DIPPL_RESTRICT_BUG)
gsell's avatar
gsell committed
63
>>>>>>> 3834e6eef6d61f1c54c3582b66db9e5e060f5178
frey_m's avatar
frey_m committed
64
    if (ENABLE_OpenMP)
65 66
	    add_compile_options (-fopenmp)
    endif ()
frey_m's avatar
frey_m committed
67

68 69
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
    if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "4.7.3")
70
        message (FATAL_ERROR "To build OPAL you need GCC version 4.7.3 or greater")
71
    endif ()
72
    # Warning flags, -Wno-unused-local-typedefs is needed for boost versions below 1.59
73
    add_compile_options (-Wno-unused-local-typedefs -Werror=unused-variable)
74

frey_m's avatar
frey_m committed
75
    if (ENABLE_OpenMP)
76 77
        add_compile_options (-fopenmp)
    endif ()
frey_m's avatar
frey_m committed
78

79
else ()
gsell's avatar
gsell committed
80
    message ("Unknown C++ compiler. Please use the GNU or Intel compiler, if you are having problems.")
81 82
endif ()

83
enable_language (Fortran OPTIONAL)
84
message ("Fortran compilers: ${CMAKE_Fortran_COMPILER_NAMES}")
85
if (CMAKE_Fortran_COMPILER)
86 87 88
    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}")
89 90 91 92
    if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
        set (Fortran_LIBS "-lgfortran")
    endif ()
else ()
93
    message ("No Fortran compiler found (optional)")
94
    if (ENABLE_AMR)
95
	message (FATAL_ERROR "AMR is enabled but no Fortran compiler found!")
96 97 98
    endif ()
endif()

99 100 101 102 103 104
find_package (H5Hut REQUIRED)
set (HDF5_USE_STATIC_LIBRARIES ON)
find_package (HDF5 REQUIRED)
message ("Found HDF5 libraries: ${HDF5_C_LIBRARIES}")
find_package (GSL REQUIRED)
message ("Found gsl libraries: ${GSL_LIBRARIES}")
105

gsell's avatar
gsell committed
106
set (BOOSTROOT $ENV{BOOST_DIR})
107 108 109 110
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED OFF)
set (Boost_USE_STATIC_RUNTIME OFF)
find_package (Boost REQUIRED COMPONENTS filesystem system iostreams regex)
111
if (Boost_INCLUDE_DIRS)
112 113 114 115 116 117 118
    if (${Boost_VERSION} VERSION_LESS 106000)
	message (FATAL_ERROR
	       "Found Boost library is to old; required is version 1.60.0 or newer!")
    endif ()
    message ("Found Boost include dir: ${Boost_INCLUDE_DIR}")
    message ("Found Boost library dir: ${Boost_LIBRARY_DIR}")
    message ("Found Boost libraries: ${Boost_LIBRARIES}")
119 120
    include_directories (${Boost_INCLUDE_DIRS})
endif ()
121

gsell's avatar
gsell committed
122 123
option (ENABLE_DKS "Enable DKS" OFF)
if (ENABLE_DKS)
124
    find_package (dKS 1.1.1 REQUIRED HINTS $ENV{DKS_PREFIX} $ENV{DKS_DIR} $ENV{DKS})
gsell's avatar
gsell committed
125
    set (DKS_VERSION_OPAL \"${DKS_VERSION}\")
gsell's avatar
gsell committed
126
<<<<<<< HEAD
gsell's avatar
gsell committed
127 128 129 130
    message ("Found DKS version: ${DKS_VERSION}")
    message ("Found DKS library: ${DKS_LIBRARY}")
    message ("Found DKS include dir: ${DKS_INCLUDE_DIR}")
    add_compile_options (-DDKS_MPI)
gsell's avatar
gsell committed
131
=======
132 133 134
    MESSAGE ("Found DKS version: ${DKS_VERSION}")
    MESSAGE ("Found DKS library: ${DKS_LIBRARY}")
    MESSAGE ("Found DKS include dir: ${DKS_INCLUDE_DIR}")
135
    add_definitions(-DDKS_MPI)
gsell's avatar
gsell committed
136
>>>>>>> 3834e6eef6d61f1c54c3582b66db9e5e060f5178
137

gsell's avatar
gsell committed
138
    ### OpenCL compiler flags ###
gsell's avatar
gsell committed
139
    #add_compile_options (-lOpenCL -pthread -DDKS_OPENCL)
140

gsell's avatar
gsell committed
141
    ### CUDA compiler flags ###
gsell's avatar
gsell committed
142
<<<<<<< HEAD
gsell's avatar
gsell committed
143
    add_compile_options(-DDKS_CUDA)
144

gsell's avatar
gsell committed
145
    ### if any accelerator enabled set flag to use DKS ###
gsell's avatar
gsell committed
146 147
    add_compile_options (-DIPPL_DKS -DIPPL_DKS_CUDA -DOPAL_DKS)
endif ()
gsell's avatar
gsell committed
148
=======
149
    add_definitions(-DDKS_CUDA)
150

gsell's avatar
gsell committed
151
    ### if any accelerator enabled set flag to use DKS ###
152
    add_definitions(-DIPPL_DKS -DIPPL_DKS_CUDA -DOPAL_DKS)
153

154
ENDIF (ENABLE_DKS)
155
### END DKS part ###
156

157
# Handle options
158
OPTION (ENABLE_AMR "Enable AMReX based AMR solver" OFF)
159
OPTION (ENABLE_AMR_MG_SOLVER "Enable AMR MG solver" OFF)
160

161
OPTION (ENABLE_SAAMG_SOLVER "Enable iteartive SA-AMG-PCG self field solver" OFF)
gsell's avatar
gsell committed
162

163 164
OPTION (DBG_SCALARFIELD "Enable dump of scalar field rho_m" OFF)
OPTION (DBG_STENCIL "Dump stencil of iterative solver in matlab format" OFF)
gsell's avatar
gsell committed
165

166
OPTION (NO_FIELD_ASSIGN_OPTIMIZATION "Disable compiler optimization of IPPL field assignment" OFF)
gsell's avatar
gsell committed
167
>>>>>>> 3834e6eef6d61f1c54c3582b66db9e5e060f5178
168

169

gsell's avatar
gsell committed
170
<<<<<<< HEAD
gsell's avatar
gsell committed
171 172 173 174 175 176
# Handle options
option (BUILD_OPAL_UNIT_TESTS "Unit tests" OFF)
if (BUILD_OPAL_UNIT_TESTS)
    find_package (GTest REQUIRED HINT $ENV{GTEST_PREFIX})
    add_compile_options (-DWITH_UNIT_TESTS)
endif ()
gsell's avatar
gsell committed
177
=======
178 179
IF (BUILD_OPAL_UNIT_TESTS)
    FIND_PACKAGE (GTest REQUIRED)
180
    ADD_DEFINITIONS(-DWITH_UNIT_TESTS)
181
ENDIF (BUILD_OPAL_UNIT_TESTS)
gsell's avatar
gsell committed
182
>>>>>>> 3834e6eef6d61f1c54c3582b66db9e5e060f5178
183

gsell's avatar
gsell committed
184
OPTION (ENABLE_AMR "Enable AMReX based AMR solver" OFF)
185
IF (ENABLE_AMR)
186
    MESSAGE ("Enable AMR_SOLVER    " ${ENABLE_AMR})
frey_m's avatar
frey_m committed
187
    ENABLE_LANGUAGE (Fortran)
188

gsell's avatar
gsell committed
189 190
    find_package (AMReX CONFIG REQUIRED
        HINTS $ENV{AMREX_HOME}/cmake $ENV{AMREX_DIR}/cmake $ENV{AMREX_PREFIX}/cmake)
191

192 193 194 195
    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}")
196 197 198
    echo_amrex_config_options()
    
    add_definitions(${AMREX_DEFINES})
199
    add_definitions(-DENABLE_AMR)
200
    
gsell's avatar
gsell committed
201
<<<<<<< HEAD
202
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_AMR")
203
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable -Wno-unused-but-set-variable -Wno-maybe-uninitialized")
204

gsell's avatar
gsell committed
205
ENDIF ()
gsell's avatar
gsell committed
206
=======
207
    add_compile_options (-Wno-unused-variable -Wno-unused-but-set-variable -Wno-maybe-uninitialized)
208
ENDIF (ENABLE_AMR)
gsell's avatar
gsell committed
209

210 211 212 213 214 215 216
# remove digits from hostname: edison03 -> edison
STRING(REGEX MATCH "[^0-9]*" HOSTNAME_BASE "${HOSTNAME}")

# In case of Edison and Cori the find_package(Trilinos) gives the wrong
# Trilinos_TPL_LIBRARIES, instead of cray-tpsl/16.07.1 it uses
# cray-tpsl/16.06.1 libraries -> Linker error.
# We can avoid this issue by not going into the if-statement
frey_m's avatar
frey_m committed
217
IF (ENABLE_SAAMG_SOLVER OR ENABLE_AMR_MG_SOLVER)
gsell's avatar
gsell committed
218
>>>>>>> 3834e6eef6d61f1c54c3582b66db9e5e060f5178
frey_m's avatar
frey_m committed
219

gsell's avatar
gsell committed
220 221 222 223 224 225 226 227 228 229
OPTION (ENABLE_AMR_MG_SOLVER "Enable AMR MG solver" OFF)
OPTION (ENABLE_SAAMG_SOLVER "Enable iteartive SA-AMG-PCG self field solver" OFF)
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})
frey_m's avatar
frey_m committed
230
    
gsell's avatar
gsell committed
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251
    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
252

gsell's avatar
gsell committed
253
OPTION (DBG_SCALARFIELD "Enable dump of scalar field rho_m" OFF)
254
IF (DBG_SCALARFIELD)
255
    MESSAGE ("\nWrite scalar rho_m field is enabled ")
gsell's avatar
gsell committed
256
<<<<<<< HEAD
gsell's avatar
gsell committed
257
    SET (CMAKE_CXX_FLAGS "-DDBG_SCALARFIELD ${CMAKE_CXX_FLAGS}")
gsell's avatar
gsell committed
258
ENDIF ()
gsell's avatar
gsell committed
259
=======
260
    ADD_DEFINITIONS(-DDBG_SCALARFIELD)
261
ENDIF (DBG_SCALARFIELD)
gsell's avatar
gsell committed
262
>>>>>>> 3834e6eef6d61f1c54c3582b66db9e5e060f5178
263

gsell's avatar
gsell committed
264
OPTION (DBG_STENCIL "Dump stencil of iterative solver in matlab format" OFF)
265
IF (DBG_STENCIL)
266
    MESSAGE ("\nWrite stencil is enabled ")
gsell's avatar
gsell committed
267
<<<<<<< HEAD
gsell's avatar
gsell committed
268
    SET (CMAKE_CXX_FLAGS "-DDBG_STENCIL ${CMAKE_CXX_FLAGS}")
gsell's avatar
gsell committed
269
ENDIF ()
gsell's avatar
gsell committed
270
=======
271
    ADD_DEFINITIONS(-DDBG_STENCIL)
272
ENDIF (DBG_STENCIL)
gsell's avatar
gsell committed
273
>>>>>>> 3834e6eef6d61f1c54c3582b66db9e5e060f5178
274

gsell's avatar
gsell committed
275
OPTION (NO_FIELD_ASSIGN_OPTIMIZATION "Disable compiler optimization of IPPL field assignment" OFF)
276
IF (NO_FIELD_ASSIGN_OPTIMIZATION)
277
    MESSAGE ("\nCompiler will not try to optimize field assignment")
gsell's avatar
gsell committed
278
<<<<<<< HEAD
279 280
    SET (CMAKE_CXX_FLAGS
        "-DdontOPTIMIZE_FIELD_ASSIGNMENT ${CMAKE_CXX_FLAGS}"
gsell's avatar
gsell committed
281
	)
gsell's avatar
gsell committed
282
ENDIF ()
gsell's avatar
gsell committed
283
=======
284
    ADD_DEFINITIONS(-DdontOPTIMIZE_FIELD_ASSIGNMENT)
285
ENDIF (NO_FIELD_ASSIGN_OPTIMIZATION)
gsell's avatar
gsell committed
286
>>>>>>> 3834e6eef6d61f1c54c3582b66db9e5e060f5178
gsell's avatar
gsell committed
287

kraus's avatar
kraus committed
288 289 290 291 292 293 294
INCLUDE(FindGit)
IF(GIT_FOUND)
    SET (OPAL_WC_REVISION 0)
    EXECUTE_PROCESS(
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        COMMAND git rev-parse HEAD
        OUTPUT_VARIABLE GIT_OUT OUTPUT_STRIP_TRAILING_WHITESPACE
gsell's avatar
gsell committed
295
        )
kraus's avatar
kraus committed
296
    SET (OPAL_WC_REVISION \"${GIT_OUT}\")
kraus's avatar
kraus committed
297
ELSE()
298
    MESSAGE ("could not find git")
kraus's avatar
kraus committed
299 300 301
    SET (OPAL_WC_REVISION \"\")
ENDIF()

kraus's avatar
kraus committed
302
SET (IPPL_USED_FROM_OPAL "TRUE")
adelmann's avatar
adelmann committed
303

gsell's avatar
gsell committed
304
ADD_SUBDIRECTORY (ippl)
adelmann's avatar
adelmann committed
305
ADD_SUBDIRECTORY (optimizer)
gsell's avatar
gsell committed
306
ADD_SUBDIRECTORY (src)
307
ADD_SUBDIRECTORY (tools)
308 309

IF (BUILD_OPAL_UNIT_TESTS)
gsell's avatar
gsell committed
310
    ADD_SUBDIRECTORY(tests)
adelmann's avatar
adelmann committed
311
ENDIF (BUILD_OPAL_UNIT_TESTS)
312

313
# make variables visible in other CMakeLists files
314
set(OPAL_CXX_FLAGS ${OPAL_CXX_FLAGS}
gsell's avatar
gsell committed
315 316
    CACHE INTERNAL "" FORCE
    )
317
set(OPAL_LIBS ${OPAL_LIBS}
gsell's avatar
gsell committed
318 319
    CACHE INTERNAL "" FORCE
    )
320 321 322

# configure file
configure_file (
gsell's avatar
gsell committed
323 324 325
    ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
    ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config_install.cmake
    )
326 327

install (
gsell's avatar
gsell committed
328 329 330 331 332 333 334 335 336 337 338
    FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config_install.cmake
    DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME}"
    RENAME ${PROJECT_NAME}Config.cmake
    )

# vi: set et ts=4 sw=4 sts=4:
# Local Variables:
# mode:cmake
# cmake-tab-width: 4
# indent-tabs-mode:nil
# End: