-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
180 lines (155 loc) · 6.2 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
cmake_minimum_required(VERSION 3.17)
include(FindCUDAToolkit)
include(FetchContent)
set(CMAKE_SUPPRESS_REGENERATION ON CACHE BOOL "" FORCE)
set(CMAKE_WARN_DEPRECATED OFF CACHE BOOL "" FORCE)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
if(NOT DEFINED CMAKE_CUDA_ARCHITECTURES)
set(CMAKE_CUDA_ARCHITECTURES "50;89")
endif()
if(NOT DEFINED CMAKE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "")
endif()
# Mandelbrot
project(Mandelbrot LANGUAGES CUDA CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# glfw-external
FetchContent_Declare(glfw-external
URL https://github.com/glfw/glfw/releases/download/3.4/glfw-3.4.bin.WIN64.zip
URL_HASH MD5=725C211378D00F3EEE5DF5ACC8108742
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/GLFW
DOWNLOAD_EXTRACT_TIMESTAMP true
)
# rapidjson-external
set(RAPIDJSON_BUILD_DOC OFF CACHE BOOL "" FORCE)
set(RAPIDJSON_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)
set(RAPIDJSON_BUILD_TESTS OFF CACHE BOOL "" FORCE)
FetchContent_Declare(rapidjson-external
GIT_REPOSITORY https://github.com/Tencent/rapidjson.git
GIT_TAG v1.1.0
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/rapidjson
DOWNLOAD_EXTRACT_TIMESTAMP true
)
# googlebenchmark-external
set(BENCHMARK_ENABLE_GTEST_TESTS OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_INSTALL OFF CACHE BOOL "" FORCE)
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
set(BENCHMARK_INSTALL_DOCS OFF CACHE BOOL "" FORCE)
set(BENCHMARK_USE_BUNDLED_GTEST OFF CACHE BOOL "" FORCE)
FetchContent_Declare(googlebenchmark-external
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.8.5
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/benchmark
DOWNLOAD_EXTRACT_TIMESTAMP true
)
# googletest-external
set(BUILD_GMOCK OFF CACHE BOOL "" FORCE)
set(INSTALL_GTEST OFF CACHE BOOL "" FORCE)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_Declare(googletest-external
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.15.2
BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/googletest
DOWNLOAD_EXTRACT_TIMESTAMP true
)
# lodepng-external
FetchContent_Declare(lodepng-external
GIT_REPOSITORY https://github.com/lvandeve/lodepng.git
GIT_TAG ed3c5f14b136c936d615ee3b38aaa7e7e642f12c
DOWNLOAD_EXTRACT_TIMESTAMP true
)
FetchContent_MakeAvailable(
glfw-external
googlebenchmark-external
googletest-external
rapidjson-external
lodepng-external
)
FetchContent_GetProperties(
rapidjson-external
)
# Google benchmark
# benchmark and benchmark_main targets are available
set_target_properties(benchmark PROPERTIES FOLDER "External")
set_target_properties(benchmark_main PROPERTIES FOLDER "External")
# Google test
# gtest and gtest_main targets are available
set_target_properties(gtest PROPERTIES FOLDER "External")
set_target_properties(gtest_main PROPERTIES FOLDER "External")
# OpenGL
add_library(OpenGL STATIC IMPORTED)
set_target_properties(OpenGL PROPERTIES
IMPORTED_LOCATION opengl32.lib
)
# GLFW
add_library(GLFW STATIC IMPORTED)
add_dependencies(GLFW glfw-external)
target_link_libraries(GLFW INTERFACE OpenGL)
set_target_properties(GLFW PROPERTIES
IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/GLFW/lib-vc2022/glfw3.lib
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/GLFW/include
)
# RapidJSON
add_library(RapidJSON INTERFACE)
target_include_directories(RapidJSON INTERFACE "$<BUILD_INTERFACE:${rapidjson-external_SOURCE_DIR}/include>")
set_target_properties(travis_doc PROPERTIES FOLDER "External")
# LodePNG
add_library(LodePNG STATIC
"${lodepng-external_SOURCE_DIR}/lodepng.cpp"
"${lodepng-external_SOURCE_DIR}/lodepng.h"
)
target_include_directories(LodePNG PUBLIC
"${lodepng-external_SOURCE_DIR}"
)
set_target_properties(LodePNG PROPERTIES FOLDER "External")
# CUDA core library
set(CUDA_CORE_INCLUDE_FOLDER "include/core")
set(CUDA_CORE_SOURCE_FOLDER "src/core/cuda")
file(GLOB CUDA_CORE_HEADERS ${CUDA_CORE_INCLUDE_FOLDER}/mandelbrot/core/cuda/*.h)
file(GLOB CUDA_CORE_SOURCES ${CUDA_CORE_SOURCE_FOLDER}/*.cpp ${CUDA_CORE_SOURCE_FOLDER}/*.cu)
add_library(MandelbrotCUDACore STATIC ${CUDA_CORE_HEADERS} ${CUDA_CORE_SOURCES})
set_target_properties(MandelbrotCUDACore PROPERTIES LINKER_LANGUAGE CUDA)
target_include_directories(MandelbrotCUDACore PUBLIC ${CUDA_CORE_INCLUDE_FOLDER})
target_link_libraries(MandelbrotCUDACore PRIVATE CUDA::cudart_static)
# Core library
set(CORE_INCLUDE_FOLDER "include/core")
set(CORE_SOURCE_FOLDER "src/core")
file(GLOB CORE_HEADERS ${CORE_INCLUDE_FOLDER}/mandelbrot/core/*.h)
file(GLOB CORE_SOURCES ${CORE_SOURCE_FOLDER}/*.cpp)
add_library(MandelbrotCore STATIC ${CORE_HEADERS} ${CORE_SOURCES})
target_include_directories(MandelbrotCore PUBLIC ${CORE_INCLUDE_FOLDER})
target_link_libraries(MandelbrotCore PRIVATE MandelbrotCUDACore LodePNG)
# Benchmarks
set(BENCHMARKS_SOURCE_FOLDER "src/benchmarks")
file(GLOB BENCHMARKS_SOURCES ${BENCHMARKS_SOURCE_FOLDER}/*.cpp)
add_executable(Benchmarks ${BENCHMARKS_SOURCES})
target_link_libraries(Benchmarks PRIVATE benchmark benchmark_main MandelbrotCore)
# Tests
enable_testing()
set(TESTS_SOURCE_FOLDER "src/tests")
file(GLOB TESTS_SOURCE_FOLDER ${TESTS_SOURCE_FOLDER}/*.cpp)
add_executable(Tests ${TESTS_SOURCE_FOLDER})
target_link_libraries(Tests PRIVATE gtest gtest_main)
target_link_libraries(Tests PUBLIC MandelbrotCore)
set_property(TARGET Tests PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
include(GoogleTest)
gtest_discover_tests(Tests)
# Application executable
set(APP_INCLUDE_FOLDER "include/application")
set(APP_SOURCE_FOLDER "src/application")
file(GLOB APP_HEADERS ${APP_INCLUDE_FOLDER}/mandelbrot/application/*.h)
file(GLOB APP_SOURCES ${APP_SOURCE_FOLDER}/*.cpp)
add_executable(MandelbrotExplorer ${APP_HEADERS} ${APP_SOURCES})
target_include_directories(MandelbrotExplorer PUBLIC ${APP_INCLUDE_FOLDER})
target_link_libraries(MandelbrotExplorer PUBLIC MandelbrotCore)
target_link_libraries(MandelbrotExplorer PRIVATE GLFW RapidJSON)
set_property(TARGET MandelbrotExplorer PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}")
add_custom_command(
TARGET MandelbrotExplorer POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${CMAKE_SOURCE_DIR}/data/config.json
$<TARGET_FILE_DIR:MandelbrotExplorer>/config.json
)
# Set starup project
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT MandelbrotExplorer)