CMakeLists.txt 19 KB
Newer Older
1
# Copyright (C) 2009-2018 The ESPResSo project
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
# Copyright (C) 2009,2010 
#   Max-Planck-Institute for Polymer Research, Theory Group
#
# This file is part of ESPResSo.
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
20

21
cmake_minimum_required(VERSION 3.0)
22
include(FeatureSummary)
23
project(ESPResSo)
24
include(cmake/FindPythonModule.cmake)
25 26 27

enable_language(CXX)

28
set(PROJECT_VERSION "4.0-dev")
29 30 31 32
string(REGEX REPLACE "^([1-9]+)\\.[0-9]+.*$" "\\1" SOVERSION "${PROJECT_VERSION}")
if (NOT ${SOVERSION} MATCHES "^[1-9]+$")
  message(FATAL_ERROR "Could not determind SOVERSION from ${PROJECT_VERSION}")
endif (NOT ${SOVERSION} MATCHES "^[1-9]+$")
33 34

######################################################################
35
# CMake internal vars
36
######################################################################
37 38 39 40

# Cmake modules/macros are in a subdirectory to keep this file cleaner
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

41 42
# If the version is smaller than 3.4, use custom find HDF5 module
# else, use prefer parallel feature of default module.
Michael Kuron's avatar
Michael Kuron committed
43
if(CMAKE_VERSION VERSION_LESS 3.4)
44 45 46 47 48 49
  set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
                        ${CMAKE_CURRENT_SOURCE_DIR}/cmake/hdf5)
else()
  set(HDF5_PREFER_PARALLEL 1)
endif()

50 51 52 53
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
endif(NOT CMAKE_BUILD_TYPE)

54 55 56 57 58 59 60
# Parse repository info from git if available
include(version)

configure_file(
  ${CMAKE_SOURCE_DIR}/src/version.hpp.in
  ${CMAKE_BINARY_DIR}/src/version.hpp
  )
61

62 63 64
# On Mac OS X, first look for other packages, then frameworks
set(CMAKE_FIND_FRAMEWORK LAST)

65
######################################################################
66
# User input options
67 68
######################################################################

69 70
set(WITH_PYTHON yes)

71
option(WITH_GSL "Build with GSL support" ON)
72
option(WITH_CUDA   "Build with GPU support"  ON)
73
option(WITH_HDF5   "Build with HDF5 support" ON)
Florian Weik's avatar
Florian Weik committed
74
option(WITH_TESTS  "Enable tests"            ON)
75
option(WITH_SCAFACOS "Build with Scafacos support" OFF)
Jean-Noël Grad's avatar
Jean-Noël Grad committed
76
option(WITH_BENCHMARKS "Enable benchmarks"   OFF)
77
option(WITH_VALGRIND_INSTRUMENTATION "Build with valgrind instrumentation markers" OFF)
Michael Kuron's avatar
Michael Kuron committed
78 79 80
if( CMAKE_VERSION VERSION_GREATER 3.5.2 AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" )
  option(WITH_CLANG_TIDY "Run Clang-Tidy during compilation" OFF)
endif()
81 82 83 84 85 86 87 88
if( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "GNU" )
  option(WITH_COVERAGE "Generate code coverage report" OFF)
  option(WITH_ASAN "Build with address sanitizer" OFF)
  option(WITH_UBSAN "Build with undefined behavior sanitizer" OFF)
endif()
if( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE )
  option(WITH_MSAN "Build with memory sanitizer (experimental; requires a memory-sanitized Python interpreter)" OFF)
endif()
89
option(WARNINGS_ARE_ERRORS "Treat warnings as errors during compilation" OFF)
Kai Szuttor's avatar
Kai Szuttor committed
90 91 92 93 94
option(WITH_CCACHE "Use ccache compiler invocation." OFF)

if(WITH_CCACHE)
  find_program(CCACHE ccache)
  if(CCACHE)
Kai Szuttor's avatar
Kai Szuttor committed
95
    message(STATUS "Found ccache ${CCACHE}")
Kai Szuttor's avatar
Kai Szuttor committed
96
    if(CMAKE_VERSION VERSION_LESS 3.4)
Kai Szuttor's avatar
Kai Szuttor committed
97 98
      set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE})
      set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${CCACHE})
