-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
151 lines (127 loc) · 4 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
CMAKE_MINIMUM_REQUIRED(VERSION 3.9)
# Set mfmg version
SET(MFMG_VERSION_MAJOR 0)
SET(MFMG_VERSION_MINOR 1)
SET(MFMG_VERSION_PATCH 0)
SET(MFMG_VERSION
${MFMG_VERSION_MAJOR}.${MFMG_VERSION_MINOR}.${MFMG_VERSION_PATCH})
MESSAGE("-- mfmg version: ${MFMG_VERSION}")
PROJECT(mfmg LANGUAGES CXX VERSION ${MFMG_VERSION})
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
INCLUDE(SetupCUDA)
INCLUDE(SetupTPLs)
INCLUDE(SetupMFMG)
INCLUDE(SetupCache)
# By default build a static library because CUDA does not work with a shared
# library
OPTION(BUILD_SHARED_LIBS "Build a shared library" OFF)
INITIALIZE_CACHE()
IF(${MFMG_ENABLE_CUDA})
IF (${BUILD_SHARED_LIBS})
MESSAGE(SEND_ERROR "CUDA build does not support shared library")
ENDIF()
# ENABLE_LANGUAGE cannot be in a function and it has to be called in the
# highest directory so we cannot encapsulate it
ENABLE_LANGUAGE(CUDA)
SET_CUDA_LIBRARIES()
IF (${MFMG_ENABLE_CUDA_MPI})
ADD_DEFINITIONS(-DMFMG_WITH_CUDA_MPI)
ENDIF()
ENDIF()
IF(${MFMG_ENABLE_STACKTRACE})
FIND_PACKAGE(Backtrace)
IF(${Backtrace_FOUND})
ADD_DEFINITIONS(-DMFMG_WITH_STACKTRACE)
ELSE()
MESSAGE(SEND_ERROR "Did not find Backtrace")
ENDIF()
ENDIF()
IF(${MFMG_ENABLE_COVERAGE})
INCLUDE(CodeCoverage)
ENDIF()
ENABLE_TESTING()
INCLUDE(CTest)
IF(${MFMG_ENABLE_TESTS})
ADD_SUBDIRECTORY(tests)
ENDIf()
# Check code style using clang-format
IF(${MFMG_ENABLE_CLANGFORMAT})
INCLUDE(CodeFormat)
ENDIF()
IF(${MFMG_ENABLE_CLANGTIDY})
INCLUDE(CodeTidy)
ENDIF()
IF(${MFMG_ENABLE_DOCUMENTATION})
ADD_SUBDIRECTORY(doc)
ENDIF()
FILE(GLOB_RECURSE MFMG_HEADERS "include/*.hpp" "include/*.cuh")
ADD_SUBDIRECTORY(source)
ADD_LIBRARY(mfmg ${MFMG_SOURCES})
TARGET_INCLUDE_DIRECTORIES(mfmg PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
TARGET_INCLUDE_DIRECTORIES(mfmg SYSTEM PUBLIC ${MPI_CXX_INCLUDE_PATH})
TARGET_LINK_LIBRARIES(mfmg PUBLIC ${MPI_CXX_LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(mfmg SYSTEM PUBLIC ${Boost_INCLUDE_DIRS})
TARGET_INCLUDE_DIRECTORIES(mfmg SYSTEM PUBLIC ${DEAL_II_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(mfmg PUBLIC ${DEAL_II_LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(mfmg SYSTEM PUBLIC ${LAPACKE_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(mfmg PUBLIC ${LAPACKE_LIBRARY})
TARGET_LINK_LIBRARIES(mfmg PUBLIC ${MFMG_CUDA_LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(mfmg PUBLIC ${AMGX_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(mfmg PUBLIC ${AMGX_LIBRARY})
TARGET_COMPILE_DEFINITIONS(mfmg PRIVATE ${CLANG_TIDY_DEFINITIONS})
IF(${Backtrace_FOUND})
TARGET_LINK_LIBRARIES(mfmg PUBLIC ${CMAKE_DL_LIBS})
IF ("${Backtrace_LIBRARIES}" STREQUAL "")
TARGET_LINK_LIBRARIES(mfmg PUBLIC "backtrace")
ENDIF()
ENDIF()
# Ideally we would like to always set the target properties for C++ and only
# append the property for CUDA if necessary. However, this does not work because
# cmake then thinks that the CUDA standard is 11;11.
IF(${MFMG_ENABLE_CUDA})
SET_TARGET_PROPERTIES(mfmg PROPERTIES
CUDA_SEPARABLE_COMPILATION ON
CUDA_STANDARD 14
CUDA_STANDARD_REQUIRED ON
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
# Don't use -std=gnu++14
CXX_EXTENSIONS OFF
VERSION ${MFMG_VERSION}
PUBLIC_HEADER "${MFMG_HEADERS}"
)
ELSE()
SET_TARGET_PROPERTIES(mfmg PROPERTIES
CXX_STANDARD 14
CXX_STANDARD_REQUIRED ON
# Don't use -std=gnu++14
CXX_EXTENSIONS OFF
VERSION ${MFMG_VERSION}
PUBLIC_HEADER "${MFMG_HEADERS}"
)
ENDIF()
# Install the library
INSTALL(TARGETS mfmg
EXPORT mfmg-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
INSTALL(EXPORT mfmg-targets
FILE
mfmgTargets.cmake
NAMESPACE
mfmg::
DESTINATION
${CMAKE_INSTALL_PREFIX}/lib/cmake/mfmg
)
# Create the config file
CONFIGURE_FILE(cmake/mfmgConfig.cmake.in
${CMAKE_BINARY_DIR}/cmake/mfmgConfig.cmake
@ONLY
)
# Install the config file
INSTALL(FILES ${CMAKE_BINARY_DIR}/cmake/mfmgConfig.cmake
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/cmake/mfmg
)