CMakeLists.txt 12 KB
Newer Older
1
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)
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 8 9 10 11 12 13 14 15 16
PROJECT(Nektar++ C CXX)


INCLUDE(CheckLanguage)

CHECK_LANGUAGE(Fortran)
IF(CMAKE_Fortran_COMPILER)
  ENABLE_LANGUAGE(Fortran)
ELSE()
  MESSAGE(STATUS "No Fortran support")
ENDIF()
17 18 19 20 21 22 23 24 25 26 27 28 29

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

30
# Add support for CMAKE_DEPENDENT_OPTION
31
INCLUDE(CMakeDependentOption)
32 33

# Enable CTest.
34 35 36 37
ENABLE_TESTING()

# Use the CMake 2.4 policy for CMake 2.6
IF(COMMAND cmake_policy)
38 39 40 41 42 43 44
    CMAKE_POLICY(SET CMP0003 OLD)

    # Silence warnings when using generator expressions in
    # TARGET_LINK_LIBRARIES.
    IF(POLICY CMP0022)
        CMAKE_POLICY(SET CMP0022 NEW)
    ENDIF()
45 46 47 48
ENDIF(COMMAND cmake_policy)

# Find the modules included with Nektar
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
49 50 51 52

# 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)
53 54
ENDIF()

55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
# Find default search paths for OS X; adapted from Stack Overflow question
# 1487752
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}")
73 74
    ELSE()
        UNSET(MACPORTS_PREFIX)
75 76 77 78 79 80
    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}")
81 82
    ELSE()
        UNSET(HOMEBREW_PREFIX)
83
    ENDIF()
84 85 86

    UNSET(DETECT_HOMEBREW)
    UNSET(DETECT_MACPORTS)
87 88
ENDIF()

89
# Attempt to retrieve git branch and SHA1 hash of current changeset.
90
INCLUDE(GetGitRevisionDescription)
Chris Cantwell's avatar
Chris Cantwell committed
91
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
92

93
# Set library, binary, include, share and doc paths.
94
SET(LIB_DIR "lib/nektar++-${NEKTAR_VERSION}")
Dave Moxey's avatar
Dave Moxey committed
95
IF( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE )
96
    SET(LIB_DIR "lib64/nektar++-${NEKTAR_VERSION}")
97 98 99 100 101
ENDIF()
SET(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")

SET(NEKTAR_BIN_DIR bin)
SET(NEKTAR_LIB_DIR ${LIB_DIR})
102 103 104
SET(NEKTAR_INCLUDE_DIR include/nektar++-${NEKTAR_VERSION})
SET(NEKTAR_SHARE_DIR share/nektar++-${NEKTAR_VERSION})
SET(NEKTAR_DOC_DIR share/doc/nektar++-${NEKTAR_VERSION})
105 106

# Build shared libraries.
107 108 109 110 111 112
SET(NEKTAR_LIBRARY_TYPE "SHARED")

# Set up RPATH
SET(CMAKE_SKIP_BUILD_RPATH  FALSE)
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
113 114 115 116
IF (APPLE)
    SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
    SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
ENDIF()
117 118 119 120 121 122
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
	"${CMAKE_INSTALL_PREFIX}/${LIB_DIR}" isSystemDir)
IF("${isSystemDir}" STREQUAL "-1")
	SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${LIB_DIR}")
ENDIF("${isSystemDir}" STREQUAL "-1")

123 124 125 126 127 128 129
# Get rid of OS X RPATH warnings -- we should set this to 1 once we reach
# required minimum cmake version of 3.0.0 and configure it in a more sane
# fashion.
IF(NOT DEFINED CMAKE_MACOSX_RPATH)
    SET(CMAKE_MACOSX_RPATH 0)
ENDIF()

130 131 132 133 134 135 136 137
# 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)
138 139
OPTION(NEKTAR_BUILD_PACKAGES   "Build Nektar++ binary packages" OFF)
MARK_AS_ADVANCED(NEKTAR_BUILD_PACKAGES)
140

141
OPTION(NEKTAR_TEST_ALL "Include full set of regression tests to this build." OFF)
142 143
OPTION(NEKTAR_TEST_USE_HOSTFILE "Use a hostfile to explicitly specify number of
slots." OFF)
144

145
# Meshing utilities and library
146 147 148
IF (NOT WIN32)
    OPTION(NEKTAR_USE_MESHGEN "Build mesh generation utilities." OFF)
ENDIF()
149

150 151 152 153
# Build options
OPTION(NEKTAR_FULL_DEBUG "Enable Full Debugging." OFF)
MARK_AS_ADVANCED(NEKTAR_FULL_DEBUG)

154
IF (${CMAKE_COMPILER_IS_GNUCXX})
155 156
    OPTION(NEKTAR_ENABLE_PROFILE "Uses -pg compiler flag" OFF)
    MARK_AS_ADVANCED(NEKTAR_ENABLE_PROFILE)
157
ENDIF (${CMAKE_COMPILER_IS_GNUCXX})
158

159
OPTION(NEKTAR_USE_EXPRESSION_TEMPLATES
160
    "Use Expression templates." OFF)
161 162 163
MARK_AS_ADVANCED(NEKTAR_USE_EXPRESSION_TEMPLATES)

# BLAS Support
164 165 166
CMAKE_DEPENDENT_OPTION(NEKTAR_USE_SYSTEM_BLAS_LAPACK
    "Use the system provided blas and lapack libraries" ON
    "UNIX; NOT APPLE; NOT NEKTAR_USE_OPENBLAS; NOT NEKTAR_USE_MKL; NOT NEKTAR_USE_ACML; NOT NEKTAR_USE_ACCELERATE_FRAMEWORK" OFF)
167 168
CMAKE_DEPENDENT_OPTION(NEKTAR_USE_OPENBLAS
    "Use OpenBLAS library as a substitute to native BLAS." OFF
169
    "NOT NEKTAR_USE_SYSTEM_BLAS_LAPACK" OFF)
170 171
CMAKE_DEPENDENT_OPTION(NEKTAR_USE_ACML
    "Use the AMD Core Math Library (ACML) for BLAS and Lapack support." OFF
172
    "NOT NEKTAR_USE_SYSTEM_BLAS_LAPACK" OFF)
173 174
CMAKE_DEPENDENT_OPTION(NEKTAR_USE_MKL
    "Use the Intel Math Kernel Library (MKL) for BLAS and Lapack support." OFF
175
    "NOT NEKTAR_USE_SYSTEM_BLAS_LAPACK" OFF)
176 177
CMAKE_DEPENDENT_OPTION(NEKTAR_USE_ACCELERATE_FRAMEWORK
    "Use the Mac Accelerate Framework for BLAS and Lapack support." ON
178
    "NOT NEKTAR_USE_SYSTEM_BLAS_LAPACK; APPLE" OFF)
179 180
CMAKE_DEPENDENT_OPTION(NEKTAR_USE_WIN32_LAPACK
    "Use Win32 Lapack provided with the Third Party Distribution."
181
    ON "NOT NEKTAR_USE_SYSTEM_BLAS_LAPACK; WIN32" OFF)
182

Dave Moxey's avatar
Dave Moxey committed
183
# Memory pools
184 185 186 187
OPTION(NEKTAR_USE_MEMORY_POOLS
    "Use memory pools to accelerate memory allocation." ON)
MARK_AS_ADVANCED(NEKTAR_USE_MEMORY_POOLS)

188 189 190
IF (MSVC)
    # Needed for M_PI to be visible in visual studio.
    ADD_DEFINITIONS(-D_USE_MATH_DEFINES)
191

192
    # Removes the warnings about unsafe methods such as strcpy, std::copy,
193
    # memcmp, etc.
194 195
    ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_DEPRECATE)
ENDIF()
196 197 198 199

# Include Nektar++ common macros
INCLUDE (NektarCommon)

200
# Set various ThirdParty locations
201 202 203 204 205 206 207
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()

208
SET(TPSRC   ${CMAKE_SOURCE_DIR}/ThirdParty)
209
SET(TPBUILD ${CMAKE_BINARY_DIR}/ThirdParty)
210
SET(TPDIST  ${CMAKE_BINARY_DIR}/ThirdParty/dist)
211
SET(TPINC   ${CMAKE_INSTALL_PREFIX}/include/ThirdParty)
212
SET(TPLIB   ${CMAKE_INSTALL_PREFIX}/${NEKTAR_LIB_DIR})
213 214

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

219
# Find ThirdParty libraries and headers.
220 221 222
INCLUDE (ThirdPartyTinyxml)
INCLUDE (ThirdPartyLoki)
INCLUDE (ThirdPartyMetis)
223
INCLUDE (ThirdPartyHDF5)
224
INCLUDE (ThirdPartyScotch)
225
INCLUDE (ThirdPartyZlib)
226
INCLUDE (ThirdPartyBoost)
227 228 229 230
INCLUDE (ThirdPartyFFTW)
INCLUDE (ThirdPartyArpack)
INCLUDE (ThirdPartyMPI)
INCLUDE (ThirdPartyVTK)
Michael Turner's avatar
Michael Turner committed
231
INCLUDE (ThirdPartyOCE)
Michael Turner's avatar
Michael Turner committed
232
INCLUDE (ThirdPartyTetGen)
233
INCLUDE (ThirdPartyCCM)
234

235 236
INCLUDE (Doxygen)

237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
IF( NEKTAR_USE_MKL )
    INCLUDE (FindMKL)
ENDIF( NEKTAR_USE_MKL )

IF( NEKTAR_USE_OPENBLAS )
    INCLUDE (FindOpenBlas)
ENDIF( NEKTAR_USE_OPENBLAS )

IF( NEKTAR_USE_ACCELERATE_FRAMEWORK )
    INCLUDE (FindAccelerateFramework)
ENDIF( NEKTAR_USE_ACCELERATE_FRAMEWORK )

IF( NEKTAR_USE_ACML )
    INCLUDE (FindACML)
ENDIF( NEKTAR_USE_ACML )

IF( NEKTAR_USE_WIN32_LAPACK )
    INCLUDE (FindWin32Lapack)
ENDIF( NEKTAR_USE_WIN32_LAPACK )

IF( NEKTAR_USE_SYSTEM_BLAS_LAPACK )
Michael Turner's avatar
Michael Turner committed
258
    INCLUDE(ThirdPartyBlasLapack)
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
ENDIF( NEKTAR_USE_SYSTEM_BLAS_LAPACK )

IF( NEKTAR_USE_TINYXML_STL )
    ADD_DEFINITIONS( -DTIXML_USE_STL)
ENDIF( NEKTAR_USE_TINYXML_STL )

IF( NEKTAR_USE_EXPRESSION_TEMPLATES )
    ADD_DEFINITIONS(-DNEKTAR_USE_EXPRESSION_TEMPLATES -DNEKTAR_USING_CMAKE)
ENDIF( NEKTAR_USE_EXPRESSION_TEMPLATES )

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
275 276
INCLUDE (ThirdPartyPETSc)

277 278 279 280 281 282 283 284 285 286 287 288 289
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)
290 291
  SET(CMAKE_INCLUDE_SYSTEM_FLAG_C   "-isystem ")
  SET(CMAKE_INCLUDE_SYSTEM_FLAG_CXX "-isystem ")
292 293 294 295
ENDIF (APPLE)

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})

296 297 298 299 300 301 302 303
# Build active components. Add utilities and solvers directories first, because
# that allows us to detect library dependencies automatically.
INCLUDE_DIRECTORIES(utilities)
ADD_SUBDIRECTORY(utilities)

INCLUDE_DIRECTORIES(solvers)
ADD_SUBDIRECTORY(solvers)

304
IF (NEKTAR_BUILD_LIBRARY)
305 306 307
    # List of Nektar++ libraries will be rebuilt every configuration.
    SET(NEKTAR++_LIBRARIES "" CACHE INTERNAL "")

308 309
    INCLUDE_DIRECTORIES(library)
    ADD_SUBDIRECTORY(library)
310
    INSTALL(EXPORT Nektar++Libraries DESTINATION ${LIB_DIR}/cmake COMPONENT dev)
311 312 313 314 315
ENDIF (NEKTAR_BUILD_LIBRARY)

IF (NEKTAR_BUILD_TESTS)
    INCLUDE_DIRECTORIES(tests)
    ADD_SUBDIRECTORY(tests)
316 317 318
    IF (NEKTAR_USE_MPI)
        OPTION(NEKTAR_TEST_FORCEMPIEXEC  "Force all tests to be run through the MPI job launcher."  OFF)
    ENDIF (NEKTAR_USE_MPI)
319 320
ENDIF (NEKTAR_BUILD_TESTS)

321 322
# Compile list of definitions for Nektar++Config.cmake input file. We exclude
# vtk definitions which should not be required for external builds.
323 324 325 326
SET(NEKTAR_DEFINITIONS "")
GET_DIRECTORY_PROPERTY(
    NEKTAR_DEFINITIONS_LIST DIRECTORY ${CMAKE_SOURCE_DIR} COMPILE_DEFINITIONS)
FOREACH(def ${NEKTAR_DEFINITIONS_LIST})
327 328 329
    IF (NOT def MATCHES "^vtk")
        SET(NEKTAR_DEFINITIONS "${NEKTAR_DEFINITIONS} -D${def}")
    ENDIF()
330 331
ENDFOREACH()

332 333
# Write out Nektar++ build configuration
CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/cmake/Nektar++Config.cmake.in
334
               ${CMAKE_BINARY_DIR}/Nektar++Config.cmake @ONLY)
335 336 337

# Install Nektar++ CMake configuration file
INSTALL(FILES ${CMAKE_BINARY_DIR}/Nektar++Config.cmake
338 339
    DESTINATION ${NEKTAR_LIB_DIR}/cmake/
    COMPONENT dev)
340 341

# Install ThirdParty headers to subdirectory of ${NEKTAR_INCLUDE_DIR}
342 343
INSTALL(DIRECTORY ${TPDIST}/include/
    DESTINATION ${NEKTAR_INCLUDE_DIR}/ThirdParty
Dave Moxey's avatar
Dave Moxey committed
344
    COMPONENT dev
345
)
346

Dave Moxey's avatar
Dave Moxey committed
347 348
# Install ThirdParty libraries into ${NEKTAR_LIB_DIR}. These are shipped with
# the LibUtilities library.
349 350
INSTALL(DIRECTORY ${TPDIST}/lib/
    DESTINATION ${NEKTAR_LIB_DIR}
Dave Moxey's avatar
Dave Moxey committed
351
    COMPONENT libutilities
352
)
353

354
ADD_SUBDIRECTORY(docs)
355 356

IF(NEKTAR_BUILD_PACKAGES)
Dave Moxey's avatar
Dave Moxey committed
357
    ADD_SUBDIRECTORY(pkg)
358
ENDIF(NEKTAR_BUILD_PACKAGES)