CMakeLists.txt 9.89 KB
Newer Older
1 2 3 4
CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
PROJECT (OPAL)
SET (OPAL_VERSION_MAJOR 1)
SET (OPAL_VERSION_MINOR 1.9)
gsell's avatar
gsell committed
5

6
SET (CMAKE_CXX_COMPILER ${MPI_COMPILER})
gsell's avatar
gsell committed
7

8 9 10
MESSAGE (STATUS "CMAKE_CXX_COMPILER: ${CMAKE_CXX_COMPILER}")
MESSAGE (STATUS "MPI_COMPILER: ${iMPI_COMPILER}")

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

18 19
MESSAGE (STATUS "Build type is: " ${CMAKE_BUILD_TYPE})

20
# Select flags.
21 22
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g ")
SET (CMAKE_CXX_FLAGS_RELEASE "-O3")
23
SET (CMAKE_CXX_FLAGS_DEBUG  "-O0 -g")
gsell's avatar
gsell committed
24

25 26 27 28

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

29 30
FIND_PACKAGE (IPPL REQUIRED HINTS $ENV{IPPL_PREFIX} $ENV{IPPL_DIR} $ENV{IPPL})
MESSAGE (STATUS "Found IPPL library: ${IPPL_LIBRARY}")
31 32 33 34 35
MESSAGE (STATUS "Found IPPL include dir: ${IPPL_INCLUDE_DIR}")

FIND_PACKAGE (H5Hut REQUIRED)
FIND_PACKAGE (HDF5 REQUIRED)
FIND_PACKAGE (GSL REQUIRED)
36
FIND_PACKAGE (MPI REQUIRED)
37 38

# Handle options
39 40
OPTION (ENABLE_AMR_SOLVER "Enable BoxLib based AMR solver" OFF)

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

43 44 45
OPTION (DBG_SCALARFIELD "Enable dump of scalar field rho_m" OFF)
OPTION (DBG_STENCIL "Dump stencil of iterative solver in matlab format" OFF)
OPTION (BUILD_LIBOPAL "Enable building the OPAL library" OFF)
gsell's avatar
gsell committed
46

47 48 49
OPTION (NOCPLUSPLUS11_FOREACH "Disable C++11 foreach support" OFF)
OPTION (NOCPLUSPLUS11_NULLPTR "Disable C++11 nullptr support" OFF)

50 51
OPTION (NO_FIELD_ASSIGN_OPTIMIZATION "Disable compiler optimization of IPPL field assignment" OFF)

52 53 54
IF (ENABLE_AMR_SOLVER)
   MESSAGE (STATUS "----> Enable AMR")
#
55
   FIND_PACKAGE (CCSE REQUIRED HINTS $ENV{CCSE_INCLUDE_DIRS} $ENV{CCSE_LIBRARY_DIR})
56 57 58 59 60 61 62
#
   SET(BL_SPACEDIM 3 CACHE INT "Dimension of BoxLib build")
   SET(ENABLE_MPI 1 CACHE INT "Enable build with MPI")
   SET(ENABLE_OpenMP 0 CACHE INT "Enable build with OpenMP")
   SET(BL_PRECISION "DOUBLE" CACHE INT "Precision of BoxLib build")
   SET(BL_USE_PARTICLES 1 CACHE INT "Include Particles classes in BoxLib build")
   SET(ENABLE_PROFILING 0 CACHE INT "Include profiling information in BoxLib build")
