CMakeLists.txt 10.1 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
MESSAGE (STATUS "Build type is: " ${CMAKE_BUILD_TYPE})
26
MESSAGE (STATUS "Host OS System: ${CMAKE_HOST_SYSTEM}")
27
MESSAGE (STATUS "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 38 39 40 41 42
find_package (MPI REQUIRED)
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}")

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
# compiler dependent flags
if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
47
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -diag-disable 383 -diag-disable 981 -std=c++11")
48

frey_m's avatar
frey_m committed
49 50 51
    if (ENABLE_OpenMP)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -openmp")
    endif (ENABLE_OpenMP)
52
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
53
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wsign-compare -Wunused-variable -Warray-bounds -DIPPL_RESTRICT_BUG -std=c++11")
54

frey_m's avatar
frey_m committed
55 56 57 58 59
    if (ENABLE_OpenMP)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
    endif (ENABLE_OpenMP)


60 61
elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
    if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "4.7.3")
62
        message (FATAL_ERROR "To build OPAL you need GCC version 4.7.3 or greater")
63
    endif ()
64 65
    # Warning flags, -Wno-unused-local-typedefs is needed for boost versions below 1.59
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-unused-local-typedefs -Werror=unused-variable -std=c++11")
frey_m's avatar
frey_m committed
66 67 68

    if (ENABLE_OpenMP)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
frey_m's avatar
frey_m committed
69
    endif (ENABLE_OpenMP)
frey_m's avatar
frey_m committed
70

71 72 73 74
else ()
    message (STATUS "Unknown C++ compiler. Please use the GNU or Intel compiler, IF you are having problems.")
endif ()

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

91 92 93
FIND_PACKAGE (H5Hut REQUIRED)
FIND_PACKAGE (HDF5 REQUIRED)
FIND_PACKAGE (GSL REQUIRED)
94

gsell's avatar
gsell committed
95
set (BOOSTROOT $ENV{BOOST_DIR})
96 97 98
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED OFF)
set(Boost_USE_STATIC_RUNTIME OFF)
kraus's avatar
kraus committed
99
find_package (Boost 1.55.0 REQUIRED COMPONENTS filesystem system iostreams regex)
100 101
if (Boost_INCLUDE_DIRS)
    message (STATUS "Found boost include dir: ${Boost_INCLUDE_DIR}")
102 103
    message (STATUS "Found boost library dir: ${Boost_LIBRARY_DIR}")
    message (STATUS "Found boost libraries: ${Boost_LIBRARIES}")
104 105
    include_directories (${Boost_INCLUDE_DIRS})
endif ()
106

107 108

### Uldis Locans 2014.09.05 ###
Uldis Locans's avatar
Uldis Locans committed
109
OPTION (ENABLE_DKS "Enable DKS" OFF)
110 111

### Load DKS package ###
112
IF (ENABLE_DKS)
gsell's avatar
gsell committed
113 114 115 116 117 118
    FIND_PACKAGE(DKS 1.1.1 REQUIRED HINTS $ENV{DKS_PREFIX} $ENV{DKS_DIR} $ENV{DKS})
    set (DKS_VERSION_OPAL \"${DKS_VERSION}\")
    MESSAGE (STATUS "Found DKS version: ${DKS_VERSION}")
    MESSAGE (STATUS "Found DKS library: ${DKS_LIBRARY}")
    MESSAGE (STATUS "Found DKS include dir: ${DKS_INCLUDE_DIR}")
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDKS_MPI")
119

gsell's avatar
gsell committed
120 121
    ### OpenCL compiler flags ###
    #SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lOpenCL -pthread -DDKS_OPENCL")
122

gsell's avatar
gsell committed
123 124
    ### CUDA compiler flags ###
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDKS_CUDA")
125

gsell's avatar
gsell committed
126 127
    ### if any accelerator enabled set flag to use DKS ###
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DIPPL_DKS -DIPPL_DKS_CUDA -DOPAL_DKS")
128
ENDIF (ENABLE_DKS)
129 130
### END DKS part ###

131
# Handle options
132
OPTION (ENABLE_AMR "Enable AMReX based AMR solver" OFF)
133
OPTION (ENABLE_AMR_MG_SOLVER "Enable AMR MG solver" OFF)
134

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

137 138
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
139

140 141
OPTION (NO_FIELD_ASSIGN_OPTIMIZATION "Disable compiler optimization of IPPL field assignment" OFF)

142 143
OPTION (BUILD_OPAL_UNIT_TESTS "Unit tests" OFF)

144 145 146 147 148
IF (BUILD_OPAL_UNIT_TESTS)
    FIND_PACKAGE (GTest REQUIRED)
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DWITH_UNIT_TESTS")
ENDIF (BUILD_OPAL_UNIT_TESTS)

149 150
IF (ENABLE_AMR)
    MESSAGE (STATUS "Enable AMR_SOLVER    " ${ENABLE_AMR})
frey_m's avatar
frey_m committed
151
    ENABLE_LANGUAGE (Fortran)
152

gsell's avatar
gsell committed
153 154
    find_package (AMReX CONFIG REQUIRED
        HINTS $ENV{AMREX_HOME}/cmake $ENV{AMREX_DIR}/cmake $ENV{AMREX_PREFIX}/cmake)
155

156 157 158
    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}")
