@@ -4,22 +4,24 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) # Group CMake targets inside a fol
44set (CMAKE_EXPORT_COMPILE_COMMANDS ON ) # Generate compile_commands.json for language servers
55
66include (FetchContent )
7- option (GLFW_BUILD_EXAMPLES OFF )
8- option (GLFW_BUILD_TESTS OFF )
9- option (GLFW_BUILD_DOCS OFF )
10- option (GLFW_INSTALL OFF )
11- FetchContent_Declare (
12- glfw
13- GIT_REPOSITORY https://github.com/glfw/glfw.git
14- GIT_TAG 3.3.8
15- )
16- list (APPEND FETCH_CONTENTS glfw)
17- FetchContent_Declare (
18- glad
19- GIT_REPOSITORY https://github.com/mononerv/glad.git
20- GIT_TAG f4759d7c5143c0a23391ab05caaf43052cefdd65
21- )
22- list (APPEND FETCH_CONTENTS glad)
7+ if (NOT EMSCRIPTEN)
8+ option (GLFW_BUILD_EXAMPLES OFF )
9+ option (GLFW_BUILD_TESTS OFF )
10+ option (GLFW_BUILD_DOCS OFF )
11+ option (GLFW_INSTALL OFF )
12+ FetchContent_Declare (
13+ glfw
14+ GIT_REPOSITORY https://github.com/glfw/glfw.git
15+ GIT_TAG 3.4
16+ )
17+ list (APPEND FETCH_CONTENTS glfw)
18+ FetchContent_Declare (
19+ glad
20+ GIT_REPOSITORY https://github.com/mononerv/glad.git
21+ GIT_TAG f4759d7c5143c0a23391ab05caaf43052cefdd65
22+ )
23+ list (APPEND FETCH_CONTENTS glad)
24+ endif ()
2325FetchContent_Declare (
2426 fmt
2527 GIT_REPOSITORY https://github.com/fmtlib/fmt.git
@@ -50,6 +52,12 @@ FetchContent_Declare(
5052 GIT_TAG 698c6fb9889c71494b49c9187d249af5fc87b211
5153)
5254list (APPEND FETCH_CONTENTS stb)
55+ FetchContent_Declare (
56+ asio
57+ GIT_REPOSITORY https://github.com/mononerv/asio.git
58+ GIT_TAG bcb8a933b27021d77f2d183991d815ea6c8cdc97
59+ )
60+ list (APPEND FETCH_CONTENTS asio)
5361FetchContent_MakeAvailable (${FETCH_CONTENTS} )
5462
5563# Group dependencies in Visual Studio and Xcode
@@ -63,22 +71,44 @@ if (CMAKE_GENERATOR MATCHES "Visual Studio" OR CMAKE_GENERATOR MATCHES "Xcode")
6371endif ()
6472
6573if (APPLE )
74+ message ("Platform: macOS" )
6675 set (PLATFORM_LINK_LIBRARIES
6776 "-framework Cocoa"
6877 "-framework IOKit"
6978 "-framework CoreVideo"
7079 "-framework OpenGL"
7180 )
72- elseif (UNIX AND NOT APPLE ) # Linux, BSD, Solaris, Minix
81+ elseif (UNIX AND NOT APPLE AND NOT EMSCRIPTEN) # Linux, BSD, Solaris, Minix
82+ message ("Platform: Linux" )
7383 set (PLATFORM_LINK_LIBRARIES
7484 "dl"
7585 "m"
86+ "GL"
7687 "X11"
7788 )
7889elseif (WIN32 )
90+ message ("Platform: Windows" )
7991 set (PLATFORM_LINK_LIBRARIES "OpenGL32.lib" )
92+ set (PLATFORM_DEFINTIONS
93+ ${PLATFORM_DEFINTIONS}
94+ "_WIN32_WINNT=0x0A00"
95+ )
96+ elseif (EMSCRIPTEN)
97+ message ("Platform: Emscripten" )
98+ add_compile_definitions (
99+ "GL_GLEXT_PROTOTYPES"
100+ "GL3_PROTOTYPES"
101+ )
102+ add_compile_options ("-pthread" "-fexceptions" )
103+ add_link_options (
104+ "-sLEGACY_GL_EMULATION=0"
105+ "-sUSE_WEBGL2=1"
106+ "-sFULL_ES3=1"
107+ "-fexceptions"
108+ "-sALLOW_MEMORY_GROWTH"
109+ )
80110else ()
81- message (FATAL_ERROR "Unkown platform !" )
111+ message (FATAL_ERROR "Platform: Unkown !" )
82112endif ()
83113
84114# Compiler specific options
@@ -98,7 +128,22 @@ if (NOT MSVC)
98128 # glm warnings
99129 "-Wno-nested-anon-types"
100130 "-Wno-gnu-anonymous-struct"
131+ # clang on windows
132+ "-Wno-microsoft-include"
133+ # asio
134+ "-Wno-sign-conversion"
135+ "-Wno-implicit-int-conversion"
101136 )
137+ if (EMSCRIPTEN)
138+ set (BASE_OPTIONS
139+ ${BASE_OPTIONS}
140+ # asio
141+ "-Wno-shadow"
142+ "-Wno-shorten-64-to-32"
143+ "-Wno-unused-private-field"
144+ "-Wno-deprecated-declarations"
145+ )
146+ endif ()
102147else ()
103148 set (BASE_OPTIONS
104149 "/W4"
@@ -112,29 +157,34 @@ endif()
112157
113158# libtxtr
114159set (HEADERS
115- txt/buffer.hpp
160+ txt/graphics/buffer.hpp
161+ txt/graphics/image.hpp
162+ txt/graphics/shader.hpp
163+ txt/graphics/texture.hpp
164+ txt/text/engine.hpp
165+ txt/text/fonts.hpp
166+ txt/input/keyboard.hpp
167+ txt/input/mouse.hpp
168+ txt/input/touch.hpp
116169 txt/event.hpp
117- txt/fonts.hpp
118- txt/image.hpp
119170 txt/input.hpp
120171 txt/renderer.hpp
121- txt/shader.hpp
122- txt/text_engine.hpp
123- txt/texture.hpp
124172 txt/types.hpp
125- txt/utility .hpp
173+ txt/utils .hpp
126174 txt/window.hpp
127175)
128176set (SOURCES
129- txt/buffer.cpp
130- txt/fonts.cpp
131- txt/image.cpp
132- txt/input.cpp
133- txt/renderer.cpp
134- txt/shader.cpp
135- txt/text_engine.cpp
136- txt/texture.cpp
137- txt/window.cpp
177+ txt/graphics/buffer.cpp
178+ txt/graphics/image.cpp
179+ txt/graphics/renderer.cpp
180+ txt/graphics/shader.cpp
181+ txt/graphics/texture.cpp
182+ txt/input/input.cpp
183+ txt/text/engine.cpp
184+ txt/text/fonts.cpp
185+ txt/window/window.cpp
186+ $<$<NOT :$<BOOL :${EMSCRIPTEN} >>:txt /window /glfw_window .cpp >
187+ $<$<BOOL :${EMSCRIPTEN} >:txt /window /web_window .cpp >
138188)
139189add_library (libtxtr STATIC ${HEADERS} ${SOURCES} )
140190target_include_directories (libtxtr
@@ -145,21 +195,24 @@ target_include_directories(libtxtr
145195)
146196target_compile_features (libtxtr PRIVATE cxx_std_23 )
147197target_compile_options (libtxtr PRIVATE ${BASE_OPTIONS} )
198+ target_compile_definitions (libtxtr PRIVATE ${PLATFORM_DEFINTIONS} )
148199target_link_libraries (libtxtr
149200 PRIVATE
150201 ${PLATFORM_LINK_LIBRARIES}
151- glfw
152- fmt
153202 utf8::cpp
154203 stb::stb
204+ fmt
205+ $<$<NOT :$<BOOL :${EMSCRIPTEN} >>:glfw >
155206
156207 PUBLIC
208+ asio::asio
157209 freetype
158- glad
210+ $<$< NOT :$< BOOL : ${EMSCRIPTEN} >>: glad :: glad >
159211 glm
160212)
161- source_group (TREE "${CMAKE_CURRENT_LIST_DIR} " FILES ${HEADERS} ${SOURCES} )
213+ # source_group(TREE "${CMAKE_CURRENT_LIST_DIR}" FILES ${HEADERS} ${SOURCES})
162214
215+ # hellotext app
163216set (HEADERS
164217 demos/app.hpp
165218 demos/text_bounce.hpp
@@ -171,6 +224,7 @@ add_executable(hellotext ${HEADERS} ${SOURCES})
171224target_include_directories (hellotext PRIVATE ${PROJECT_SOURCE_DIR} )
172225target_compile_features (hellotext PRIVATE cxx_std_20 )
173226target_compile_options (hellotext PRIVATE ${BASE_OPTIONS} )
227+ target_compile_definitions (hellotext PRIVATE ${PLATFORM_DEFINTIONS} )
174228target_link_libraries (hellotext
175229 PRIVATE
176230 ${PLATFORM_LINK_LIBRARIES}
0 commit comments