63
   SET(ENABLE_BACKTRACE 1 CACHE INT "Include backtrace information in BoxLib build")
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
   INCLUDE($ENV{BOXLIB_HOME}/Tools/CMake/CCSEOptions.cmake)
   SET (CMAKE_CXX_FLAGS "-Wno-sign-compare -DHAVE_AMR_SOLVER -DTULIN ${CMAKE_CXX_FLAGS}")
   SET (CCSE_INCLUDE_DIRS $ENV{CCSE_INCLUDE_DIRS})
   SET (CCSE_LIBRARY_DIR $ENV{CCSE_LIBRARY_DIR})
   #
   SET(CCSE_LIBRARIES box_camrdata;cboxlib;cfboxlib;fboxlib)
   FOREACH (L ${CCSE_LIBRARIES})

            find_library(CCSE_LIBRARY
                         NAMES ${L}
                         HINTS ${CCSE_LIBRARY_DIR}
                         NO_DEFAULT_PATH)

            IF ( NOT CCSE_LIBRARY )
                message(SEND_ERROR "Cannot locate CCSE library: ${L}")
            ENDIF()

    ENDFOREACH()
    MESSAGE (STATUS "----> Enable AMR done")
    # Get Trilinos as one entity
    FIND_PACKAGE(Trilinos REQUIRED HINTS $ENV{TRILINOS_PREFIX} $ENV{TRILINOS_DIR} $ENV{TRILINOS})

    # Echo trilinos build info just for fun
    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}")

    # Make sure to use same compilers and flags as Trilinos
    IF (NOT ${CMAKE_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_ERROR "Oops ...")
    ENDIF ()
ENDIF (ENABLE_AMR_SOLVER)

108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
IF (DBG_SCALARFIELD)
   MESSAGE (STATUS "\nWrite scalar rho_m field is enabled ")
   SET (CMAKE_CXX_FLAGS "-DDBG_SCALARFIELD ${CMAKE_CXX_FLAGS}")
ENDIF (DBG_SCALARFIELD)

IF (DBG_STENCIL)
   MESSAGE (STATUS "\nWrite stencil is enabled ")
   SET (CMAKE_CXX_FLAGS "-DDBG_STENCIL ${CMAKE_CXX_FLAGS}")
ENDIF (DBG_STENCIL)

IF (BUILD_LIBOPAL)
   MESSAGE (STATUS "\nBuilding OPAL library")
ENDIF (BUILD_LIBOPAL)

IF (NOCPLUSPLUS11_FOREACH)
    MESSAGE (STATUS "\nBuilding OPAL without c++11 foreach support")
    SET (CMAKE_CXX_FLAGS
        "-DOPAL_NOCPLUSPLUS11_FOREACH ${CMAKE_CXX_FLAGS}"
126
    )
127
ENDIF (NOCPLUSPLUS11_FOREACH)
128

129 130 131 132
IF (NOCPLUSPLUS11_NULLPTR)
    MESSAGE (STATUS "\nBuilding OPAL without c++11 nullptr support")
    SET (CMAKE_CXX_FLAGS
        "-DOPAL_NOCPLUSPLUS11_NULLPTR ${CMAKE_CXX_FLAGS}"
133
    )
134
ENDIF (NOCPLUSPLUS11_NULLPTR)
135

136 137 138 139 140 141
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}"
    )
ENDIF (NO_FIELD_ASSIGN_OPTIMIZATION)
gsell's avatar
gsell committed
142

143
IF (ENABLE_SAAMG_SOLVER)
gsell's avatar
gsell committed
144
    # Get Trilinos as one entity
145
    FIND_PACKAGE(Trilinos REQUIRED HINTS $ENV{TRILINOS_PREFIX} $ENV{TRILINOS_DIR} $ENV{TRILINOS})
gsell's avatar
gsell committed
146 147

    # Echo trilinos build info just for fun
148 149 150 151 152
    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
153 154

    # Make sure to use same compilers and flags as Trilinos
