CMakeLists.txt 3.24 KB
Newer Older
Gregor Olenik's avatar
Gregor Olenik committed
1
2
3
4
cmake_minimum_required(VERSION 3.9)

project(OGL LANGUAGES C CXX DESCRIPTION "A wrapper for Ginkgo solver to provide GPGPU capabilities to OpenFOAM")

5
6
7
8
if(NOT DEFINED ENV{FOAM_SRC})
    message(FATAL_ERROR "You must source OpenFOAM before building OGL")
endif()

Gregor Olenik's avatar
Gregor Olenik committed
9
10
11
12
13
14
# Configuration options

include(cmake/build_type_helpers.cmake)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/")

include(CheckIncludeFileCXX)
15
option(OGL_USE_EXTERNAL_GINKGO "Use external ginkgo" FALSE)
Gregor Olenik's avatar
Gregor Olenik committed
16
17
18
19
20
21
22
23
24
25

include(CheckIncludeFileCXX)
check_include_file_cxx(cxxabi.h GKO_HAVE_CXXABI_H)

include(cmake/package_helpers.cmake)
include(cmake/build_helpers.cmake)
include(cmake/install_helpers.cmake)
ginkgo_find_package(Ginkgo "Ginkgo::ginkgo" FALSE 1.4.0)

add_subdirectory(third_party)
26
27
28
#if (NOT Ginkgo)
#  find_package(Ginkgo 1.4.0 REQUIRED PATHS ${CMAKE_CURRENT_BINARY_DIR}/third_party/ginkgo/build/install/lib/cmake)
#endif()
Gregor Olenik's avatar
Gregor Olenik committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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

# To interface with ginkgo at least C++ 14 is needed
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)


set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall -O0 -ggdb")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} \
  -Wall -Wpedantic -Wextra -march=native -fopenmp -fPIC"
  )

if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
  set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} \
      -fno-omit-frame-pointer \
      -fsanitize=address"
    )

  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} \
    -fno-omit-frame-pointer \
    -Rpass=loop-vectorize \
      -ffast-math \
      "
      #-Rpass-analysis=loop-vectorize \
      #-Rpass-missed=loop-vectorize \
      )

elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU")

    add_definitions(-DWITH_GNU)

    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} \
      --coverage\
      -fprofile-arcs \
      -fsanitize=address \
      -ggdb3 \
      -ftest-coverage"
)

    set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} \
        -ffast-math \
        -march=native  \
        -ftree-vectorize \
        -rdynamic \
        "
        # -fopt-info-vec-missed"
        )
endif()

option(BUILD_SHARED_LIBS "Build shared library" ON)
add_library(OGL  ""  )

add_compile_definitions(
  WM_LABEL_SIZE=32
  WM_ARCH_OPTION=64
  NoRepository
  linux64
  WM_DP
  )

target_sources(OGL
  PRIVATE
lduMatrix/GKOlduBase/GKOlduBase.C
lduMatrix/GKOCG/GKOCG.C
lduMatrix/GKOIR/GKOIR.C
lduMatrix/GKOBiCGStab/GKOBiCGStab.C
LduMatrix/GKOLduBase/GKOLduBase.C
LduMatrix/GKOACG/GKOACG.C
  PUBLIC
lduMatrix/GKOlduBase/GKOlduBase.H
lduMatrix/GKOCG/GKOCG.H
lduMatrix/GKOIR/GKOIR.H
lduMatrix/GKOBiCGStab/GKOBiCGStab.H
LduMatrix/GKOLduBase/GKOLduBase.H
LduMatrix/GKOACG/GKOACG.H
  )

108

Gregor Olenik's avatar
Gregor Olenik committed
109
110
target_include_directories(OGL
  PUBLIC
111
112
113
114
  $ENV{FOAM_SRC}/OpenFOAM/lnInclude
  $ENV{FOAM_SRC}/meshTools/lnInclude
  $ENV{FOAM_SRC}/finiteVolume/lnInclude
  $ENV{FOAM_SRC}/OSspecific/POSIX/lnInclude
Gregor Olenik's avatar
Gregor Olenik committed
115
116
117
118
119
    common/
    lduMatrix/GKOlduBase
    LduMatrix/GKOLduBase
  )

120

Gregor Olenik's avatar
Gregor Olenik committed
121
122
123
124
target_link_libraries(OGL
  PUBLIC
    Ginkgo::ginkgo
  )
125
126
127
128
129
130
131
132
133
134
135

install(TARGETS OGL 
    DESTINATION $ENV{FOAM_USER_LIBBIN}
    )

if(NOT ${OGL_USE_EXTERNAL_GINKGO})
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/third_party/ginkgo/build/install/lib/
    DESTINATION $ENV{FOAM_USER_LIBBIN}
    )
endif()