-
Notifications
You must be signed in to change notification settings - Fork 26
/
CMakeLists.txt
324 lines (271 loc) · 12.6 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
#------------------------------------------------------------------------------
# Copyright (c) 2018-2024 Michele Morrone
# All rights reserved.
#
# https://michelemorrone.eu - https://brutpitt.com
#
# X: https://x.com/BrutPitt - GitHub: https://github.com/BrutPitt
#
# direct mail: brutpitt(at)gmail.com - me(at)michelemorrone.eu
#
# This software is distributed under the terms of the BSD 2-Clause license
#------------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.15)
# SET(BUILD_wglAPP FALSE CACHE FALSE TRUE)
###########################################################
#
# To build example in Linux/MacOS/Windows (with MinGW) uses follow command:
#
# cmake -DBuildTarget:String=<BuildVer> -G <MakeTool> -B<FolderToBuild>
# where:
# <BuildVer> must be one of follow strings:
# OpenGL_45
# OpenGL_41
# OpenGL_ES
# <MakeTool> is your preferred generator like "Unix Makefiles" or "Ninja"
# <FolderToBuild> is the folder where will be generated Makefile, move in it and run your generator
# - Default build is "Release" but it can be changed via CMAKE_BUILD_TYPE definition:
# command line: -DCMAKE_BUILD_TYPE:STRING=<Debug|Release|MinSizeRel|RelWithDebInfo>
# cmake-gui: from combo associated to CMAKE_BUILD_TYPE var
#
# Example:
# to build example compliant to OpenGL 4.5, with "make" utility, in "./build" folder, type:
#
# > cmake -DBuildTarget:String=OpenGL_45 -G Unix\ Makefiles -B./build
# > cd build
# > make
#
#
#
#
# To build example with EMSCRIPTEN uses follow command:
# cmake cmake -DCMAKE_TOOLCHAIN_FILE:STRING=<EMSDK_PATH>/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake -DBuildTarget:String=<BuildVer> -G "Unix Makefiles"|"ninja" -B<FolderToBuild>
# where:
# <EMSDK_PATH> is where was installed EMSCRIPTEN: you need to have it in EMSDK environment variable
# <BuildVer> must be one of follow strings:
# WebGL
# WebGL_LowRes
# <MakeTool> is your preferred generator like "Unix Makefiles" or "ninja"
# Windows users need to use MinGW-make utility (by EMSCRIPTEN specification): ninja or othe can not work.
# <FolderToBuild> is the folder where will be generated Makefile, move in it and run your generator
# - Default build is "MinSizeRel" but it can be changed via CMAKE_BUILD_TYPE definition:
# command line: -DCMAKE_BUILD_TYPE:STRING=<Debug|Release|MinSizeRel|RelWithDebInfo>
# cmake-gui: from combo associated to CMAKE_BUILD_TYPE var
#
#set(GLAPP_DISABLE_DLA "-DGLAPP_DISABLE_DLA")
#set(ENABLE_TEST "-DGLAPP_TEST")
set(OGL_45 "OpenGL_45")
set(OGL_41 "OpenGL_41")
set(OGL_ES "OpenGL_ES")
set(WGL_FULL "WebGL")
set(BuildTarget ${OGL_45} CACHE STRING "Select the target to build:\n glChAoS.P compliant with OpenGL 4.5/4.1/ES 3.x\n wglChAoS.P compliant with WebGL 2.0\n \"LowRes\" stands for GPU with LowResources (mem/cores\)")
set(BuildTargetValues "${OGL_45};${OGL_41};${OGL_ES};${WGL_FULL};" CACHE INTERNAL "Select one")
set_property(CACHE BuildTarget PROPERTY STRINGS ${BuildTargetValues} )
set(OGL45 "-DGLAPP_REQUIRE_OGL45 -DGLAPP_USES_SEPARABLE") #-DGLAPP_USES_SEPARABLE
set(OGL41 "")
set(OGLES "-DGLAPP_USES_ES3 -DIMGUI_IMPL_OPENGL_ES3")
set(BASE_DEFINES "-DGLAPP_USE_IMGUI -DVGM_USES_TEMPLATE")
if(${BuildTarget} STREQUAL ${OGL_45})
set(OGL_VER_USED ${OGL45} ${ENABLE_TEST})
message(STATUS "selected ${BuildTarget} ...")
elseif(${BuildTarget} STREQUAL ${OGL_41})
set(OGL_VER_USED ${OGL41})
message(STATUS "selected ${BuildTarget} ...")
elseif(${BuildTarget} STREQUAL ${OGL_ES})
set(OGL_VER_USED ${OGLES})
message(STATUS "selected ${BuildTarget} ...")
elseif(${BuildTarget} STREQUAL ${WGL_FULL})
set(BUILD_WebGL TRUE BOOL)
set(defaultBuildType "MinSizeRel")
message(STATUS "selected ${BuildTarget} ...")
endif()
#change default build type from cmake-gui
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "'CMAKE_BUILD_TYPE' not specified, now is set to: '${defaultBuildType}' ...")
set(CMAKE_BUILD_TYPE "${defaultBuildType}" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug;Release;MinSizeRel;RelWithDebInfo")
endif()
set(SRC "${CMAKE_SOURCE_DIR}/src")
set(SOURCE_FILES
${SRC}/libs/imgui/imconfig.h
${SRC}/libs/imgui/imgui.cpp
${SRC}/libs/imgui/imgui_widgets.cpp
${SRC}/libs/imgui/imgui.h
${SRC}/libs/imgui/imgui_draw.cpp
${SRC}/libs/imgui/imgui_impl_glfw.cpp
${SRC}/libs/imgui/imgui_impl_glfw.h
${SRC}/libs/imgui/imgui_impl_opengl3.cpp
${SRC}/libs/imgui/imgui_tables.cpp
${SRC}/libs/imgui/imgui_impl_opengl3_loader.h
${SRC}/libs/imgui/imgui_impl_opengl3.h
${SRC}/libs/imgui/imgui_impl_opengl3.h
${SRC}/libs/imgui/imgui_internal.h
${SRC}/libs/imgui/imstb_rectpack.h
${SRC}/libs/imgui/imstb_textedit.h
${SRC}/libs/imgui/imstb_truetype.h
${SRC}/libs/lodePNG/lodepng.cpp
${SRC}/libs/lodePNG/lodepng.h
${SRC}/tools/glslProgramObject.cpp
${SRC}/tools/glslProgramObject.h
${SRC}/tools/glslShaderObject.cpp
${SRC}/tools/glslShaderObject.h
${SRC}/tools/mmFBO.cpp
${SRC}/tools/mmFBO.h
${SRC}/ui/uiMainDlg.cpp
${SRC}/ui/uiMainDlg.h
${SRC}/ui/uiSettings.cpp
${SRC}/glApp.cpp
${SRC}/glApp.h)
if(DEFINED ENABLE_TEST)
set(SOURCE_FILES ${SOURCE_FILES}
${SRC}/glWindow_test.cpp
${SRC}/glWindow_test.h)
else()
set(SOURCE_FILES ${SOURCE_FILES}
${SRC}/glWindow.cpp
${SRC}/glWindow.h)
endif()
###########################################################
# EMSCRIPTEN setting
###########################################################
if(BUILD_WebGL)
project(wglApp)
set(OGL_EMITTER_TYPE "${OGL41} -DGLAPP_WEBGL")
set(CMAKE_CXX_STANDARD 14)
find_package(OpenGL)
include_directories(BEFORE SYSTEM ${EMSCRIPTEN_ROOT_PATH}/system/include)
# include_directories(BEFORE SYSTEM $ENV{EMSCRIPTEN}/system/include)
include_directories(${SRC})
include_directories(${SRC}/tools)
include_directories(AFTER ${SRC}/libs)
# include_directories(AFTER $ENV{INCLUDE})
# -o ${PROJECT_NAME}.html -> CMAKE_EXECUTABLE_SUFFIX .html .bc, .js (default), etc
set(CMAKE_EXECUTABLE_SUFFIX ".html")
# relative emscripten output files (EMSOUT_PATH for my RAMDISK, if defined)
#file(MAKE_DIRECTORY ${EMSOUT}/${CMAKE_BUILD_TYPE})
#set(EMSOUT ${EMSOUT}/${CMAKE_BUILD_TYPE})
# emcc compiler options
set(M_EMCC_FLAGS "-DGLAPP_NO_OGL_DSA -DGLFW_INCLUDE_ES3")
set(M_GLOBAL_FLAGS "${BASE_DEFINES} -DIMGUI_IMPL_OPENGL_ES3 -fpermissive")
# BUILD TYPE: [Debug|RelWithDebInfo|Release|MinSizeRel]
if(${CMAKE_BUILD_TYPE} MATCHES "Debug")
set(M_EMCC_BINARYEN "-s WASM=0 -s DEMANGLE_SUPPORT=1 ")
set(M_EMCC_SHELL_FILE "--shell-file \"${CMAKE_SOURCE_DIR}/mVeryMinimal.html\"")
else()
# -s BINARYEN_METHOD='native-wasm,asmjs' 'interpret-asm2wasm' -s BINARYEN_ASYNC_COMPILATION=0
if(${CMAKE_BUILD_TYPE} MATCHES "RelWithDebInfo")
set(M_EMCC_BINARYEN "-s WASM=1")
set(M_EMCC_SHELL_FILE "--shell-file \"${CMAKE_SOURCE_DIR}/mVeryMinimal.html\"")
else()
if(${CMAKE_BUILD_TYPE} MATCHES "MinSizeRel")
# one file no memory option: -s SINGLE_FILE=1 --memory-init-file 0
set(M_EMCC_BINARYEN "--no-heap-copy --closure 1 -s WASM=1 ")
set(M_EMCC_SHELL_FILE "--shell-file \"${CMAKE_SOURCE_DIR}/mVeryMinimal.html\"")
else() # Release
# -s SINGLE_FILE=1 --memory-init-file 0 -s \"BINARYEN_METHOD='interpret-asm2wasm'\"
set(M_EMCC_BINARYEN "-s WASM=1 ")
set(M_EMCC_SHELL_FILE "--shell-file \"${CMAKE_SOURCE_DIR}/mVeryMinimal.html\"")
endif()
endif()
endif()
set(M_EMCC_EMBED_ALL_ATTRACTORS "${CMAKE_SOURCE_DIR}/../ChaoticAttractors@ChaoticAttractors/")
set(M_EMCC_EMBED_FEW_ATTRACTORS "${CMAKE_SOURCE_DIR}/../selectedAttractors@ChaoticAttractors/")
# grouped EMCC_OPTIONS
# --embed-file \"${CMAKE_SOURCE_DIR}/../ChaoticAttractors@ChaoticAttractors/\"\
set(M_EMCC_EMBED_FILES "--preload-file \"${CMAKE_SOURCE_DIR}/Shaders@Shaders/\"\
--preload-file \"${CMAKE_SOURCE_DIR}/image0.png@./\"\
--preload-file \"${CMAKE_SOURCE_DIR}/image1.png@./\"\
--preload-file \"${CMAKE_SOURCE_DIR}/image2.png@./\"")
# --embed-file \"${CMAKE_SOURCE_DIR}/../Fonts/Cousine-Regular.ttf@Fonts/\"\
# --embed-file \"${CMAKE_SOURCE_DIR}/../Fonts/fontawesome-webfont.ttf@Fonts/\"\
# set(M_EMCC_EMBED_FILES "--preload-file \"${CMAKE_SOURCE_DIR}/Shaders@/Shaders\"")
# -s FULL_ES3=1 -s OFFSCREENCANVAS_SUPPORT=1
set(M_EMCC_OGL_OPTIONS "-s USE_WEBGL2=1 -s USE_GLFW=3 -s LEGACY_GL_EMULATION=0 -s OFFSCREENCANVAS_SUPPORT=1 ")
# merge all EMCC_OPTIONS -s BINARYEN_TRAP_MODE=clamp
set(M_EMCC_OPTIONS "-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1 -s ALLOW_MEMORY_GROWTH=1 -s PRECISE_F32=1 ${M_EMCC_SHELL_FILE} ${M_EMCC_OGL_OPTIONS} ${M_EMCC_BINARYEN} ${M_EMCC_EMBED_FILES}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${EMSOUT}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${M_GLOBAL_FLAGS} ${OGL_EMITTER_TYPE} ${M_EMCC_FLAGS} ${M_EMCC_OPTIONS} ${GLAPP_DISABLE_DLA} -Wno-parentheses -Wno-format-security -Wno-logical-op-parentheses -Wno-unused-value -Wdelete-non-virtual-dtor -Wno-unused-command-line-argument")
if(EXISTS $ENV{EMSOUT_PATH})
set(EMSOUT "$ENV{EMSOUT_PATH}/WebGL")
else()
set(EMSOUT "${CMAKE_SOURCE_DIR}/WebGL")
endif()
if(EXISTS $ENV{RAMDISK}) #my RAMDISK env
set(BUILD_DIR $ENV{RAMDISK}/emsOut/${CMAKE_BUILD_TYPE})
else ()
set(BUILD_DIR ${EMSOUT}/${CMAKE_BUILD_TYPE})
endif()
add_executable(${PROJECT_NAME} ${SOURCE_FILES})
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${BUILD_DIR})
###########################################################
# PC setting
###########################################################
else()
set(APP_NAME "SmartDeNoise")
if(APPLE)
project(gl${APP_NAME}_OSX)
else()
if(WIN32)
project(gl${APP_NAME})
else()
project(gl${APP_NAME}_Linux)
endif()
endif()
set(CMAKE_CXX_STANDARD 14)
add_executable(${PROJECT_NAME}
${SRC}/libs/tinyFileDialog/tinyfiledialogs.h
${SRC}/libs/tinyFileDialog/tinyfiledialogs.c
${SRC}/libs/glad/glad.cpp
${SRC}/libs/glad/glad.h
${SOURCE_FILES})
# GLFW package
#
find_package(glfw3)
if(glfw3_FOUND)
set(LIB_GLFW "glfw")
else()
message (FATAL_ERROR "GLFW not found... REQUIRED!!!!")
endif()
# OpenGL
#
find_package(OpenGL)
if(OPENGL_FOUND)
message(STATUS "OPENGL_INCLUDE_DIRS: ${OPENGL_INCLUDE_DIRS}")
message(STATUS "OPENGL_LIBRARY: ${OPENGL_LIBRARY}")
#include_directories(${OPENGL_INCLUDE_DIRS}) # no more necessary: modern OGL uses loaders ==> glad
else ()
message (FATAL_ERROR "OPENGL not found... REQUIRED!!!!")
endif()
if(EXISTS $ENV{RAMDISK}) #my RAMDISK env var
message("RamDisk...")
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY $ENV{RAMDISK}/gl${APP_NAME})
else()
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/..)
endif()
# set(CMAKE_BINARY_DIR "${CMAKE_SOURCE_DIR}/builds")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}")
if(APPLE)
set(COMMON_DEFINES "${BASE_DEFINES} -DGLFW_INCLUDE_NONE -DIMGUI_IMPL_OPENGL_LOADER_GLAD -Wno-logical-op-parentheses -Wno-unused-command-line-argument -Wno-parentheses -framework Cocoa -framework IOKit -framework CoreVideo")
else()
set(COMMON_DEFINES "${BASE_DEFINES} -DGLFW_INCLUDE_NONE -DIMGUI_IMPL_OPENGL_LOADER_GLAD")
endif(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format-security -std=c++14 -fpermissive")
add_definitions(${OGL_VER_USED} ${OGL_EMITTER_TYPE} ${COMMON_DEFINES} ${GLAPP_DISABLE_DLA})
include_directories(${SRC})
include_directories(${SRC}/tools)
include_directories(${SRC}/libs)
# include_directories($ENV{INCLUDE})
#uncomment for GLFW installed dir
if(OPENGL_FOUND)
if(APPLE)
set(TARGET_LIBS "-ldl")
else()
if(WIN32)
set(TARGET_LIBS "-ldl")
else()
set(TARGET_LIBS "-ldl -lX11")
endif(WIN32)
endif(APPLE)
target_link_libraries(${PROJECT_NAME} ${OPENGL_LIBRARY} ${TARGET_LIBS} ${LIB_GLFW})
endif(OPENGL_FOUND)
endif()