Skip to content
Snippets Groups Projects
CMakeLists.txt 7.32 KiB
Newer Older
#################################################################################
#   _    ___      __              __________      _     __
# | |  / (_)____/ /___  ______ _/ / ____/ /_  __(_)___/ /____
# | | / / / ___/ __/ / / / __ `/ / /_  / / / / / / __  / ___/
# | |/ / / /  / /_/ /_/ / /_/ / / __/ / / /_/ / / /_/ (__  )
# |___/_/_/   \__/\__,_/\__,_/_/_/   /_/\__,_/_/\__,_/____/
#
#################################################################################
cmake_minimum_required(VERSION 3.15..3.20 FATAL_ERROR)
project(VirtualFluids
        DESCRIPTION "CFD code based on the Lattice Boltzmann Method"
        HOMEPAGE_URL "https://www.tu-braunschweig.de/irmb/forschung/virtualfluids"
        LANGUAGES CXX)
peters's avatar
peters committed
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Release)
endif()
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")

set(CMAKE_CXX_STANDARD 17)
Soeren Peters's avatar
Soeren Peters committed
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER ".cmake")
set(libraryFolder "libs")
set(testFolder    "tests")
set(appFolder     "apps")
set(thirdFolder   "3rd")
set (VF_CMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/CMake)
set (VF_THIRD_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rdParty)
set (VF_SRC_DIR   ${CMAKE_CURRENT_SOURCE_DIR}/src)
set (VF_ROOT_DIR  ${CMAKE_CURRENT_SOURCE_DIR})
peters's avatar
peters committed
if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
  message(FATAL_ERROR "In-source builds are prohibited. "
    "Create a new directory and build there.")
endif ()
#################################################################################
#  OPTIONS
#################################################################################
option(BUILD_VF_CPU "Build VirtualFluids cpu variant" OFF)
option(BUILD_VF_GPU "Build VirtualFluids gpu variant" OFF)
option(BUILD_USE_OPENMP "Build VirtualFluids with openmp" ON)
option(BUILD_USE_BOOST "Build VirtualFluids with boost" OFF)
option(BUILD_USE_MPI "include MPI library support" ON)
# vf gpu
option(BUILD_VF_GKS          "Build VirtualFluids GKS"     OFF )
option(BUILD_VF_TRAFFIC      "Build VirtualFluids Traffic" OFF)
option(BUILD_JSONCPP         "Builds json cpp "            OFF)
option(BUILD_NUMERIC_TESTS   "Build numeric tests"         OFF)

option(BUILD_VF_UNIT_TESTS "Build VirtualFluids unit tests" OFF)
option(BUILD_VF_CLANG_TIDY "Add the clang tidy checks to the targets" OFF)
option(BUILD_VF_INCLUDE_WHAT_YOU_USE "Add IWYU to the targets" OFF)
option(BUILD_VF_CPPCHECK "Add cppcheck to the targets" OFF)
option(BUILD_VF_COVERAGE "Add the -coverage compiler flag." OFF)
peters's avatar
peters committed
option(BUILD_CUDA_LTO "Enables the cuda link optimization." OFF)

option(BUILD_SHARED_LIBS "" OFF)

# windows: use multi-threaded dynamically-linked runtime library
if(BUILD_SHARED_LIBS)
    set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
else()
    set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
option(BUILD_VF_DOUBLE_ACCURACY "Use double accuracy" OFF)

#################################################################################
#  MACROS
#################################################################################
add_library(project_warnings INTERFACE)

# standard compiler warnings - Link this 'library' to use the warnings specified in CompilerWarnings.cmake
include(${VF_CMAKE_DIR}/CompilerWarnings.cmake)
set_project_warnings(project_warnings)

# enable cache system
include(${VF_CMAKE_DIR}/Cache.cmake)

include(${VF_CMAKE_DIR}/VirtualFluidsMacros.cmake)
IF( BUILD_VF_DOUBLE_ACCURACY )
    list(APPEND VF_COMPILER_DEFINITION VF_DOUBLE_ACCURACY)
ENDIF()

# set gpu features
if(BUILD_VF_GPU OR BUILD_VF_GKS)
    include(CheckLanguage)
    check_language(CUDA)

    if(NOT CMAKE_CUDA_COMPILER)
        message(FATAL_ERROR "CUDA Compiler was requested but is not found on the system.")
    endif()

    set(CMAKE_CUDA_STANDARD 17)
    set(CMAKE_CUDA_STANDARD_REQUIRED TRUE)

Soeren Peters's avatar
Soeren Peters committed
    enable_language(CUDA)

peters's avatar
peters committed
    if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
        message(WARNING "CMAKE_CUDA_ARCHITECTURES was not defined and is set to 30 (CUDA support until 10.1 only).")
        set(CMAKE_CUDA_ARCHITECTURES 30)
peters's avatar
peters committed
    endif()
peters's avatar
peters committed
    if(BUILD_CUDA_LTO)
       if(CMAKE_CUDA_ARCHITECTURES LESS 50)
            message(FATAL_ERROR "CUDA Link time optimization requires CUDA 11.2 and CC 5.0.")
       else()

        set(CMAKE_CUDA_FLAGS "-dlto -arch=sm_${CMAKE_CUDA_ARCHITECTURES}")
        set(CMAKE_CUDA_ARCHITECTURES OFF)

        list(APPEND VF_COMPILER_DEFINITION BUILD_CUDA_LTO)

       endif()
    endif()
    set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --extended-lambda")

    message(STATUS "CMAKE_CUDA_FLAGS: ${CMAKE_CUDA_FLAGS}")
    message(STATUS "CUDA Architecture: ${CMAKE_CUDA_ARCHITECTURES}")
    set(CMAKE_CUDA_ARCHITECTURES "${CMAKE_CUDA_ARCHITECTURES}" CACHE STRING "Cuda Architecture (compute capabilitiy)")
#################################################################################
#  COMMON LIBRARIES
#################################################################################
include(FetchContent)

# spdlog
set(spdlog_version "v1.9.1")
set(spdlog_url "https://github.com/gabime/spdlog")
message(STATUS "Fetching spdlog: ${spdlog_version}")
FetchContent_Declare(
        spdlog
        GIT_REPOSITORY ${spdlog_url}
        GIT_TAG        ${spdlog_version}
)

FetchContent_MakeAvailable(spdlog)
target_compile_options(spdlog PRIVATE "-fPIC")
groupTarget(spdlog ${thirdFolder})
# googletest
if(BUILD_VF_UNIT_TESTS)
    FetchContent_Declare(
        googletest
        DOWNLOAD_EXTRACT_TIMESTAMP FALSE # https://cmake.org/cmake/help/latest/policy/CMP0135.html
        URL https://github.com/google/googletest/archive/1f643f71d4151c3b364c0e9302042f7a6debd439.zip # 30.11.2022
    )
    # For Windows: Prevent overriding the parent project's compiler/linker settings
    set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)

    FetchContent_MakeAvailable(googletest)

    groupTarget(gmock ${thirdFolder}/googletest)
    groupTarget(gmock_main ${thirdFolder}/googletest)
    groupTarget(gtest ${thirdFolder}/googletest)
    groupTarget(gtest_main ${thirdFolder}/googletest)

    include(GoogleTest)
    enable_testing()
endif()

if(BUILD_USE_OPENMP)
    find_package(OpenMP REQUIRED)
endif()

if(BUILD_USE_MPI)
    find_package(MPI REQUIRED)
# boost
IF(BUILD_USE_BOOST)
    list(APPEND VF_COMPILER_DEFINITION BUILD_USE_BOOST)

    set(Boost_USE_STATIC_LIBS ON)
    set(Boost_USE_MULTITHREADED ON)
    set(Boost_USE_STATIC_RUNTIME ON)

    # minimum boost version: 1.60
    # no packages specfied - only headeronly libraries
    find_package(Boost 1.60 REQUIRED)
ENDIF()

add_subdirectory(src/logger)
add_subdirectory(src/basics)
Soeren Peters's avatar
Soeren Peters committed
add_subdirectory(src/lbm)
#################################################################################
#  VIRTUAL FLUIDS CPU / GPU
#################################################################################
if (BUILD_VF_CPU)
    include (cpu.cmake)
endif()
if(BUILD_VF_GPU OR BUILD_VF_GKS)
    add_subdirectory(src/cuda)
    include (gpu.cmake)
peters's avatar
peters committed
endif()

if (BUILD_VF_PYTHON_BINDINGS)
    add_subdirectory(${VF_THIRD_DIR}/pybind11/pybind11-2.6.0)
    add_subdirectory(pythonbindings)
endif()