frey_m's avatar
frey_m committed
159
    MESSAGE (STATUS "Found AMReX Fortran links: ${AMREX_EXTRA_Fortran_LINK_LINE}")
160 161 162 163 164
    echo_amrex_config_options()
    
    add_definitions(${AMREX_DEFINES})
    
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DENABLE_AMR")
165
    SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable -Wno-unused-but-set-variable -Wno-maybe-uninitialized")
166

167
ENDIF (ENABLE_AMR)
gsell's avatar
gsell committed
168

169 170 171 172 173 174 175
# 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
176 177 178 179 180 181 182 183
IF (ENABLE_SAAMG_SOLVER OR ENABLE_AMR_MG_SOLVER)

    IF ( ENABLE_SAAMG_SOLVER )
        MESSAGE (STATUS "Enable SAAMG_SOLVER  " ${ENABLE_SAAMG_SOLVER})
    ELSE ( ENABLE_SAAMG_SOLVER )
        MESSAGE (STATUS "Enable AMR_MG_SOLVER " ${ENABLE_AMR_MG_SOLVER})
    ENDIF( ENABLE_SAAMG_SOLVER )
    
gsell's avatar
gsell committed
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
    IF (NOT (
                ${HOSTNAME_BASE} MATCHES "edison" OR
                ${HOSTNAME_BASE} MATCHES "cori"))
        
        find_package (Trilinos REQUIRED HINTS $ENV{TRILINOS_PREFIX} $ENV{TRILINOS_DIR} $ENV{TRILINOS})

        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}")

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

211
IF (DBG_SCALARFIELD)
gsell's avatar
gsell committed
212 213
    MESSAGE (STATUS "\nWrite scalar rho_m field is enabled ")
    SET (CMAKE_CXX_FLAGS "-DDBG_SCALARFIELD ${CMAKE_CXX_FLAGS}")
214 215 216
ENDIF (DBG_SCALARFIELD)

IF (DBG_STENCIL)
gsell's avatar
gsell committed
217 218
    MESSAGE (STATUS "\nWrite stencil is enabled ")
    SET (CMAKE_CXX_FLAGS "-DDBG_STENCIL ${CMAKE_CXX_FLAGS}")
219 220
ENDIF (DBG_STENCIL)

221 222 223 224
IF (NO_FIELD_ASSIGN_OPTIMIZATION)
    MESSAGE (STATUS "\nCompiler will not try to optimize field assignment")
    SET (CMAKE_CXX_FLAGS
        "-DdontOPTIMIZE_FIELD_ASSIGNMENT ${CMAKE_CXX_FLAGS}"
gsell's avatar
gsell committed
225
	)
226
ENDIF (NO_FIELD_ASSIGN_OPTIMIZATION)
gsell's avatar
gsell committed
227

kraus's avatar
kraus committed
228 229 230 231 232 233 234
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
235
        )
kraus's avatar
kraus committed
236
    SET (OPAL_WC_REVISION \"${GIT_OUT}\")
kraus's avatar
kraus committed
237
ELSE()
kraus's avatar
kraus committed
238
    MESSAGE (STATUS "could not find git")
kraus's avatar
kraus committed
239 240 241
    SET (OPAL_WC_REVISION \"\")
ENDIF()

kraus's avatar
kraus committed
242
SET (IPPL_USED_FROM_OPAL "TRUE")
adelmann's avatar
adelmann committed
243

gsell's avatar
gsell committed
244
ADD_SUBDIRECTORY (ippl)
adelmann's avatar
adelmann committed
245
ADD_SUBDIRECTORY (optimizer)
adelmann's avatar
adelmann committed
246

gsell's avatar
gsell committed
247
ADD_SUBDIRECTORY (src)
248
ADD_SUBDIRECTORY (tools)
249 250

IF (BUILD_OPAL_UNIT_TESTS)
gsell's avatar
gsell committed
251
    ADD_SUBDIRECTORY(tests)
adelmann's avatar
adelmann committed
252
ENDIF (BUILD_OPAL_UNIT_TESTS)
253

254
# make variables visible in other CMakeLists files
255
set(OPAL_CXX_FLAGS ${OPAL_CXX_FLAGS}
gsell's avatar
gsell committed
256 257
    CACHE INTERNAL "" FORCE
    )
258

259
set(OPAL_LIBS ${OPAL_LIBS}
gsell's avatar
gsell committed
260 261
    CACHE INTERNAL "" FORCE
    )
262 263 264

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

install (
gsell's avatar
gsell committed
270 271 272 273 274 275 276 277 278 279 280
    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: