CMakeLists.txt 11.2 KB
Newer Older
1
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.11)
2 3 4 5
SET(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build,
options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS used) Debug Release
RelWithDebInfo MinSizeRel.")

6 7
PROJECT(Nektar++ C CXX)

8
CMAKE_POLICY(SET CMP0022 NEW)
9 10 11 12 13 14

# Defer to use _ROOT variables to avoid Zlib warning
IF (POLICY CMP0074)
    CMAKE_POLICY(SET CMP0074 OLD)
ENDIF()

15 16
# Nektar++ requires C++11. Try to infer this for older CMake versions (less than
# 3.1.0)
17 18 19 20 21 22 23 24 25 26 27 28
IF ("${CMAKE_VERSION}" VERSION_LESS "3.1")
    IF (NOT MSVC)
        INCLUDE(CheckCXXCompilerFlag)
        CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)

        IF (COMPILER_SUPPORTS_CXX11)
            SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
        ELSE()
            MESSAGE(FATAL_ERROR "Nektar++ requires a compiler with C++11 support.")
        ENDIF()
    ELSEIF(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 18.0)
        MESSAGE(FATAL_ERROR "Nektar++ requires full C++11 support: please upgrade to Visual Studio 2013 or later")
29 30 31 32 33 34
    ENDIF()
ELSE()
    SET(CMAKE_CXX_STANDARD 11)
    SET(CMAKE_CXX_STANDARD_REQUIRED ON)
    SET(CMAKE_CXX_EXTENSIONS OFF)
ENDIF()
35 36 37 38 39

INCLUDE(CheckLanguage)

CHECK_LANGUAGE(Fortran)
IF(CMAKE_Fortran_COMPILER)
40
    ENABLE_LANGUAGE(Fortran)
41
ELSE()
42
    MESSAGE(STATUS "No Fortran support")
43
ENDIF()
44 45 46 47 48 49 50 51 52 53 54 55 56

# Helps organize projects in IDEs.
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)

# Extract the version number from the VERSION file and set in CMake
# The format of this file must be X.X.X
FILE(STRINGS "VERSION" NEKVER)
STRING(REPLACE "." ";" NEKVERLIST ${NEKVER})
LIST(GET NEKVERLIST 0 NEKTAR_VERSION_MAJOR)
LIST(GET NEKVERLIST 1 NEKTAR_VERSION_MINOR)
LIST(GET NEKVERLIST 2 NEKTAR_VERSION_PATCH)
SET(NEKTAR_VERSION ${NEKTAR_VERSION_MAJOR}.${NEKTAR_VERSION_MINOR}.${NEKTAR_VERSION_PATCH})

57
# Add support for CMAKE_DEPENDENT_OPTION
58
INCLUDE(CMakeDependentOption)
59
INCLUDE(CMakeParseArguments)
60 61

# Enable CTest.
62 63 64 65
ENABLE_TESTING()

# Find the modules included with Nektar
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
66 67 68 69

# Set default install path if not provided on the command-line
IF (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
    SET(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/dist CACHE PATH "" FORCE)
70 71
ENDIF()

72
# Find default search paths for OS X; adapted from Stack Overflow question
73
# 1487752.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
IF (APPLE)
    EXECUTE_PROCESS(COMMAND which port
        RESULT_VARIABLE DETECT_MACPORTS
        OUTPUT_VARIABLE MACPORTS_PREFIX
        ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
    EXECUTE_PROCESS(COMMAND brew --prefix
        RESULT_VARIABLE DETECT_HOMEBREW
        OUTPUT_VARIABLE HOMEBREW_PREFIX
        ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)

    IF (${DETECT_MACPORTS} EQUAL 0)
        GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY)
        GET_FILENAME_COMPONENT(MACPORTS_PREFIX ${MACPORTS_PREFIX} DIRECTORY)
        SET(CMAKE_LIBRARY_PATH ${MACPORTS_PREFIX}/lib ${CMAKE_LIBRARY_PATH})
        SET(CMAKE_INCLUDE_PATH ${MACPORTS_PREFIX}/include ${CMAKE_INCLUDE_PATH})
        MESSAGE(STATUS "Detected MacPorts installation: ${MACPORTS_PREFIX}")
90 91
    ELSE()
        UNSET(MACPORTS_PREFIX)
92 93 94 95 96 97
    ENDIF()

    IF (${DETECT_HOMEBREW} EQUAL 0)
        SET(CMAKE_LIBRARY_PATH ${HOMEBREW_PREFIX}/lib ${CMAKE_LIBRARY_PATH})
        SET(CMAKE_INCLUDE_PATH ${HOMEBREW_PREFIX}/include ${CMAKE_INCLUDE_PATH})
        MESSAGE(STATUS "Detected Homebrew installation: ${HOMEBREW_PREFIX}")
98 99
    ELSE()
        UNSET(HOMEBREW_PREFIX)
100
    ENDIF()
101 102 103

    UNSET(DETECT_HOMEBREW)
    UNSET(DETECT_MACPORTS)
104 105
ENDIF()

106
# Attempt to retrieve git branch and SHA1 hash of current changeset.
107
INCLUDE(GetGitRevisionDescription)
Chris Cantwell's avatar
Chris Cantwell committed
108
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
109

110
# Set library, binary, include, share and doc paths.
Dave Moxey's avatar
Dave Moxey committed
111
SET(LIB_DIR "lib")
Dave Moxey's avatar
Dave Moxey committed
112
IF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE )
Dave Moxey's avatar
Dave Moxey committed
113
    SET(LIB_DIR "lib64")
114 115 116 117 118
ENDIF()
SET(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")

SET(NEKTAR_BIN_DIR bin)
SET(NEKTAR_LIB_DIR ${LIB_DIR})
Dave Moxey's avatar
Dave Moxey committed
119 120 121
SET(NEKTAR_INCLUDE_DIR include/nektar++)
SET(NEKTAR_SHARE_DIR share/nektar++)
SET(NEKTAR_DOC_DIR share/doc/nektar++)
Dave Moxey's avatar
Dave Moxey committed
122
SET(NEKTAR_CMAKE_DIR ${LIB_DIR}/nektar++/cmake)
123

124 125 126 127 128 129 130 131 132 133 134 135
# Set ThirdParty locations.
SET(TPSRC   ${CMAKE_SOURCE_DIR}/ThirdParty)
SET(TPBUILD ${CMAKE_BINARY_DIR}/ThirdParty)
SET(TPDIST  ${CMAKE_BINARY_DIR}/ThirdParty/dist)
SET(TPINC   ${CMAKE_INSTALL_PREFIX}/include/ThirdParty)
SET(TPLIB   ${CMAKE_INSTALL_PREFIX}/${NEKTAR_LIB_DIR}/nektar++/thirdparty)

# Create ThirdParty source directory if it doesn't exist already.
IF (NOT EXISTS ${TPSRC})
    FILE(MAKE_DIRECTORY ${TPSRC})
ENDIF ()

136
# Build shared libraries.
137 138 139 140 141 142
SET(NEKTAR_LIBRARY_TYPE "SHARED")

# Set up RPATH
SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
Dave Moxey's avatar
Dave Moxey committed
143
     "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}" isSystemDir)
144
IF("${isSystemDir}" STREQUAL "-1")
145
    SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}" "${TPLIB}/")
Dave Moxey's avatar
Dave Moxey committed
146 147 148
ELSE()
    SET(CMAKE_INSTALL_RPATH "${TPLIB}")
ENDIF()
149

150 151
# Enable the use of @rpath in macOS install names so that we can use multiple
# third-party directories.
152
IF(NOT DEFINED CMAKE_MACOSX_RPATH)
153
    SET(CMAKE_MACOSX_RPATH 1)
154 155
ENDIF()

156 157 158 159 160 161 162 163
# Components of the Nektar++ package to build
OPTION(NEKTAR_BUILD_LIBRARY    "Build main Nektar++ libraries." ON)
OPTION(NEKTAR_BUILD_DEMOS      "Build demonstration codes."     ON)
OPTION(NEKTAR_BUILD_SOLVERS    "Build example solvers."         ON)
OPTION(NEKTAR_BUILD_UTILITIES  "Build utilities."               ON)
OPTION(NEKTAR_BUILD_UNIT_TESTS "Build unit tests."              ON)
OPTION(NEKTAR_BUILD_TESTS      "Build regression tests."        ON)
OPTION(NEKTAR_BUILD_TIMINGS    "Build benchmark timing codes."  OFF)
Dave Moxey's avatar
Dave Moxey committed
164
OPTION(NEKTAR_BUILD_PYTHON     "Build Nektar++ Python bindings" OFF)
165

166
OPTION(NEKTAR_TEST_ALL "Include full set of regression tests to this build." OFF)
167 168
OPTION(NEKTAR_TEST_USE_HOSTFILE "Use a hostfile to explicitly specify number of
slots." OFF)
169

170 171 172
OPTION(NEKTAR_ERROR_ON_WARNINGS "Use -Werror to make warnings stop compilation." ON)
MARK_AS_ADVANCED(NEKTAR_ERROR_ON_WARNINGS)

173
# Meshing utilities and library
174 175 176
IF (NOT WIN32)
    OPTION(NEKTAR_USE_MESHGEN "Build mesh generation utilities." OFF)
ENDIF()
177

178 179 180 181
# Build options
OPTION(NEKTAR_FULL_DEBUG "Enable Full Debugging." OFF)
MARK_AS_ADVANCED(NEKTAR_FULL_DEBUG)

182
IF (${CMAKE_COMPILER_IS_GNUCXX})
183 184
    OPTION(NEKTAR_ENABLE_PROFILE "Uses -pg compiler flag" OFF)
    MARK_AS_ADVANCED(NEKTAR_ENABLE_PROFILE)
185
ENDIF (${CMAKE_COMPILER_IS_GNUCXX})
186

Dave Moxey's avatar
Dave Moxey committed
187
# Memory pools
188 189 190 191
OPTION(NEKTAR_USE_MEMORY_POOLS
    "Use memory pools to accelerate memory allocation." ON)
MARK_AS_ADVANCED(NEKTAR_USE_MEMORY_POOLS)

192 193 194 195 196 197 198 199
# Thread safety
OPTION(NEKTAR_USE_THREAD_SAFETY
    "Guarantee thread safety in certain core Nektar++ classes." OFF)
MARK_AS_ADVANCED(NEKTAR_USE_THREAD_SAFETY)
IF (NEKTAR_USE_THREAD_SAFETY)
    ADD_DEFINITIONS(-DNEKTAR_USE_THREAD_SAFETY)
ENDIF()

Dave Moxey's avatar
Dave Moxey committed
200 201 202 203 204 205
# Disable backups
OPTION(NEKTAR_DISABLE_BACKUPS "Disable automatic backup file creation" OFF)
IF (NEKTAR_DISABLE_BACKUPS)
    ADD_DEFINITIONS(-DNEKTAR_DISABLE_BACKUPS)
ENDIF()

206 207 208
IF (MSVC)
    # Needed for M_PI to be visible in visual studio.
    ADD_DEFINITIONS(-D_USE_MATH_DEFINES)
209

210
    # Removes the warnings about unsafe methods such as strcpy, std::copy,
211
    # memcmp, etc.
212 213
    ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_DEPRECATE)
ENDIF()
214 215 216 217

# Include Nektar++ common macros
INCLUDE (NektarCommon)

