Skip to content

Commit c2a3793

Browse files
committed
[build][feature] added emcc WASM build-type support
1 parent 9747e1a commit c2a3793

File tree

4 files changed

+54
-14
lines changed

4 files changed

+54
-14
lines changed

CMakeLists.txt

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,38 @@ set(EKG_VERSION 1.2.0)
2828
message(STATUS "Building EKG user interface library version ${EKG_VERSION}")
2929
project(ekg VERSION ${EKG_VERSION} DESCRIPTION "graphical user interface")
3030

31+
set(
32+
MATCH_SPECIALIZED_COMPILERS_ID
33+
"/emcc"
34+
)
35+
36+
string(
37+
REGEX MATCH
38+
${MATCH_SPECIALIZED_COMPILERS_ID}
39+
MATCHED_COMPILER_FILENAME
40+
${CMAKE_CXX_COMPILER}
41+
)
42+
43+
if(
44+
EKG_WASM_LINUX_EMCC_BUILD
45+
OR
46+
MATCHED_COMPILER_FILENAME STREQUAL "/emcc"
47+
)
48+
message(STATUS "Found specialized compiler ID: ${MATCHED_COMPILER_FILENAME}, WASM build type")
49+
set(EKG_WASM_LINUX_EMCC_BUILD 1)
50+
elseif(EKG_WASM_LINUX_EMCC_BUILD)
51+
message(FATAL_ERROR "No specialized compiler ID was found with '/emcc' for WASM build type")
52+
endif()
53+
54+
if(
55+
CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
56+
OR
57+
CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
58+
)
59+
message(STATUS "Found compiler ID: ${CMAKE_CXX_COMPILER_ID}")
60+
add_compile_options(-O3)
61+
endif()
62+
3163
# Enable if your base OS is Debian-based (e.g Ubuntu).
3264
# It is a common issue related by the Linux community.
3365
if (EKG_LINUX_NOT_FOUND_FREETYPE)
@@ -44,6 +76,9 @@ if(WIN32 OR EKG_FORCE_WINDOWS)
4476
elseif(ANDROID OR EKG_FORCE_ANDROID)
4577
set(LIBRARY_OUTPUT_PATH "${ANDROID_ABI}/")
4678
set(PLATFORM "${ANDROID_ABI}")
79+
elseif(LINUX AND EKG_WASM_LINUX_EMCC_BUILD)
80+
set(LIBRARY_OUTPUT_PATH "../lib/linux-wasm/")
81+
set(PLATFORM "linux-wasm")
4782
elseif(LINUX OR EKG_FORCE_LINUX)
4883
# WSL is not detected as Linux-based OS, same you use a Linux kernel-based distribution.
4984
set(LIBRARY_OUTPUT_PATH "../lib/linux/")
@@ -53,17 +88,16 @@ endif()
5388
message(STATUS "Generating EKG ${PLATFORM} native library")
5489
file(GLOB_RECURSE SOURCE_FILES "src/*.cpp")
5590

56-
if(
57-
CMAKE_CXX_COMPILER_ID STREQUAL "GNU"
58-
OR
59-
CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
60-
)
61-
add_compile_options(-O3)
62-
endif()
63-
6491
include_directories(./include)
6592
add_library(ekg STATIC ${SOURCE_FILES})
6693

94+
if (EKG_WASM_LINUX_EMCC_BUILD)
95+
set_target_properties(
96+
ekg
97+
PROPERTIES LINK_FLAGS "--bind -s USE_FREETYPE=1"
98+
)
99+
endif()
100+
67101
message(STATUS "EKG native library building done")
68102

69103
if(LINUX OR EKG_FORCE_LINUX)

devlog/commit.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,5 @@
230230
-- Added memory-safe method to EKG-tasks and one option to disable that.
231231
-- Added an unsafe function `ekg::draw::scissor`/method to explicit display a new scissor placement (position and size).
232232
-- Solved a visual-glitch where the line always was zero on listbox header(s) and item(s) text-label.
233-
-- Fixed a glitch where dragging and swap was not working out of header(s)-rect boudings.
233+
-- Fixed a glitch where dragging and swap was not working out of header(s)-rect boudings.
234+
-- Added WASM build-type compatibility.

ekg-ui-library.sublime-project

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,10 @@
3737
"shell_cmd":
3838
"cd $folder && cmake -S . -B ./cmake-build/ -G Ninja -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DEKG_LINUX_NOT_FOUND_FREETYPE=1 && cmake --build ./cmake-build/ && cd ./test && cmake -S . -B ./cmake-build -G Ninja -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DEKG_LINUX_NOT_FOUND_FREETYPE=1 && cmake --build ./cmake-build && cd ./bin && ./ekg-gui-showcase-test"
3939
},
40+
{
41+
"name": "Linux Build WASM",
42+
"shell_cmd":
43+
"cd $folder && emcmake cmake -S . -B ./cmake-build/ -G Ninja -DEKG_LINUX_NOT_FOUND_FREETYPE=1 -DCMAKE_CXX_COMPILER=/home/rina/emsdk/emsdk/upstream/emscripten/emcc -DCMAKE_EXPORT_COMPILE_COMMANDS=1 && cmake --build ./cmake-build"
44+
}
4045
],
4146
}

test/CMakeLists.txt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cmake_minimum_required(VERSION 3.10)
22

3-
message("-- EKG tests enabled")
4-
message("-- EKG GUI showcase test building")
3+
message(STATUS "EKG tests enabled")
4+
message(STATUS "EKG GUI showcase test building")
55

66
project(ekg-gui-showcase-test)
77

@@ -21,7 +21,7 @@ else()
2121
# It is a common issue related by the Linux community.
2222
if (EKG_LINUX_NOT_FOUND_FREETYPE)
2323
include_directories(/usr/include/freetype2)
24-
message("-- Using var EKG_LINUX_NOT_FOUND_FREETYPE to include `/usr/include/freetype2` directly")
24+
message(STATUS "Using var EKG_LINUX_NOT_FOUND_FREETYPE to include `/usr/include/freetype2` directly")
2525
endif()
2626

2727
set(PLATFORM "linux")
@@ -32,7 +32,7 @@ include_directories(../include)
3232
add_executable(ekg-gui-showcase-test "src/ekg_gui_showcase_test.cpp")
3333

3434
file(GLOB LIBRARY_PATH "../lib/${PLATFORM}/libekg.a")
35-
message("-- EKG GUI test found native library on: ${LIBRARY_PATH}")
35+
message(STATUS "EKG GUI test found native library on: ${LIBRARY_PATH}")
3636

3737
if (WIN32)
3838
set(THIRD_PARTY_LIBRARIES mingw32 SDL2main SDL2 opengl32 glew32 freetype)
@@ -47,4 +47,4 @@ target_link_libraries(
4747
-static-libgcc -static-libstdc++
4848
)
4949

50-
message("-- EKG GUI showcase test building done")
50+
message(STATUS "EKG GUI showcase test building done")

0 commit comments

Comments
 (0)