Kai Szuttor's avatar
Kai Szuttor committed
99 100 101 102 103 104 105 106
    else()
      set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE} CACHE STRING "ccache executable")
    endif()
  else()
      message(FATAL_ERROR "ccache not found.")
  endif(CCACHE)
endif(WITH_CCACHE)

107

Florian Weik's avatar
Florian Weik committed
108 109 110
# Write compile commands to file, for various tools...
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

111
# choose the name of the config file
Florian Weik's avatar
Florian Weik committed
112
set(MYCONFIG_NAME "myconfig.hpp"
113 114
  CACHE STRING "Default name of the local config file")

115 116 117
# Check which config file to use
include(MyConfig)

118
######################################################################
Florian Weik's avatar
Florian Weik committed
119 120 121 122 123
# Pretty function
######################################################################

include(CheckCXXSourceCompiles)

124
set(__PRETTYFUNC__ __func__)
Florian Weik's avatar
Florian Weik committed
125 126 127 128
foreach(func_name __PRETTY_FUNCTION__ __FUNCTION__)
   check_cxx_source_compiles("
     #include <string>
     int main() { std::string(${func_name}); }
129
     " result${func_name})
Florian Weik's avatar
Florian Weik committed
130 131 132 133 134 135 136
   if(result${func_name})
     set(__PRETTYFUNC__ ${func_name})
     break()
   endif(result${func_name})
endforeach(func_name __PRETTY_FUNCTION__ __FUNCTION__)

######################################################################
137 138 139
# Libraries
######################################################################

Florian Weik's avatar
Florian Weik committed
140
if (WITH_CUDA)
141
  if (EXISTS "$ENV{NVCC}" AND NOT CUDA_NVCC_EXECUTABLE)
142
    set(CUDA_NVCC_EXECUTABLE $ENV{NVCC} CACHE FILEPATH "Path to CUDA compiler.")
143
  endif()
Michael Kuron's avatar
Michael Kuron committed
144
  if (CUDA_NVCC_EXECUTABLE STREQUAL CMAKE_CXX_COMPILER)
145
    message(STATUS "Found CUDA-capable host compiler: ${CUDA_NVCC_EXECUTABLE}")
146 147 148 149 150 151 152 153
    if( CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang" )
        execute_process(COMMAND ${CUDA_NVCC_EXECUTABLE} ${CMAKE_CXX_FLAGS} --verbose
                ERROR_VARIABLE CUDA_DIR)
        string(REGEX REPLACE "^.*Found CUDA installation: ([^,]+).*\$" "\\1" CUDA_DIR "${CUDA_DIR}")
        message(STATUS "Found CUDA installation: ${CUDA_DIR}")
    else()
        set(CUDA_DIR "/usr/local/cuda")
    endif()
154 155
    find_library(CUDART_LIBRARY NAMES cudart PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH)
    find_library(CUFFT_LIBRARY NAMES cufft PATHS ${CUDA_DIR}/lib64 ${CUDA_DIR}/lib /usr/local/nvidia/lib NO_DEFAULT_PATH)
156 157
    list(APPEND LIBRARIES ${CUDART_LIBRARY})
    list(APPEND LIBRARIES ${CUFFT_LIBRARY})
158
    set(CUDA 1)
159

160 161 162
    set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} --cuda-gpu-arch=sm_30")
    if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 3.8.9)
      set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} --cuda-gpu-arch=sm_52")
163
    endif()
164

165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
    function(cuda_include_directories)
      include_directories(${ARGV})
    endfunction()
    function(cuda_add_library)
      set(options STATIC SHARED MODULE EXCLUDE_FROM_ALL)
      set(oneValueArgs)
      set(multiValueArgs)
      cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
      list(REMOVE_AT ARG_UNPARSED_ARGUMENTS 0)
      set_source_files_properties(${ARG_UNPARSED_ARGUMENTS} PROPERTIES LANGUAGE "CXX" COMPILE_FLAGS "${CUDA_NVCC_FLAGS}")
      add_library(${ARGV})
      set_target_properties(${ARGV0} PROPERTIES LINKER_LANGUAGE "CXX")
      target_link_libraries(${ARGV0} ${CUDA_LIBRARY} ${CUDART_LIBRARY})
    endfunction()
    function(CUDA_ADD_CUFFT_TO_TARGET target)
