-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
74 lines (62 loc) · 2.57 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
cmake_minimum_required(VERSION 3.10)
# If the EMSDK environment variable is set, configure the toolchain file. this has to be done before the project() line below
if(DEFINED ENV{EMSDK})
set(CMAKE_TOOLCHAIN_FILE "$ENV{EMSDK}/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake" CACHE STRING "Emscripten toolchain file")
message(STATUS "WebAssembly build enabled")
message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
else()
message(STATUS "WebAssembly build NOT enabled. EMSDK environment variable is not set. Falling back to native build. If you want to compile for WebAssembly, first `source emsdk_env.sh` in the emsdk directory and then do `mkdir buildwasm && cd buildwasm && emcmake cmake .. && emmake make`")
endif()
project(bgfx-glfw-wasm-3dcube-template-starting-point)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
set(BGFX_DIR ${CMAKE_SOURCE_DIR}/bgfx)
if(NOT DEFINED ENV{EMSDK})
find_package(glfw3 REQUIRED)
find_package(OpenGL REQUIRED)
endif()
include_directories(${BGFX_DIR}/include)
include_directories(${CMAKE_SOURCE_DIR}/bx/include)
include_directories(${CMAKE_SOURCE_DIR}/bimg/include)
add_definitions(-DBX_CONFIG_DEBUG)
add_executable(bgfx-glfw-wasm-3dcube-template-starting-point main.cpp)
file(INSTALL DESTINATION ${CMAKE_BINARY_DIR}
TYPE FILE
FILES ${BGFX_DIR}/examples/runtime/shaders/glsl/vs_cubes.bin
${BGFX_DIR}/examples/runtime/shaders/glsl/fs_cubes.bin)
if(DEFINED ENV{EMSDK})
set(CMAKE_CXX_FLAGS "-s MIN_WEBGL_VERSION=2 \
-s MAX_WEBGL_VERSION=2 \
-s EXCEPTION_DEBUG \
-fexceptions \
--preload-file vs_cubes.bin \
--preload-file fs_cubes.bin \
--bind \
--use-preload-plugins \
-Wall \
-Wextra \
-Werror=return-type \
-s ASSERTIONS=1 \
-w \
-g4 \
-s DISABLE_EXCEPTION_CATCHING=0 \
-Os \
-s USE_GLFW=3 \
--no-heap-copy \
-s GL_ENABLE_GET_PROC_ADDRESS \
-static \
-s ALLOW_MEMORY_GROWTH=1 \
-s EXIT_RUNTIME=1")
target_link_libraries(bgfx-glfw-wasm-3dcube-template-starting-point
${BGFX_DIR}/.build/wasm/bin/bgfxDebug.bc
${BGFX_DIR}/.build/wasm/bin/bxDebug.bc
${BGFX_DIR}/.build/wasm/bin/bimgDebug.bc)
file(INSTALL DESTINATION ${CMAKE_BINARY_DIR}
TYPE FILE
FILES ${CMAKE_SOURCE_DIR}/index.html)
else() # Native Linux/X11
target_link_libraries(bgfx-glfw-wasm-3dcube-template-starting-point
glfw
OpenGL::GL
${BGFX_DIR}/.build/linux64_gcc/bin/libbgfx-shared-libDebug.so)
endif()