-
Notifications
You must be signed in to change notification settings - Fork 42
/
CMakeLists.txt
179 lines (146 loc) · 6.82 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
cmake_minimum_required(VERSION 3.10)
set(BUILD_EMSCRIPTEN FALSE CACHE BOOL FALSE)
# To build with SDL framwework and VirtualGizmo type:
# cmake -DUSE_SDL:BOOL=TRUE -DUSE_VIRTUALGIZMO:BOOL=TRUE .
set(USE_SDL FALSE CACHE BOOL FALSE)
set(USE_VIRTUALGIZMO FALSE CACHE BOOL FALSE)
set(IMGUI_DIR imgui)
set(CMAKE_CXX_STANDARD 11)
set(M_GLOBAL_FLAGS "-DIMGUI_DIR -DGLM_ENABLE_EXPERIMENTAL")
if(USE_VIRTUALGIZMO)
set(M_GLOBAL_FLAGS "${M_GLOBAL_FLAGS} -DGLAPP_USE_VIRTUALGIZMO")
endif()
# relative source directory
set(SRC "${CMAKE_SOURCE_DIR}/src")
set(SOURCE_FILES
${SRC}/glApp.h
${SRC}/glApp.cpp
${SRC}/glWindow.h
${SRC}/glWindow.cpp
${SRC}/qJulia.h
${SRC}/qJulia.cpp
${SRC}/ui/uiMainDlg.h
${SRC}/ui/uiMainDlg.cpp
${SRC}/ui/uiSettings.cpp
${SRC}/tools/glslProgramObject.cpp
${SRC}/tools/glslShaderObject.cpp
${SRC}/tools/glslProgramObject.h
${SRC}/tools/glslShaderObject.h
${SRC}/tools/imGuIZMOquat.cpp
${SRC}/tools/imGuIZMOquat.h
${SRC}/tools/vGizmo.h
${SRC}/tools/vgMath.h
${SRC}/tools/vgConfig.h
${SRC}/libs/${IMGUI_DIR}/imconfig.h
${SRC}/libs/${IMGUI_DIR}/imgui.h
${SRC}/libs/${IMGUI_DIR}/imgui.cpp
${SRC}/libs/${IMGUI_DIR}/imgui_widgets.cpp
${SRC}/libs/${IMGUI_DIR}/imgui_draw.cpp
${SRC}/libs/${IMGUI_DIR}/imgui_demo.cpp
${SRC}/libs/${IMGUI_DIR}/imgui_impl_opengl3.cpp
${SRC}/libs/${IMGUI_DIR}/imgui_impl_opengl3.h
${SRC}/libs/${IMGUI_DIR}/imgui_internal.h
${SRC}/libs/${IMGUI_DIR}/imstb_rectpack.h
${SRC}/libs/${IMGUI_DIR}/imstb_textedit.h
${SRC}/libs/${IMGUI_DIR}/imstb_truetype.h)
# additional INCLUDE directories
include_directories(${SRC})
include_directories(${SRC}/libs)
include_directories(${SRC}/tools)
include_directories(${SRC}/tools)
#include_directories($ENV{INCLUDE})
#include_directories("D:/Lang/mingw64/include")
# additional LIB directories
# link_directories($ENV{LIB})
if (${BUILD_EMSCRIPTEN})
project(wgl_qjSet)
add_executable(${PROJECT_NAME} ${SOURCE_FILES}
${SRC}/libs/${IMGUI_DIR}/imgui_impl_glfw.cpp
${SRC}/libs/${IMGUI_DIR}/imgui_impl_glfw.h)
set(M_GLOBAL_FLAGS "${M_GLOBAL_FLAGS} -DGLAPP_NO_GLSL_PIPELINE -DIMGUI_IMPL_OPENGL_ES3 -DGLFW_INCLUDE_NONE -DGLAPP_NO_OGL_DSA -DGLFW_INCLUDE_ES3")
# set(CMAKE_C_COMPILER "emcc")
# set(CMAKE_CXX_COMPILER "emcc")
# -o ${PROJECT_NAME}.html -> CMAKE_EXECUTABLE_SUFFIX .html .bc, .js (default), etc
set(CMAKE_EXECUTABLE_SUFFIX ".html")
# relative emscripten output files
set(EMSOUT "emsOut")
file(MAKE_DIRECTORY ${EMSOUT})
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")
# 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}/shell_minimal.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 \"${SRC}/shell_minimal.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 "-s WASM=1 -s SINGLE_FILE=1 --memory-init-file 0")
set(M_EMCC_SHELL_FILE "--shell-file \"${SRC}/mVeryMinimal.html\"")
else() # Release
# -s SINGLE_FILE=1 --memory-init-file 0 -s \"BINARYEN_METHOD='interpret-asm2wasm'\"
set(M_EMCC_BINARYEN "-s WASM=1 -s \"BINARYEN_METHOD='native-wasm'\" ")
set(M_EMCC_SHELL_FILE "--shell-file \"${SRC}/mVeryMinimal.html\"")
endif()
endif()
endif()
# grouped EMCC_OPTIONS
set(M_EMCC_EMBED_FILES "--embed-file \"${CMAKE_SOURCE_DIR}/Shaders/qjFragES2.glsl@Shaders/\" --embed-file \"${CMAKE_SOURCE_DIR}/Shaders/qjVert.glsl@Shaders/\"")
# 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
# set(M_EMCC_OPTIONS "-s \"BINARYEN_TRAP_MODE='clamp'\" ${M_EMCC_SHELL_FILE} ${M_EMCC_OGL_OPTIONS} ${M_EMCC_BINARYEN} ${M_EMCC_EMBED_FILES}")
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 "${CMAKE_SOURCE_DIR}/${EMSOUT}")
set(CMAKE_BINARY_DIR "${CMAKE_SOURCE_DIR}/${EMSOUT}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${M_GLOBAL_FLAGS} ${M_EMCC_FLAGS} ${M_EMCC_OPTIONS}")
# set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "${M_EMCC_OPTIONS}")
else()
project(qjSet)
find_package(OpenGL REQUIRED)
set(M_GLOBAL_FLAGS "${M_GLOBAL_FLAGS} -DIMGUI_IMPL_OPENGL_LOADER_GLAD -DGLFW_INCLUDE_NONE -DGLAPP_NO_OGL_DSA")
if(USE_SDL)
add_executable(${PROJECT_NAME} ${SOURCE_FILES}
${SRC}/libs/glad/glad.cpp
${SRC}/libs/${IMGUI_DIR}/imgui_impl_sdl.cpp
${SRC}/libs/${IMGUI_DIR}/imgui_impl_sdl.h)
set(M_GLOBAL_FLAGS "${M_GLOBAL_FLAGS} -DGLAPP_USE_SDL")
else()
add_executable(${PROJECT_NAME} ${SOURCE_FILES}
${SRC}/libs/glad/glad.cpp
${SRC}/libs/${IMGUI_DIR}/imgui_impl_glfw.cpp
${SRC}/libs/${IMGUI_DIR}/imgui_impl_glfw.h)
endif(USE_SDL)
set(M_CXX_FLAGS "-DAPP_REQUIRE_OGL45")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${M_GLOBAL_FLAGS} ${M_CXX_FLAGS}")
if(WIN32)
set(TARGET_LIBS "")
else()
set(TARGET_LIBS ${CMAKE_DL_LIBS})
endif()
if(USE_SDL)
find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} ${OPENGL_gl_LIBRARY} ${SDL2_LIBRARIES} ${TARGET_LIBS})
else()
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}")
if(WIN32)
find_package(glfw3 REQUIRED)
#link_directories(${SRC}/libs/glfw/buildWin/lib/${CMAKE_BUILD_TYPE})
#set(TARGET_LIBS ${CMAKE_DL_LIBS} "${SRC}/libs/glfw/buildWin/lib/${CMAKE_BUILD_TYPE}/glfw3.lib")
#set(TARGET_LIBS ${CMAKE_DL_LIBS} "-lglfw3.lib")
else()
#find_package(glfw3 REQUIRED)
set(TARGET_LIBS ${CMAKE_DL_LIBS} "-lglfw3 -lpthread -lX11")
endif(WIN32)
target_link_libraries(${PROJECT_NAME} ${OPENGL_gl_LIBRARY} ${GLFW3_LIBRARY})
endif()
endif ()