CMakeLists.txt 9.92 KB
Newer Older
1
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.10)
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}\"")
11 12
STRING (REGEX REPLACE "\\.([0-9])\\." ".0\\1." PACKAGE_VERSION ${PACKAGE_VERSION})
STRING (REGEX REPLACE "\\.([0-9])$" ".0\\1" PACKAGE_VERSION ${PACKAGE_VERSION})
13
STRING (REGEX REPLACE "\\." "" PACKAGE_VERSION ${PACKAGE_VERSION})
gsell's avatar
gsell committed
14

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

22 23 24

CMAKE_HOST_SYSTEM_INFORMATION(RESULT HOSTNAME QUERY HOSTNAME)

25 26 27
MESSAGE ("Build type is: " ${CMAKE_BUILD_TYPE})
MESSAGE ("Host OS System: ${CMAKE_HOST_SYSTEM}")
MESSAGE ("Hostname:  ${HOSTNAME}")
28

29
# Select flags.
30 31
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g ")
SET (CMAKE_CXX_FLAGS_RELEASE "-O3")
32
SET (CMAKE_CXX_FLAGS_DEBUG  "-O0 -g")
gsell's avatar
gsell committed
33

34 35 36
# Resolve all library dependencies
SET (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules")

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

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

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

add_compile_options (-Wall)

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

58 59
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
    add_compile_options (-Werror -Wsign-compare -Wunused-variable -Warray-bounds -DIPPL_RESTRICT_BUG)
frey_m's avatar
frey_m committed
60
    if (ENABLE_OpenMP)
61 62
	    add_compile_options (-fopenmp)
    endif ()
frey_m's avatar
frey_m committed
63

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

74
else ()
75
    message ("Unknown C++ compiler. Please use the GNU or Intel compiler, IF you are having problems.")
76 77
endif ()

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

94 95 96 97 98 99
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}")
100

gsell's avatar
gsell committed
101
set (BOOSTROOT $ENV{BOOST_DIR})
102 103 104 105
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)
106
if (Boost_INCLUDE_DIRS)
107 108 109 110 111 112 113
    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}")
114 115
    include_directories (${Boost_INCLUDE_DIRS})
endif ()
116

Uldis Locans's avatar
Uldis Locans committed
117
OPTION (ENABLE_DKS "Enable DKS" OFF)
118
IF (ENABLE_DKS)
119
    find_package (dKS 1.1.1 REQUIRED HINTS $ENV{DKS_PREFIX} $ENV{DKS_DIR} $ENV{DKS})
gsell's avatar
gsell committed
120
    set (DKS_VERSION_OPAL \"${DKS_VERSION}\")
121 122 123
    MESSAGE ("Found DKS version: ${DKS_VERSION}")
    MESSAGE ("Found DKS library: ${DKS_LIBRARY}")
    MESSAGE ("Found DKS include dir: ${DKS_INCLUDE_DIR}")
gsell's avatar
gsell committed
124
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDKS_MPI")
125

gsell's avatar
gsell committed
126 127
    ### OpenCL compiler flags ###
    #SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lOpenCL -pthread -DDKS_OPENCL")
128

gsell's avatar
gsell committed
129 130
    ### CUDA compiler flags ###
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDKS_CUDA")
131

gsell's avatar
gsell committed
132 133
    ### if any accelerator enabled set flag to use DKS ###
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIPPL_DKS -DIPPL_DKS_CUDA -DOPAL_DKS")
134
ENDIF (ENABLE_DKS)
135 136
### END DKS part ###

137
# Handle options
138
OPTION (ENABLE_AMR "Enable AMReX based AMR solver" OFF)
139
OPTION (ENABLE_AMR_MG_SOLVER "Enable AMR MG solver" OFF)
140

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

143 144
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
145

146 147
OPTION (NO_FIELD_ASSIGN_OPTIMIZATION "Disable compiler optimization of IPPL field assignment" OFF)

148 149
OPTION (BUILD_OPAL_UNIT_TESTS "Unit tests" OFF)

150 151 152 153 154
IF (BUILD_OPAL_UNIT_TESTS)
    FIND_PACKAGE (GTest REQUIRED)
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWITH_UNIT_TESTS")
ENDIF (BUILD_OPAL_UNIT_TESTS)

155
IF (ENABLE_AMR)
156
    MESSAGE ("Enable AMR_SOLVER    " ${ENABLE_AMR})
frey_m's avatar
frey_m committed
157
    ENABLE_LANGUAGE (Fortran)
158

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

162 163 164 165
    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}")