155 156 157 158 159 160 161 162 163 164 165 166
    IF (NOT ${CMAKE_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_ERROR "Oops ...")
    ENDIF ()
gsell's avatar
gsell committed
167 168 169 170

    #SET(CMAKE_CXX_FLAGS  "${Trilinos_CXX_COMPILER_FLAGS} ${CMAKE_CXX_FLAGS}")
    #SET(CMAKE_C_FLAGS  "${Trilinos_C_COMPILER_FLAGS} ${CMAKE_C_FLAGS}")
    #SET(CMAKE_Fortran_FLAGS  "${Trilinos_Fortran_COMPILER_FLAGS} ${CMAKE_Fortran_FLAGS}")
171
ENDIF (ENABLE_SAAMG_SOLVER)
gsell's avatar
gsell committed
172

173
MESSAGE (STATUS "Using C++ compiler: ${CMAKE_CXX_COMPILER}")
174

kraus's avatar
kraus committed
175
# compiler dependent flags
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191

SET (MPI_UNDERLYING_COMPILER "")

EXECUTE_PROCESS (COMMAND ${CMAKE_CXX_COMPILER} -show
                OUTPUT_VARIABLE MPI_COMPILER_OUTPUT
                ERROR_VARIABLE MPI_COMPILER_ERROR)
IF ("${MPI_COMPILER_ERROR}" STREQUAL "")
    STRING (REGEX REPLACE "([A-Za-z.0-9/]*) .*$" "\\1" MPI_UNDERLYING_COMPILER ${MPI_COMPILER_OUTPUT})
    STRING (REGEX REPLACE "/" ";" MPI_UNDERLYING_COMPILER_SPLIT ${MPI_UNDERLYING_COMPILER})
    LIST (REVERSE MPI_UNDERLYING_COMPILER_SPLIT)
    LIST (GET MPI_UNDERLYING_COMPILER_SPLIT 0 MPI_UNDERLYING_COMPILER_NAME)
ENDIF ("${MPI_COMPILER_ERROR}" STREQUAL "")

IF ("${MPI_UNDERLYING_COMPILER_NAME}" STREQUAL "icpc")
    # using intel compiler
    MESSAGE (STATUS "The underlying compiler is: icpc")
192 193
    SET (CMAKE_CXX_FLAGS
         "-diag-disable 383 -diag-disable 981 $ENV{CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS} ${OTHER_CMAKE_CXX_FLAGS}")
194 195 196 197

ELSEIF ("${MPI_UNDERLYING_COMPILER_NAME}" STREQUAL "clang++")
    # using clang compiler
    MESSAGE (STATUS "The underlying compiler is: clang++")
198 199
    SET (CMAKE_CXX_FLAGS
         "-Wall -Werror -Wsign-compare -Wunused-variable -Warray-bounds -DIPPL_RESTRICT_BUG $ENV{CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS} ${OTHER_CMAKE_CXX_FLAGS}")
200 201 202 203 204 205 206 207 208 209 210 211 212 213

ELSEIF ("${MPI_UNDERLYING_COMPILER_NAME}" STREQUAL "g++")
    # using gnu compiler
    MESSAGE (STATUS "The underlying compiler is: g++")
    EXECUTE_PROCESS (COMMAND ${MPI_UNDERLYING_COMPILER} --version
                    OUTPUT_VARIABLE GCC_VERSION_OUTPUT
                    ERROR_VARIABLE GCC_VERSION_ERROR)
    STRING (REGEX REPLACE ".*([0-9]\\.[0-9]\\.[0-9]).*" "\\1" GCC_VERSION ${GCC_VERSION_OUTPUT})
    MESSAGE (STATUS "Your gcc version is: ${GCC_VERSION}")

    IF (${GCC_VERSION} VERSION_LESS "4.5.0")
        MESSAGE (FATAL_ERROR "To build OPAL you need gcc version 4.5.0 or greater")

    ELSEIF (${GCC_VERSION} VERSION_LESS "4.6.0")
214 215
        SET (CMAKE_CXX_FLAGS
             "-DOPAL_NOCPLUSPLUS11_NULLPTR -DOPAL_NOCPLUSPLUS11_FOREACH $ENV{CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS} ${OTHER_CMAKE_CXX_FLAGS}")
216 217 218 219

    ELSEIF (${GCC_VERSION} VERSION_LESS "4.7.0")
        SET (CMAKE_CXX_FLAGS
    	"-Wall -Werror -Wno-reorder -std=c++0x $ENV{CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS} ${OTHER_CMAKE_CXX_FLAGS}")
kraus's avatar
kraus committed
220

221
    ELSEIF (${GCC_VERSION} VERSION_EQUAL "4.7.0")
222 223
        SET (CMAKE_CXX_FLAGS
            "-DdontOPTIMIZE_FIELD_ASSIGNMENT $ENV{CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS} ${OTHER_CMAKE_CXX_FLAGS}")
224 225 226

    ELSEIF (${GCC_VERSION} VERSION_GREATER "4.7")
        SET (CMAKE_CXX_FLAGS
227
        "-Wall -Werror -Wno-reorder -Werror=unused-variable -std=c++11 $ENV{CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS} ${OTHER_CMAKE_CXX_FLAGS}")
228 229 230 231 232 233 234 235 236 237
    ENDIF ()

ELSE ()
    # using unknown compiler
    MESSAGE (STATUS "${CMAKE_CXX_COMPILER} is using a compiler (${MPI_UNDERLYING_COMPILER}) we were not thinking of!
             Please use the gnu compiler or the intel compiler IF you are having problems.")
ENDIF ()



238 239
MESSAGE (STATUS "Compiling with ${CMAKE_CXX_FLAGS}")

240

241 242
ADD_SUBDIRECTORY (classic/5.0/src)
ADD_SUBDIRECTORY (src)