180
      target_link_libraries(${target} ${CUFFT_LIBRARY})
181 182
    endfunction()
  else()
183 184
    list(APPEND CMAKE_MODULE_PATH "/opt/rocm/hip/cmake")
    find_package(HIP 1.5.18494 QUIET MODULE)
185
    if(HIP_FOUND)
Michael Kuron's avatar
Michael Kuron committed
186
      set(HCC_PATH "${HIP_ROOT_DIR}")
187 188
      find_package(HIP MODULE)
      message(STATUS "Found HIP compiler: ${HIP_HIPCC_EXECUTABLE}")
189
      set(CUDA 1)
Michael Kuron's avatar
Michael Kuron committed
190
      list(APPEND HIP_HCC_FLAGS "-Wno-macro-redefined -Wno-duplicate-decl-specifier")
191 192 193 194 195 196
      HIP_INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/src/core" "${CMAKE_SOURCE_DIR}/src/core")
      function(cuda_include_directories)
        HIP_INCLUDE_DIRECTORIES(${ARGV})
      endfunction()
      function(cuda_add_library)
        HIP_ADD_LIBRARY(${ARGV})
Michael Kuron's avatar
Michael Kuron committed
197
        set_target_properties(${ARGV0} PROPERTIES LINKER_LANGUAGE HIP)
198 199 200 201 202 203 204 205 206 207
      endfunction()
      find_library(ROCFFT_LIB name "rocfft" PATHS "${HIP_ROOT_DIR}/lib")
      function(CUDA_ADD_CUFFT_TO_TARGET target)
        target_link_libraries(${target} "${ROCFFT_LIB}")
      endfunction()
    else()
      find_package(CUDA 7.0)
      if(CUDA_FOUND)
        list(APPEND LIBRARIES ${CUDA_CUFFT_LIBRARIES})
        list(APPEND LIBRARIES ${CUDA_LIBRARIES})
208 209 210 211 212
        if(NOT CUDA_NVCC_EXECUTABLE STREQUAL "${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc")
          get_filename_component(NVCC_EXECUTABLE_DIRNAME "${CUDA_NVCC_EXECUTABLE}" DIRECTORY)
          get_filename_component(NVCC_EXECUTABLE_DIRNAME "${NVCC_EXECUTABLE_DIRNAME}" DIRECTORY)
          message(WARNING "Your nvcc (${CUDA_NVCC_EXECUTABLE}) does not appear to match your CUDA libraries (in ${CUDA_TOOLKIT_ROOT_DIR}). While Espresso will still compile, you might get unexpected crashes. Please point CUDA_TOOLKIT_ROOT_DIR to your CUDA toolkit path, e.g. by adding -DCUDA_TOOLKIT_ROOT_DIR=${NVCC_EXECUTABLE_DIRNAME} to your cmake command.")
        endif()
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
        set(CUDA 1)

        set(CUDA_NVCC_FLAGS_DEBUG "${CUDA_NVCC_FLAGS_DEBUG} -g -G")
        set(CUDA_NVCC_FLAGS_RELEASE "${CUDA_NVCC_FLAGS_RELEASE} -O3 -DNDEBUG")
        set(CUDA_NVCC_FLAGS_MINSIZEREL "${CUDA_NVCC_FLAGS_MINSIZEREL} -Os -DNDEBUG")
        set(CUDA_NVCC_FLAGS_RELWITHDEBINFO "${CUDA_NVCC_FLAGS_RELWITHDEBINFO} -g -G -O2")
        set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -gencode=arch=compute_30,code=sm_30 -gencode=arch=compute_52,code=sm_52 -gencode=arch=compute_52,code=compute_52")
        list(APPEND CUDA_NVCC_FLAGS "-std=c++11")
        if (CUDA_VERSION VERSION_LESS "8.0" AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "5.0")
          list(APPEND CUDA_NVCC_FLAGS "-D_MWAITXINTRIN_H_INCLUDED -D_FORCE_INLINES")
        endif()
        SET(CUDA_PROPAGATE_HOST_FLAGS OFF)

        if (CMAKE_OSX_SYSROOT)
          set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -isysroot -Xcompiler ${CMAKE_OSX_SYSROOT}")
        endif()
      endif(CUDA_FOUND)
    endif()
231
  endif()
232
endif(WITH_CUDA)
Florian Weik's avatar
Florian Weik committed
233

234
find_package(PythonInterp REQUIRED)
235

236
if (WITH_PYTHON)
237
  find_package(Cython 0.23 REQUIRED)
238 239 240
  execute_process(COMMAND ${PYTHON_EXECUTABLE}
                -c "import distutils.sysconfig as cg; print(cg.get_python_inc())"
                OUTPUT_VARIABLE PYTHON_INCLUDE_DIRS OUTPUT_STRIP_TRAILING_WHITESPACE)
241
  find_package(NumPy REQUIRED)
242 243
  if(NOT PYTHON_INSTDIR)
    execute_process(COMMAND ${PYTHON_EXECUTABLE} 
Michael Kuron's avatar
Michael Kuron committed
244
                -c "import distutils.sysconfig as cg; print(cg.get_python_lib(1,0,prefix='${CMAKE_INSTALL_EXEC_PREFIX}'))"
245
                OUTPUT_VARIABLE PYTHON_INSTDIR OUTPUT_STRIP_TRAILING_WHITESPACE)
246
  endif(NOT PYTHON_INSTDIR)
247 248 249 250 251
  if(PYTHON_VERSION_MAJOR EQUAL 2)
    set(CYTHON_FLAGS "-2" CACHE STRING "Flags used by the Cython compiler during all build types.")
  else()
    set(CYTHON_FLAGS "-3" CACHE STRING "Flags used by the Cython compiler during all build types.")
  endif()
252 253 254 255

  if(WARNINGS_ARE_ERRORS)
    set(CYTHON_FLAGS "--warning-errors;${CYTHON_FLAGS}")
  endif()
256
endif(WITH_PYTHON)
257

258 259 260

find_package(FFTW3)
if (FFTW3_FOUND)
Michael Kuron's avatar
Michael Kuron committed
261
  include_directories(SYSTEM ${FFTW3_INCLUDE_DIR})
262 263
  list(APPEND LIBRARIES ${FFTW3_LIBRARIES})
  set(FFTW 3)
264 265
endif(FFTW3_FOUND)

266

267
# If we build either interface turn on script interface
Rudolf Weeber's avatar
Rudolf Weeber committed
268
if (WITH_PYTHON)
269 270 271
  set(WITH_SCRIPT_INTERFACE ON)
endif()

272
# We need the parallel hdf5 version!
Michael Lahnert's avatar
Michael Lahnert committed
273
if (WITH_HDF5)
274 275 276 277 278 279
  find_package(HDF5 "1.8" COMPONENTS C)
  if(HDF5_IS_PARALLEL)
    set(H5MD 1)
    include(FindPythonModule)
    find_python_module(h5py)
    list(APPEND LIBRARIES ${HDF5_LIBRARIES})
Michael Kuron's avatar
Michael Kuron committed
280
    include_directories(SYSTEM ${HDF5_INCLUDE_DIRS})
281 282
    add_feature_info(HDF5 ON "parallel")
  else()
283
    unset(H5MD)
284 285
    unset(HDF5_FOUND)
  endif(HDF5_IS_PARALLEL)
Michael Lahnert's avatar
Michael Lahnert committed
286
endif(WITH_HDF5)
287