166 167 168 169 170
    echo_amrex_config_options()
    
    add_definitions(${AMREX_DEFINES})
    
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_AMR")
171
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable -Wno-unused-but-set-variable -Wno-maybe-uninitialized")
172

173
ENDIF (ENABLE_AMR)
gsell's avatar
gsell committed
174

175 176 177 178 179 180 181
# 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
182 183 184
IF (ENABLE_SAAMG_SOLVER OR ENABLE_AMR_MG_SOLVER)

    IF ( ENABLE_SAAMG_SOLVER )
185
        MESSAGE ("Enable SAAMG_SOLVER  " ${ENABLE_SAAMG_SOLVER})
frey_m's avatar
frey_m committed
186
    ELSE ( ENABLE_SAAMG_SOLVER )
187
        MESSAGE ("Enable AMR_MG_SOLVER " ${ENABLE_AMR_MG_SOLVER})
frey_m's avatar
frey_m committed
188 189
    ENDIF( ENABLE_SAAMG_SOLVER )
    
gsell's avatar
gsell committed
190 191 192 193 194 195
    IF (NOT (
                ${HOSTNAME_BASE} MATCHES "edison" OR
                ${HOSTNAME_BASE} MATCHES "cori"))
        
        find_package (Trilinos REQUIRED HINTS $ENV{TRILINOS_PREFIX} $ENV{TRILINOS_DIR} $ENV{TRILINOS})

196 197 198 199 200
        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}")
gsell's avatar
gsell committed
201 202

        if (NOT ${MPI_CXX_COMPILER} STREQUAL ${Trilinos_CXX_COMPILER} )
203 204 205 206 207 208 209 210 211 212
            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  "")
gsell's avatar
gsell committed
213 214 215
        ENDIF ()
    ENDIF ()
ENDIF ()
frey_m's avatar
frey_m committed
216

217
IF (DBG_SCALARFIELD)
218
    MESSAGE ("\nWrite scalar rho_m field is enabled ")
gsell's avatar
gsell committed
219
    SET (CMAKE_CXX_FLAGS "-DDBG_SCALARFIELD ${CMAKE_CXX_FLAGS}")
220 221 222
ENDIF (DBG_SCALARFIELD)

IF (DBG_STENCIL)
223
    MESSAGE ("\nWrite stencil is enabled ")
gsell's avatar
gsell committed
224
    SET (CMAKE_CXX_FLAGS "-DDBG_STENCIL ${CMAKE_CXX_FLAGS}")
225 226
ENDIF (DBG_STENCIL)

227
IF (NO_FIELD_ASSIGN_OPTIMIZATION)
228
    MESSAGE ("\nCompiler will not try to optimize field assignment")
229 230
    SET (CMAKE_CXX_FLAGS
        "-DdontOPTIMIZE_FIELD_ASSIGNMENT ${CMAKE_CXX_FLAGS}"
gsell's avatar
gsell committed
231
	)
232
ENDIF (NO_FIELD_ASSIGN_OPTIMIZATION)
gsell's avatar
gsell committed
233

kraus's avatar
kraus committed
234 235 236 237 238 239 240
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
241
        )
kraus's avatar
kraus committed
242
    SET (OPAL_WC_REVISION \"${GIT_OUT}\")
kraus's avatar
kraus committed
243
ELSE()
244
    MESSAGE ("could not find git")
kraus's avatar
kraus committed
245 246 247
    SET (OPAL_WC_REVISION \"\")
ENDIF()

kraus's avatar
kraus committed
248
SET (IPPL_USED_FROM_OPAL "TRUE")
adelmann's avatar
adelmann committed
249

gsell's avatar
gsell committed
250
ADD_SUBDIRECTORY (ippl)
adelmann's avatar
adelmann committed
251
ADD_SUBDIRECTORY (optimizer)
gsell's avatar
gsell committed
252
ADD_SUBDIRECTORY (src)
253
ADD_SUBDIRECTORY (tools)
254 255

IF (BUILD_OPAL_UNIT_TESTS)
gsell's avatar
gsell committed
256
    ADD_SUBDIRECTORY(tests)
adelmann's avatar
adelmann committed
257
ENDIF (BUILD_OPAL_UNIT_TESTS)
258

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

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

install (
gsell's avatar
gsell committed
274 275 276 277 278 279 280 281 282 283 284
    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: