-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathCMakeLists.txt
390 lines (343 loc) · 13.7 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
cmake_minimum_required(VERSION 3.13)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/" "${CMAKE_SOURCE_DIR}/resources")
include(VersionFromGit)
string(TIMESTAMP BUILD_TIME "%Y-%m-%d %H:%M")
message(STATUS "Saving build timestamp: ${BUILD_TIME}")
version_from_git(LOG ON TIMESTAMP "%Y-%m-%d-%H:%M:%S")
project(
SamplinSafari
DESCRIPTION "A research tool to visualize and interactively inspect high-dimensional (quasi) Monte Carlo samplers."
VERSION ${VERSION}
LANGUAGES C CXX
)
message(STATUS "C++ compiler is: ${CMAKE_CXX_COMPILER_ID}")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(VERSION_LONG "${GIT_DESCRIBE} (64 bit)")
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(VERSION_LONG "${GIT_DESCRIBE} (32 bit)")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/common.cpp.in ${CMAKE_CURRENT_BINARY_DIR}/src/common.cpp @ONLY)
# copy asset directory to the build tree file
file(
GLOB_RECURSE MY_RESOURCE_FILES
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
# CONFIGURE_DEPENDS
${CMAKE_CURRENT_SOURCE_DIR}/assets/**.*
)
foreach(MY_RESOURCE_FILE ${MY_RESOURCE_FILES})
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/${MY_RESOURCE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${MY_RESOURCE_FILE} COPYONLY
)
endforeach()
include(sanitizers)
# Set ourselves as the startup project in visual studio. Not available until cmake 3.6, but doesn't break older
# versions.
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT SamplinSafari)
# ============================================================================
# Set a default build configuration (Release)
# ============================================================================
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Release' as none was specified.")
set(CMAKE_BUILD_TYPE
Release
CACHE STRING "Choose the type of build." FORCE
)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)
# ============================================================================
# Enable folders for projects in Visual Studio
# ============================================================================
if(CMAKE_GENERATOR MATCHES "Visual Studio")
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
# Prefer libc++ in conjunction with Clang
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-stdlib=libc++" HAS_LIBCPP)
if(HAS_LIBCPP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -D_LIBCPP_VERSION")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -stdlib=libc++")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -stdlib=libc++")
message(STATUS "SamplinSafari: using libc++.")
else()
message(
WARNING
"libc++ is recommended in conjunction with clang. Please install the libc++ development headers, provided e.g. by the packages 'libc++-dev' and 'libc++abi-dev' on Debian/Ubuntu."
)
endif()
endif()
# Enable link time optimization and set the default symbol visibility to hidden (very important to obtain small
# binaries)
if(NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
# Default symbol visibility
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
# set(CMAKE_CXX_VISIBILITY_PRESET hidden)
endif()
# Disable specific GCC 7 warnings
if(CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0)
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations -Wno-misleading-indentation -Wformat-truncation=0 -Wno-int-in-bool-context -Wimplicit-fallthrough=0"
)
endif()
endif()
# ============================================================================
# Sanitize build environment for static build with C++11/17
# ============================================================================
if(MSVC)
# Disable annoying secure CRT warnings
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS")
# Parallel build on MSVC (all targets)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /arch:SSE2")
endif()
# Static build
set(CompilerFlags
CMAKE_CXX_FLAGS
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELWITHDEBINFO
)
foreach(CompilerFlag ${CompilerFlags})
string(REPLACE "/MD" "/MT" ${CompilerFlag} "${${CompilerFlag}}")
endforeach()
endif()
# ============================================================================
# Add dependencies via CPM (cmake/tools.cmake includes cmake/CPM.cmake)
#
# see https://github.com/TheLartians/CPM.cmake for more info
# ============================================================================
include(cmake/CPM.cmake)
CPMAddPackage("gh:wjakob/pcg32#70099eadb86d3999c38cf69d2c55f8adc1f7fe34")
if(pcg32_ADDED)
message(STATUS "pcg32 library added")
add_library(pcg32 INTERFACE IMPORTED)
target_include_directories(pcg32 INTERFACE "${pcg32_SOURCE_DIR}")
endif()
CPMAddPackage("gh:wkjarosz/galois#6105d219a6f26777fc02a1649c2e1d56f6e8e51e")
if(galois_ADDED)
message(STATUS "galois++ library added")
target_include_directories(galois++ INTERFACE "${galois_SOURCE_DIR}/include")
endif()
CPMAddPackage("gh:sgorsten/[email protected]")
if(linalg_ADDED)
message(STATUS "linalg library added")
add_library(linalg INTERFACE IMPORTED)
target_include_directories(linalg INTERFACE "${linalg_SOURCE_DIR}")
endif()
CPMAddPackage("gh:Armchair-Software/emscripten-browser-file#2ff8f8f791c0e7177b40e621ee3f758e03b31bf5")
if(emscripten-browser-file_ADDED)
message(STATUS "emscripten-browser-file library added")
add_library(emscripten-browser-file INTERFACE IMPORTED)
target_include_directories(emscripten-browser-file INTERFACE "${emscripten-browser-file_SOURCE_DIR}")
endif()
CPMAddPackage("gh:fmtlib/fmt#10.1.1")
if(fmt_ADDED)
message(STATUS "fmt library added")
endif()
CPMAddPackage("gh:samhocevar/portable-file-dialogs#7f852d88a480020d7f91957cbcefe514fc95000c")
if(portable-file-dialogs_ADDED)
message(STATUS "portable-file-dialogs library added")
add_library(portable-file-dialogs INTERFACE IMPORTED)
target_include_directories(portable-file-dialogs INTERFACE "${portable-file-dialogs_SOURCE_DIR}")
endif()
# set(HELLOIMGUI_USE_GLFW_METAL ON)
# set(HELLOIMGUI_USE_GLFW_OPENGL3 ON)
# set(HELLOIMGUI_USE_SDL_OPENGL3 ON)
CPMAddPackage("gh:pthom/hello_imgui#8abe2c98dbf99e3a098eb5548b0a079c9f4c8a8f")
if(hello_imgui_ADDED)
message(STATUS "hello_imgui library added")
endif()
CPMAddPackage("gh:lgruen/sobol#0227291a97e514ba34de035b1be3dbd34d12acbb")
if(sobol_ADDED)
message(STATUS "sobol library added")
# sobol has no CMake support, so we create our own target compile just the single-precision version and make it
# available as #include <sobol.h>
add_library(sobol STATIC ${sobol_SOURCE_DIR}/single-precision/sobol.cpp)
target_include_directories(sobol PUBLIC ${sobol_SOURCE_DIR}/single-precision)
set_target_properties(sobol PROPERTIES CXX_STANDARD 17)
endif()
CPMAddPackage("gh:Andrew-Helmer/stochastic-generation#dbc6e9f2c6bf03ed60fe88cb2893e52d2de2195c")
if(stochastic-generation_ADDED)
message(STATUS "stochastic-generation library added")
# stochastic-generation has no CMake support, so we create our own target
file(GLOB stochastic-generation_sources ${stochastic-generation_SOURCE_DIR}/sampling/*.cpp)
add_library(stochastic-generation STATIC ${stochastic-generation_sources})
target_include_directories(stochastic-generation PUBLIC ${stochastic-generation_SOURCE_DIR})
set_target_properties(stochastic-generation PROPERTIES CXX_STANDARD 17)
target_compile_options(
stochastic-generation PRIVATE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>,$<CXX_COMPILER_ID:GNU>>:
-Wno-sign-compare>
)
endif()
CPMAddPackage(
NAME CascadedSobol
GITHUB_REPOSITORY wkjarosz/CascadedSobol
GIT_TAG 16320b8a4d8ae543affa8267ed7b83f0207bb657
# CascadedSobol's CMakelists are not intended for library use
DOWNLOAD_ONLY YES
)
if(CascadedSobol_ADDED)
message(STATUS "CascadedSobol library added")
configure_file(
${CascadedSobol_SOURCE_DIR}/data/cascaded_sobol_init_tab.dat
${CMAKE_CURRENT_BINARY_DIR}/assets/cascaded_sobol_init_tab.dat COPYONLY
)
message(STATUS "Copied Sobol table data to assets directory")
add_library(CascadedSobol INTERFACE IMPORTED)
target_include_directories(CascadedSobol INTERFACE "${CascadedSobol_SOURCE_DIR}")
endif()
CPMAddPackage(
NAME bitcount
GITHUB_REPOSITORY mpdn/bitcount
GIT_TAG c27e7a707eca125a0e75fcdba110f41aa092b263
DOWNLOAD_ONLY YES
)
if(bitcount_ADDED)
message(STATUS "bitcount library added")
add_library(bitcount STATIC ${bitcount_SOURCE_DIR}/bitcount.c ${bitcount_SOURCE_DIR}/bitcount.h)
target_include_directories(bitcount PUBLIC ${bitcount_SOURCE_DIR})
set_target_properties(bitcount PROPERTIES CXX_STANDARD 17)
endif()
# ============================================================================
# Compile remainder of the codebase with compiler warnings turned on
# ============================================================================
if(MSVC)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wno-unused-parameter")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -Wno-gnu-anonymous-struct -Wno-c99-extensions -Wno-nested-anon-types -Wno-deprecated-register"
)
endif()
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
# Compile samplers library
add_library(
samplerlib OBJECT
STATIC
include/sampler/CascadedSobol.h
include/sampler/CSVFile.h
include/sampler/Faure.h
include/sampler/GrayCode.h
include/sampler/fwd.h
include/sampler/halton_sampler.h
include/sampler/Halton.h
include/sampler/Hammersley.h
include/sampler/Jittered.h
include/sampler/LP.h
include/sampler/Misc.h
include/sampler/MultiJittered.h
include/sampler/NRooks.h
include/sampler/OA.h
include/sampler/OAAddelmanKempthorne.h
include/sampler/OABose.h
include/sampler/OABoseBush.h
include/sampler/OABush.h
include/sampler/OACMJND.h
include/sampler/Random.h
include/sampler/RandomPermutation.h
include/sampler/Sampler.h
include/sampler/Sobol.h
include/sampler/Sudoku.h
include/sampler/xi.h
include/sampler/XiSequence.h
src/sampler/CascadedSobol.cpp
src/sampler/CSVFile.cpp
src/sampler/Faure.cpp
src/sampler/GrayCode.cpp
src/sampler/Halton.cpp
src/sampler/Jittered.cpp
src/sampler/LP.cpp
src/sampler/Misc.cpp
src/sampler/MultiJittered.cpp
src/sampler/NRooks.cpp
src/sampler/OA.cpp
src/sampler/OAAddelmanKempthorne.cpp
src/sampler/OABose.cpp
src/sampler/OABoseBush.cpp
src/sampler/OABush.cpp
src/sampler/OACMJND.cpp
src/sampler/Random.cpp
src/sampler/Sobol.cpp
src/sampler/Sudoku.cpp
src/sampler/XiSequence.cpp
)
# Link dependencies
target_link_libraries(samplerlib PUBLIC galois++ pcg32 stochastic-generation sobol CascadedSobol bitcount)
set_target_properties(samplerlib PROPERTIES CXX_STANDARD 17)
# Now build the Samplin' Safari viewer app
string(TIMESTAMP YEAR "%Y")
set(output_name "Samplin Safari")
set(HELLO_IMGUI_BUNDLE_IDENTIFIER_URL_PART "com.im.SamplinSafari")
set(HELLO_IMGUI_BUNDLE_IDENTIFIER_NAME_PART ${app_name})
set(HELLO_IMGUI_ICON_DISPLAY_NAME ${output_name})
set(HELLO_IMGUI_BUNDLE_NAME ${output_name})
set(HELLO_IMGUI_BUNDLE_COPYRIGHT "© Wojciech Jarosz, ${YEAR}")
set(HELLO_IMGUI_BUNDLE_EXECUTABLE ${output_name})
set(HELLO_IMGUI_BUNDLE_VERSION ${VERSION})
set(HELLO_IMGUI_BUNDLE_SHORT_VERSION ${VERSION})
set(HELLO_IMGUI_BUNDLE_ICON_FILE icon.icns)
if(APPLE AND (HELLOIMGUI_USE_GLFW_METAL OR HELLOIMGUI_USE_SDL_METAL))
list(APPEND EXTRA_SOURCES src/renderpass_metal.mm src/shader_metal.mm)
endif()
hello_imgui_add_app(
SamplinSafari
src/app.cpp
${CMAKE_CURRENT_BINARY_DIR}/src/common.cpp
src/opengl_check.cpp
src/shader.cpp
src/shader_gl.cpp
src/export_to_file.cpp
src/renderpass_gl.cpp
${EXTRA_SOURCES}
ASSETS_LOCATION
${CMAKE_CURRENT_BINARY_DIR}/assets
)
set_target_properties(SamplinSafari PROPERTIES OUTPUT_NAME ${output_name} CXX_STANDARD 17)
target_link_libraries(SamplinSafari PRIVATE samplerlib linalg fmt::fmt)
if(EMSCRIPTEN)
target_link_libraries(SamplinSafari PRIVATE emscripten-browser-file)
target_link_options(
SamplinSafari
PRIVATE
-sEXPORTED_RUNTIME_METHODS=[ccall]
-sEXPORTED_FUNCTIONS=[_main,_malloc,_free]
-sNO_DISABLE_EXCEPTION_CATCHING
-sMAX_WEBGL_VERSION=2
-sMIN_WEBGL_VERSION=2
)
hello_imgui_set_emscripten_target_initial_memory_megabytes(SamplinSafari 120)
else()
target_link_libraries(SamplinSafari PRIVATE portable-file-dialogs)
endif()
if(UNIX AND NOT ${U_CMAKE_BUILD_TYPE} MATCHES DEBUG)
add_custom_command(
TARGET SamplinSafari
POST_BUILD
COMMAND strip $<TARGET_FILE:SamplinSafari>
)
endif()
# Force colored output for the ninja generator
if(CMAKE_GENERATOR STREQUAL "Ninja")
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fdiagnostics-color=always")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fdiagnostics-color=always")
endif()
endif()