@@ -2,27 +2,28 @@ include(FetchContent)
22
33
44set (BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE )
5- set (GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE )
6- set (GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE )
7- set (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
8-
95FetchContent_Declare (
106 imgui
117 GIT_REPOSITORY https://github.com/ocornut/imgui
128 GIT_TAG docking
139)
1410
15- FetchContent_Declare (
16- glfw
17- GIT_REPOSITORY https://github.com/glfw/glfw
18- GIT_TAG 3.3.8
19- )
11+ if (NOT EMSCRIPTEN)
12+ FetchContent_Declare (
13+ glfw
14+ GIT_REPOSITORY https://github.com/glfw/glfw
15+ GIT_TAG 3.3.8
16+ )
17+ set (GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE )
18+ set (GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE )
19+ set (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
20+ FetchContent_MakeAvailable (glfw)
21+ endif ()
2022
2123set (GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE )
2224set (GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE )
2325set (GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE )
2426
25- FetchContent_MakeAvailable (glfw)
2627
2728FetchContent_Declare (
2829 glm
@@ -32,8 +33,10 @@ FetchContent_Declare(
3233FetchContent_MakeAvailable (glm)
3334
3435
35- add_library (glad STATIC
36- glad/src/glad.c )
36+ if (NOT EMSCRIPTEN)
37+ add_library (glad STATIC glad/src/glad.c )
38+ target_include_directories (glad PUBLIC glad/include )
39+ endif ()
3740
3841
3942add_library (learnopengl
@@ -42,13 +45,16 @@ add_library(learnopengl
4245 "learnopengl/include/stb_image/stb_image.h"
4346 "learnopengl/src/stb_image.cpp" "learnopengl/include/camera/camera.h" "learnopengl/src/camera.cpp" "learnopengl/include/VAO/VAO.h" "learnopengl/include/VBO/VBO.h" "learnopengl/src/VAO.cpp" "learnopengl/src/VBO.cpp" "learnopengl/include/texture/texture.h" "learnopengl/src/texture.cpp" )
4447
45- target_include_directories (glad PUBLIC glad/include )
4648target_include_directories (learnopengl PUBLIC learnopengl/include )
47- target_link_libraries (learnopengl PUBLIC
48- glad
49- glm::glm )
49+ if (EMSCRIPTEN)
50+ target_link_libraries (learnopengl PUBLIC glm::glm )
51+ else ()
52+ target_link_libraries (learnopengl PUBLIC glad glm::glm OpenGL::GL )
53+ endif ()
5054
51- find_package (OpenGL REQUIRED )
55+ if (NOT EMSCRIPTEN)
56+ find_package (OpenGL REQUIRED )
57+ endif ()
5258
5359FetchContent_MakeAvailable (imgui)
5460
@@ -60,13 +66,16 @@ add_library(imgui STATIC
6066 ${imgui_SOURCE_DIR } /imgui_widgets.cpp
6167 ${imgui_SOURCE_DIR } /backends/imgui_impl_glfw.cpp
6268 ${imgui_SOURCE_DIR } /backends/imgui_impl_opengl3.cpp
63- )
69+ )
6470
6571target_include_directories (imgui PUBLIC
6672 ${imgui_SOURCE_DIR }
6773 ${imgui_SOURCE_DIR } /backends
6874)
6975
70- target_link_libraries (imgui PUBLIC glfw OpenGL::GL )
71-
72- target_link_libraries (learnopengl PUBLIC OpenGL::GL )
76+ if (EMSCRIPTEN)
77+ target_compile_options (imgui PRIVATE "-s" "USE_GLFW=3" )
78+ else ()
79+ target_link_libraries (imgui PUBLIC glfw OpenGL::GL )
80+ target_link_libraries (learnopengl PUBLIC OpenGL::GL )
81+ endif ()
0 commit comments