288
# Check for the h5xx submodule
289 290
# and try to check it out if not found or update it if found.
if(WITH_HDF5 AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
291 292
  # Try to find git
  find_package(Git)
293 294 295 296 297 298 299 300
  if(GIT_FOUND)
    if (NOT EXISTS "${CMAKE_SOURCE_DIR}/libs/h5xx/.git")
      execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init -- libs/h5xx
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
    else()
      execute_process(COMMAND ${GIT_EXECUTABLE} submodule update -- libs/h5xx
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
    endif()
301
  endif()
302 303
endif()

304 305 306 307 308 309 310 311
if(WITH_SCAFACOS)
  find_package(PkgConfig)
  pkg_check_modules(SCAFACOS scafacos)
  if(SCAFACOS_FOUND)
    set(SCAFACOS 1)
  endif(SCAFACOS_FOUND)
endif(WITH_SCAFACOS)

312
if(WITH_GSL)
Rudolf Weeber's avatar
Rudolf Weeber committed
313
  find_package(GSL)
Rudolf Weeber's avatar
Rudolf Weeber committed
314 315
  if (GSL_FOUND)
    set(GSL 1)
Rudolf Weeber's avatar
Rudolf Weeber committed
316
  endif(GSL_FOUND)
317 318
endif(WITH_GSL)

319 320 321 322 323 324
if(WITH_VALGRIND_INSTRUMENTATION)
  find_package(PkgConfig)
  pkg_check_modules(VALGRIND valgrind)
  if(VALGRIND_FOUND)
    set(VALGRIND_INSTRUMENTATION 1)
    message(STATUS ${VALGRIND_INCLUDE_DIRS})
Michael Kuron's avatar
Michael Kuron committed
325
    include_directories(SYSTEM ${VALGRIND_INCLUDE_DIRS})
326 327 328
  endif(VALGRIND_FOUND)
endif(WITH_VALGRIND_INSTRUMENTATION)

329 330 331 332 333
#######################################################################
# Process MPI settings
#######################################################################

find_package(MPI REQUIRED)
334
# Workaround for https://gitlab.kitware.com/cmake/cmake/issues/18349
335
foreach(_MPI_FLAG ${MPI_CXX_COMPILE_FLAGS})
336 337
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_MPI_FLAG}")
endforeach()
338
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_LINK_FLAGS}")
Michael Kuron's avatar
Michael Kuron committed
339
include_directories(SYSTEM ${MPI_INCLUDE_PATH})
340 341 342
list(APPEND LIBRARIES ${MPI_LIBRARIES})
add_definitions(-DH5XX_USE_MPI)

343 344 345 346
#######################################################################
# Boost
#######################################################################

347

348 349 350 351 352 353
list(APPEND BOOST_COMPONENTS mpi serialization filesystem system)

if(WITH_TESTS)
  list(APPEND BOOST_COMPONENTS unit_test_framework)
endif()

Michael Kuron's avatar
Michael Kuron committed
354 355
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
  set(BOOST_MINIMUM_VERSION "1.65.0")
356 357 358
  if (CUDA_FOUND AND NOT CUDA_VERSION VERSION_LESS "9.0")
    set(BOOST_MINIMUM_VERSION "1.66.0")
  endif()
Michael Kuron's avatar
Michael Kuron committed
359 360 361 362 363
else()
  set(BOOST_MINIMUM_VERSION "1.53.0")
endif()

find_package(Boost ${BOOST_MINIMUM_VERSION} REQUIRED ${BOOST_COMPONENTS})
Michael Kuron's avatar
Michael Kuron committed
364
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
365
list(APPEND LIBRARIES ${Boost_LIBRARIES})
366

Michael Kuron's avatar
Michael Kuron committed
367
if(Boost_VERSION VERSION_GREATER 106399 AND Boost_VERSION VERSION_LESS 106500)
368 369 370 371 372 373
  # Boost 1.64 has incompatible Serialization and MPI modules, see https://svn.boost.org/trac10/ticket/12723 .
  # Some distributions, like Fedora, have backported the patch.
  FILE(READ "${Boost_INCLUDE_DIR}/boost/mpi/detail/mpi_datatype_primitive.hpp" boost_mpi_datatype_file)
  if(boost_mpi_datatype_file MATCHES "boost::serialization::detail::get_data")
    message(FATAL_ERROR "Boost 1.64 is unsupported")
  endif()
Michael Kuron's avatar
Michael Kuron committed
374 375
endif()

376 377 378 379 380 381 382 383
#######################################################################
# Paths
#######################################################################

if (NOT DEFINED BINDIR)
  set(BINDIR "bin")
endif(NOT DEFINED BINDIR)

384
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTDIR}/espressomd")
385

386

387 388 389 390
#######################################################################
# Flags
#######################################################################

Michael Kuron's avatar
Michael Kuron committed
391 392 393 394 395 396 397 398
# C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if(CMAKE_VERSION VERSION_LESS 3.1)
  include(RequireCXX11)
endif()

399

400 401 402
if(APPLE)
  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -undefined dynamic_lookup")
endif()
403 404 405
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
  set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-as-needed")
endif()
406 407
# drop 'lib' prefix from all libraries
set(CMAKE_SHARED_LIBRARY_PREFIX "")
408

409 410
if(WARNINGS_ARE_ERRORS)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
411
  if (NOT CUDA_NVCC_EXECUTABLE STREQUAL CMAKE_CXX_COMPILER)
412 413 414
    set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -Xcompiler -Werror")
  endif()
endif(WARNINGS_ARE_ERRORS)
415
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-sign-compare -Wno-unused-function -Wno-unused-variable")
Michael Kuron's avatar
Michael Kuron committed
416 417 418
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi")
endif()
419 420
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
  # G++ and Intel don't know this flag
421 422
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-private-field")
endif()
Michael Kuron's avatar
Michael Kuron committed
423 424 425
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-zero-variadic-macro-arguments")
endif()
426
if (NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER "4.8.5")
Michael Kuron's avatar
Michael Kuron committed
427 428 429
  # older versions don't support -Wno-pedantic which we need in src/python
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
endif()
Michael Kuron's avatar
Michael Kuron committed
430 431 432 433
if (CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "16.0")
  # workaround for compiler crash related to decltype() and variadic template usage inside Boost
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DBOOST_NO_CXX11_VARIADIC_TEMPLATES")
endif()
434

435 436
set(CMAKE_MACOSX_RPATH TRUE)

437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
if( WITH_ASAN AND WITH_MSAN )
  message(FATAL_ERROR "Address sanitizer and memory sanitizer cannot be enabled simultaneously")
endif()
if( WITH_ASAN )
  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O1")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer")
endif()
if( WITH_MSAN )
  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O1")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=memory -fno-omit-frame-pointer")
endif()
if( WITH_UBSAN )
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
endif()

Michael Kuron's avatar
Michael Kuron committed
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466
#######################################################################
# Testing
#######################################################################

if( WITH_CLANG_TIDY )
  string(REGEX REPLACE "^([1-9]+\\.[0-9]+).*$" "\\1" CLANG_MINOR_VERSION "${CMAKE_CXX_COMPILER_VERSION}")
  find_program(
    CLANG_TIDY_EXE
    NAMES "clang-tidy-${CLANG_MINOR_VERSION}" "clang-tidy"
    DOC "Path to clang-tidy executable"
    )
  if(NOT CLANG_TIDY_EXE)
    message(STATUS "clang-tidy not found.")
  else()
    message(STATUS "clang-tidy found: ${CLANG_TIDY_EXE}")
467
    set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE}" "-checks=*,-clang-analyzer-alpha.*,-misc-unused-*,-android-*,-fuchsia-*,-google-*,-llvm-*,-modernize-*,-readability-*,-cppcoreguidelines-*,-clang-analyzer-deadcode*,-cert-*,-clang-analyzer-core.NullDereference,-clang-analyzer-core.DivideZero,-misc-misplaced-widening-cast,-misc-macro-parentheses,-clang-analyzer-security.FloatLoopCounter,-clang-analyzer-optin.mpi.MPI-Checker,-boost-use-to-string,-hicpp-*" "-header-filter=.*" "-warnings-as-errors=*")
Michael Kuron's avatar
Michael Kuron committed
468 469 470 471 472 473 474 475 476 477 478 479 480
  endif()
endif()

if(WITH_TESTS)
  enable_testing()
  if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
    set(WITH_UNIT_TESTS ON)
    list(APPEND LIBRARIES ${Boost_LIBRARIES})
  endif(Boost_UNIT_TEST_FRAMEWORK_FOUND)
  add_custom_target(check)
  add_subdirectory(testsuite)
endif(WITH_TESTS)

Jean-Noël Grad's avatar
Jean-Noël Grad committed
481 482 483 484 485
if(WITH_BENCHMARKS)
  add_custom_target(benchmark)
  add_subdirectory(maintainer/benchmarks)
endif(WITH_BENCHMARKS)

Florian Weik's avatar
Florian Weik committed
486 487 488
#######################################################################
# Subdirectories
#######################################################################
489 490 491

add_subdirectory(doc)
add_subdirectory(src)
492
add_subdirectory(config)
493 494 495 496 497 498 499

#######################################################################
# Feature summary
#######################################################################

include(FeatureSummary)
feature_summary(WHAT ALL)