-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
161 lines (130 loc) · 4.16 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
cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(SimulationServer LANGUAGES C CXX CUDA)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
option(WINDOW_RENDERING "Switches between window rendering and streaming mode" ON)
option(MULTI_GPU "Whether the simulation should run on multiple gpus" OFF)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
IF(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
endif(NOT CMAKE_BUILD_TYPE)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES 50)
endif()
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-arch=sm_50)
#
# Adding compilation flags
#
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
set(CMAKE_CUDA_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wall")
set(CMAKE_CUDA_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -Wall")
set (CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl -lm")
set (CMAKE_CUDA_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -ldl -lm")
#
# Program sources
#
file(GLOB_RECURSE CUDA_SOURCES "src/*.cu")
file(GLOB_RECURSE CUDA_HEADERS "src/*.cuh")
file(GLOB_RECURSE CPP_SOURCES "src/*.cpp")
file(GLOB_RECURSE CPP_HEADERS "src/*.hpp" "src/*.h")
#
# Common packages
#
find_package(CUDA REQUIRED)
add_library(GLAD Libraries/lib/glad.c)
set(LIBS
${CUDA_LIBRARIES}
${CUDA_CUDA_LIBRARY}
${CUDA_curand_LIBRARY}
GLAD
${CMAKE_SOURCE_DIR}/Libraries/lib/libenet.a
)
#
# Program mode specific options
#
if (MULTI_GPU)
#
# Multiple gpus
#
find_package(MPI REQUIRED)
find_package(NCCL REQUIRED)
if (NCCL_FOUND)
add_definitions(-DUSE_NCCL)
include_directories(SYSTEM ${NCCL_INCLUDE_DIR} ${MPI_INCLUDE_PATH})
endif ()
set(LIBS
${LIBS}
${MPI_LIBRARIES}
${NCCL_LIBRARY}
)
add_definitions( -DMULTI_GPU)
endif()
if(WINDOW_RENDERING)
#
# Window rendering
#
find_package(OpenGL REQUIRED COMPONENTS OpenGL)
find_package(X11 REQUIRED)
add_definitions( -DWINDOW_RENDER)
set(LIBS
${LIBS}
OpenGL::OpenGL
${CMAKE_SOURCE_DIR}/Libraries/lib/libglfw3.a
)
list(REMOVE_ITEM CPP_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/graphics/offscreencontroller.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/graphics/streamingcontroller.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/graphics/videocontroller.cpp"
)
list(REMOVE_ITEM CPP_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/src/graphics/offscreencontroller.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/graphics/streamingcontroller.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/graphics/videocontroller.hpp"
)
else()
#
# Streaming
#
find_package(OpenGL REQUIRED COMPONENTS OpenGL EGL)
find_package(PkgConfig REQUIRED)
pkg_search_module(gstreamer REQUIRED IMPORTED_TARGET gstreamer-1.0>=1.4)
pkg_search_module(gstreamer-app REQUIRED IMPORTED_TARGET gstreamer-app-1.0>=1.4)
set(LIBS
${LIBS}
OpenGL::OpenGL OpenGL::EGL
PkgConfig::gstreamer
PkgConfig::gstreamer-app
)
list(REMOVE_ITEM CPP_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/graphics/windowcontroller.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/graphics/inputcontroller.cpp"
)
list(REMOVE_ITEM CPP_HEADERS
"${CMAKE_CURRENT_SOURCE_DIR}/src/graphics/windowcontroller.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/graphics/inputcontroller.hpp"
)
endif()
include_directories(${CMAKE_SOURCE_DIR}/Libraries/include/)
link_directories(${CMAKE_SOURCE_DIR}/Libraries/lib/)
#
# Defining executable target
#
add_executable(Simulation_server ${CUDA_SOURCES} ${CPP_SOURCES} ${CUDA_HEADERS} ${CPP_HEADERS})
target_compile_options(Simulation_server PRIVATE -ggdb3 $<$<COMPILE_LANGUAGE:CUDA>:--expt-relaxed-constexpr --maxrregcount=40>)
set_target_properties(Simulation_server PROPERTIES CUDA_SEPARABLE_COMPILATION ON)
target_link_libraries(Simulation_server ${LIBS})
#
# Copy directory with shaders
#
file(COPY Shaders DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
#
# Tests
#
add_subdirectory("src/")
include(CTest)
add_subdirectory("${PROJECT_SOURCE_DIR}/Libraries/googletest-1.14.0/")
add_subdirectory("tests/")