218
# Set various ThirdParty locations
219 220 221 222 223 224 225
OPTION(THIRDPARTY_USE_SSL "Use secure HTTP connection to download third-party files." OFF)
IF (THIRDPARTY_USE_SSL)
    SET(TPURL https://www.nektar.info/thirdparty)
ELSE()
    SET(TPURL http://www.nektar.info/thirdparty)
ENDIF()

226
# Find ThirdParty libraries and headers.
227 228 229 230
# --------------------------------------

# Need to find MPI first, as other packages depend on the compiler wrappers
INCLUDE (ThirdPartyMPI)
231 232
INCLUDE (ThirdPartyTinyxml)
INCLUDE (ThirdPartyMetis)
233
INCLUDE (ThirdPartyHDF5)
234
INCLUDE (ThirdPartyScotch)
235
INCLUDE (ThirdPartyZlib)
236
INCLUDE (ThirdPartyBoost)
Dave Moxey's avatar
Dave Moxey committed
237
INCLUDE (ThirdPartyPython)
238 239 240
INCLUDE (ThirdPartyFFTW)
INCLUDE (ThirdPartyArpack)
INCLUDE (ThirdPartyVTK)
Michael Turner's avatar
Michael Turner committed
241
INCLUDE (ThirdPartyOCE)
Michael Turner's avatar
Michael Turner committed
242
INCLUDE (ThirdPartyTriangle)
Michael Turner's avatar
Michael Turner committed
243
INCLUDE (ThirdPartyTetGen)
244
INCLUDE (ThirdPartyCCM)
Dave Moxey's avatar
Dave Moxey committed
245
INCLUDE (ThirdPartyBlasLapack)
Kilian Lackhove's avatar
Kilian Lackhove committed
246
INCLUDE (ThirdPartyCwipi)
Michael Turner's avatar
Michael Turner committed
247
INCLUDE (FindCFI)
248

249 250
INCLUDE (Doxygen)

251 252 253 254 255 256 257 258 259 260
IF( NEKTAR_USE_TINYXML_STL )
    ADD_DEFINITIONS( -DTIXML_USE_STL)
ENDIF( NEKTAR_USE_TINYXML_STL )

IF( NEKTAR_USE_MEMORY_POOLS )
    ADD_DEFINITIONS(-DNEKTAR_MEMORY_POOL_ENABLED)
ELSE( NEKTAR_USE_MEMORY_POOLS )
    REMOVE_DEFINITIONS(-DNEKTAR_MEMORY_POOL_ENABLED)
ENDIF( NEKTAR_USE_MEMORY_POOLS )

Kilian Lackhove's avatar
Kilian Lackhove committed
261 262
INCLUDE (ThirdPartyPETSc)

263 264 265 266 267 268 269 270 271 272 273 274 275
SET(Boost_USE_STATIC_LIBS OFF)
IF( WIN32 )
    # The auto-linking feature has problems with USE_STATIC_LIBS off, so we use
    # BOOST_ALL_NO_LIB to turn it off.
    # Several boost libraries headers aren't configured correctly if
    # USE_STATIC_LIBS is off, so we explicitly say they are dynamic with the
    # remaining definitions.
    ADD_DEFINITIONS(-DBOOST_ALL_NO_LIB -DBOOST_PROGRAM_OPTIONS_DYN_LINK -DBOOST_IOSTREAMS_DYN_LINK -DBOOST_THREAD_DYN_LINK)
ENDIF( )

# Set up include directories. Include work-around for -isystem for CMake (see
# bug 0010837) to avoid unnecessary compiler warnings for third-party libs.
IF (APPLE)
276 277
  SET(CMAKE_INCLUDE_SYSTEM_FLAG_C   "-isystem ")
  SET(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
278 279 280 281
ENDIF (APPLE)

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})

282 283
# Build active components. Add utilities and solvers directories first, because
# that allows us to detect library dependencies automatically.
284 285 286 287
IF (NEKTAR_BUILD_LIBRARY)
    INCLUDE_DIRECTORIES(library)
ENDIF()

288 289 290 291 292 293
INCLUDE_DIRECTORIES(utilities)
ADD_SUBDIRECTORY(utilities)

INCLUDE_DIRECTORIES(solvers)
ADD_SUBDIRECTORY(solvers)

294
IF (NEKTAR_BUILD_LIBRARY)
295 296 297
    # List of Nektar++ libraries will be rebuilt every configuration.
    SET(NEKTAR++_LIBRARIES "" CACHE INTERNAL "")

298
    ADD_SUBDIRECTORY(library)
Dave Moxey's avatar
Dave Moxey committed
299
    INSTALL(EXPORT Nektar++Libraries DESTINATION ${NEKTAR_CMAKE_DIR} COMPONENT dev)
300 301 302 303 304
ENDIF (NEKTAR_BUILD_LIBRARY)

IF (NEKTAR_BUILD_TESTS)
    INCLUDE_DIRECTORIES(tests)
    ADD_SUBDIRECTORY(tests)
305 306 307
    IF (NEKTAR_USE_MPI)
        OPTION(NEKTAR_TEST_FORCEMPIEXEC  "Force all tests to be run through the MPI job launcher."  OFF)
    ENDIF (NEKTAR_USE_MPI)
308 309
ENDIF (NEKTAR_BUILD_TESTS)

310 311
# Compile list of definitions for Nektar++Config.cmake input file. We exclude
# vtk definitions which should not be required for external builds.
312 313 314 315
SET(NEKTAR_DEFINITIONS "")
GET_DIRECTORY_PROPERTY(
    NEKTAR_DEFINITIONS_LIST DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
FOREACH(def ${NEKTAR_DEFINITIONS_LIST})
316 317 318
    IF (NOT def MATCHES "^vtk")
        SET(NEKTAR_DEFINITIONS "${NEKTAR_DEFINITIONS} -D${def}")
    ENDIF()
319 320
ENDFOREACH()

321 322
# Write out Nektar++ build configuration
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/Nektar++Config.cmake.in
323
               ${CMAKE_BINARY_DIR}/Nektar++Config.cmake @ONLY)
324 325 326

# Install Nektar++ CMake configuration file
INSTALL(FILES ${CMAKE_BINARY_DIR}/Nektar++Config.cmake
Dave Moxey's avatar
Dave Moxey committed
327
    DESTINATION ${NEKTAR_CMAKE_DIR}
328
    COMPONENT dev)
329

330
INSTALL(CODE "FILE(GLOB tplibs ${TPDIST}/lib/*${CMAKE_SHARED_LIBRARY_SUFFIX}*)
331 332 333
    IF (NOT tplibs STREQUAL \"\")
        FILE(INSTALL \${tplibs} DESTINATION ${TPLIB})
    ENDIF()
334 335
")

336
# Install ThirdParty headers to subdirectory of ${NEKTAR_INCLUDE_DIR}
337 338 339 340 341
INSTALL(DIRECTORY ${TPDIST}/include/
    DESTINATION ${NEKTAR_INCLUDE_DIR}/ThirdParty
    COMPONENT dev
    OPTIONAL
    )
342

343
ADD_SUBDIRECTORY(docs)