forked from cselab/Mirheo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
163 lines (131 loc) · 5.22 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
152
153
154
155
156
157
158
159
160
161
162
163
cmake_minimum_required(VERSION 3.8)
if(POLICY CMP0060)
cmake_policy(SET CMP0060 NEW)
endif()
if(POLICY CMP0074)
cmake_policy(SET CMP0074 NEW)
endif()
project(YMeRo LANGUAGES C CXX CUDA)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(YMR "libymero")
set(YMR_MAIN "ymero_main")
# version
execute_process(COMMAND
git describe --abbrev=0
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE YMR_VERSION
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# the commit's SHA1, and whether the building workspace was dirty or not
execute_process(COMMAND
git describe --match=NeVeRmAtCh --always --abbrev=40 --dirty
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_SHA1
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
# Add the pybind11
add_subdirectory(src/extern/pybind11)
# CUDA
# Dynamic linking should allegedly improve UCX-based MPI,
# but it seriously affects other code aspects (maybe stream polling?)
#set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
find_package(CUDA REQUIRED)
include_directories(${CUDA_INCLUDE_DIRS})
# MPI
find_package(MPI REQUIRED)
# On CRAY systems things are complicated
# This workaround should work to supply
# nvcc with correct mpi paths
# Libraries should not be needed here as
# we link with MPI wrapper anyways
if (DEFINED ENV{CRAY_MPICH_DIR})
set(MPI_C_INCLUDE_DIRS "$ENV{CRAY_MPICH_DIR}/include")
set(MPI_CXX_INCLUDE_DIRS "$ENV{CRAY_MPICH_DIR}/include")
endif()
include_directories(${MPI_CXX_INCLUDE_DIRS})
set(CMAKE_C_COMPILER ${MPI_C_COMPILER})
set(CMAKE_CXX_COMPILER ${MPI_CXX_COMPILER})
set(CMAKE_CUDA_HOST_LINK_LAUNCHER ${MPI_CXX_COMPILER})
# Require c++11
#set(PYBIND11_CPP_STANDARD -std=c++11)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CUDA_STANDARD 11)
# Alias some dirs
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src/ )
set(CORE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/core/")
set(PLUGINS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/plugins/")
set(BINDINGS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/bindings/")
set(PYTHON_LIB_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/ymero")
# generate version.cpp
configure_file(
"${CORE_DIR}/version.cpp.in"
"${CORE_DIR}/version.cpp"
)
#generate version.py
configure_file(
"${PYTHON_LIB_DIR}/version.py.in"
"${PYTHON_LIB_DIR}/version.py"
)
# Find sources
file(GLOB_RECURSE SOURCES_BINDINGS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${BINDINGS_DIR}/*.cpp")
file(GLOB_RECURSE SOURCES_MAIN RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
"${CORE_DIR}/*.cu" "${PLUGINS_DIR}/*.cu" "${CORE_DIR}/*.cpp" "${PLUGINS_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/src/extern/pugixml/src/*.cpp")
# Define the main library
add_library(main_compiled OBJECT ${SOURCES_MAIN})
set_property(TARGET main_compiled PROPERTY POSITION_INDEPENDENT_CODE 1)
add_library(${YMR_MAIN} SHARED $<TARGET_OBJECTS:main_compiled>)
add_library(${YMR} MODULE ${SOURCES_BINDINGS} $<TARGET_OBJECTS:main_compiled>)
target_link_libraries(${YMR} PRIVATE pybind11::module)
set_target_properties(${YMR} PROPERTIES PREFIX "${PYTHON_MODULE_PREFIX}"
SUFFIX "${PYTHON_MODULE_EXTENSION}")
target_link_libraries(${YMR} PRIVATE ${CUDA_LIBRARIES})
target_link_libraries(${YMR_MAIN} PRIVATE ${CUDA_LIBRARIES})
#######################################################
# Optional packages
# For field dumps
set(HDF5_PREFER_PARALLEL ON)
find_package(HDF5 REQUIRED)
# On CRAY systems things are complicated
# This workaround should work to supply
# nvcc with correct hdf paths
if (DEFINED ENV{CRAY_HDF5_DIR})
set(HDF5_INCLUDE_DIRS "$ENV{HDF5_DIR}/include")
set(HDF5_LIBRARIES "$ENV{HDF5_DIR}/lib/libhdf5.so")
endif()
if (${HDF5_FOUND})
include_directories(${HDF5_INCLUDE_DIRS})
target_link_libraries(${YMR} PRIVATE ${HDF5_LIBRARIES})
target_link_libraries(${YMR_MAIN} PRIVATE ${HDF5_LIBRARIES})
endif()
# For pretty stacktrace in case of a crash
find_package(LIBBFD REQUIRED)
if (${LIBBFD_FOUND})
include_directories(${LIBBFD_INCLUDE_DIRS})
target_link_libraries(${YMR} PRIVATE ${LIBBFD_BFD_LIBRARY})
target_link_libraries(${YMR_MAIN} PRIVATE ${LIBBFD_BFD_LIBRARY})
endif()
########################################################
# Setup compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-extended-lambda")
set(CMAKE_CUDA_FLAGS_RELEASE "-O3 -DNDEBUG --use_fast_math -lineinfo -g")
set(CMAKE_CUDA_FLAGS_DEBUG "-O0 -G -g")
# Silence deprecation warnings for CUDA >= 9
if (CUDA_VERSION_MAJOR GREATER_EQUAL 9)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --Wno-deprecated-declarations")
endif()
# Auto-detect compute capability if not provided
if (NOT DEFINED CUDA_ARCH_NAME)
set(CUDA_ARCH_NAME Auto)
endif()
# The options come out crooked, fix'em
cuda_select_nvcc_arch_flags(BUGGED_ARCH_FLAGS ${CUDA_ARCH_NAME})
unset(CUDA_ARCH_NAME CACHE)
string(REPLACE "gencode;" "gencode=" ARCH_FLAGS_LIST "${BUGGED_ARCH_FLAGS}")
string(REPLACE ";" " " CUDA_ARCH_FLAGS "${ARCH_FLAGS_LIST}")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} ${CUDA_ARCH_FLAGS}")
# Linker flags
set(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} -rdynamic -flto -g")
# Choose Release mode as default.
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()