Skip to content

Commit 358c47d

Browse files
authored
Merge pull request #15 from Moros1138/develop
Switch to CMake and Test new build and deployment workflows
2 parents 8dbac31 + 2040120 commit 358c47d

10 files changed

+282
-25
lines changed

.github/workflows/emscripten-build.yml

+4-6
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ jobs:
1515

1616
steps:
1717
- name: Checkout source code
18-
uses: actions/checkout@v3
18+
uses: actions/checkout@v4
1919
with:
2020
submodules: 'recursive'
2121

2222
- name: Set up Python (required for Emscripten)
23-
uses: actions/setup-python@v4
23+
uses: actions/setup-python@v5
2424
with:
2525
python-version: '3.x'
2626

@@ -36,8 +36,6 @@ jobs:
3636
- name: Build with Emscripten
3737
run: |
3838
source emsdk/emsdk_env.sh
39-
cd demo
40-
make emscripten
39+
emcmake cmake . -B emscripten-build
40+
cmake --build emscripten-build --config=Release
4141
shell: bash
42-
43-

.github/workflows/emscripten-deploy.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ jobs:
1111

1212
steps:
1313
- name: Checkout source code
14-
uses: actions/checkout@v3
14+
uses: actions/checkout@v4
1515
with:
1616
submodules: 'recursive'
1717

1818
- name: Set up Python (required for Emscripten)
19-
uses: actions/setup-python@v4
19+
uses: actions/setup-python@v5
2020
with:
2121
python-version: '3.x'
2222

@@ -32,8 +32,8 @@ jobs:
3232
- name: Build with Emscripten
3333
run: |
3434
source emsdk/emsdk_env.sh
35-
cd demo
36-
make emscripten
35+
emcmake cmake . -B emscripten-build
36+
cmake --build emscripten-build --config=Release
3737
shell: bash
3838

3939
- name: Deploy Main Demo
@@ -43,7 +43,7 @@ jobs:
4343
username: ${{ secrets.REMOTE_SERVER_USER }}
4444
key: ${{ secrets.REMOTE_SERVER_SSH_KEY }}
4545
port: ${{ secrets.REMOTE_SERVER_PORT }}
46-
source: "demo/demo.html,demo/demo.js,demo/demo.wasm,demo/demo.data"
46+
source: "emscripten-build/demo.html,emscripten-build/demo.js,emscripten-builddemo.wasm,emscripten-build/demo.data"
4747
target: ${{ secrets.REMOTE_SERVER_DIRECTORY }}
4848
strip_components: 1
4949

@@ -54,7 +54,7 @@ jobs:
5454
username: ${{ secrets.REMOTE_SERVER_USER }}
5555
key: ${{ secrets.REMOTE_SERVER_SSH_KEY }}
5656
port: ${{ secrets.REMOTE_SERVER_PORT }}
57-
source: "demo/demo_waveform.html,demo/demo_waveform.js,demo/demo_waveform.wasm,demo/demo_waveform.data"
57+
source: "emscripten-build/demo_waveform.html,emscripten-build/demo_waveform.js,emscripten-build/demo_waveform.wasm,emscripten-build/demo_waveform.data"
5858
target: ${{ secrets.REMOTE_SERVER_DIRECTORY }}
5959
strip_components: 1
6060

@@ -65,6 +65,6 @@ jobs:
6565
username: ${{ secrets.REMOTE_SERVER_USER }}
6666
key: ${{ secrets.REMOTE_SERVER_SSH_KEY }}
6767
port: ${{ secrets.REMOTE_SERVER_PORT }}
68-
source: "demo/demo_synthesis.html,demo/demo_synthesis.js,demo/demo_synthesis.wasm,demo/demo_synthesis.data"
68+
source: "emscripten-build/demo_synthesis.html,emscripten-build/demo_synthesis.js,emscripten-build/demo_synthesis.wasm,emscripten-build/demo_synthesis.data"
6969
target: ${{ secrets.REMOTE_SERVER_DIRECTORY }}
7070
strip_components: 1

.gitignore

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
.vscode
2-
demo/demo*
3-
!demo/demo.cpp
4-
2+
build
3+
emscripten-build

CMakeLists.txt

+262
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
# require version 3.10 or higher
2+
cmake_minimum_required(VERSION 3.10)
3+
4+
project(olcPGEX_MiniAudio)
5+
6+
option(UPDATE_GIT_SUBMODULES "Update Git submodules" ON)
7+
8+
if (UPDATE_GIT_SUBMODULES)
9+
message(STATUS "Updating Git submodules...")
10+
execute_process(
11+
COMMAND git submodule update --init --recursive
12+
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
13+
RESULT_VARIABLE result
14+
)
15+
16+
if(NOT result EQUAL 0)
17+
message(FATAL_ERROR "Failed to update Git submodules")
18+
endif()
19+
endif()
20+
21+
# Set C++ Standards
22+
set(CMAKE_CXX_STANDARD 20)
23+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
24+
set(CMAKE_CXX_EXTENSIONS OFF)
25+
26+
function(add_common_settings target)
27+
28+
######################################################################
29+
# MacOS
30+
######################################################################
31+
if(APPLE)
32+
33+
# OpenGL
34+
set(OpenGL_GL_PREFERENCE LEGACY)
35+
find_package(OpenGL REQUIRED)
36+
include_directories(${OpenGL_INCLUDE_DIRS})
37+
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)
38+
39+
# Carbon
40+
FIND_LIBRARY(CARBON_LIBRARY Carbon)
41+
target_link_libraries(${target} ${CARBON_LIBRARY})
42+
43+
# GLUT
44+
find_package(GLUT REQUIRED)
45+
target_link_libraries(${target} ${GLUT_LIBRARIES})
46+
47+
# Threads
48+
find_package(Threads REQUIRED)
49+
target_link_libraries(${target} Threads::Threads)
50+
include_directories(${Threads_INCLUDE_DIRS})
51+
52+
find_package(PNG REQUIRED)
53+
target_link_libraries(${target} PNG::PNG)
54+
include_directories(${PNG_INCLUDE_DIRS})
55+
56+
# debug mode!
57+
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>)
58+
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>)
59+
60+
endif() # APPLE
61+
62+
63+
######################################################################
64+
# Windows: MinGW
65+
######################################################################
66+
if(WIN32 AND MINGW)
67+
68+
# OpenGL
69+
set(OpenGL_GL_PREFERENCE LEGACY)
70+
find_package(OpenGL REQUIRED)
71+
include_directories(${OpenGL_INCLUDE_DIRS})
72+
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)
73+
74+
if (NOT HAS_TERMINAL)
75+
target_link_libraries(${target} -mwindows -municode)
76+
endif (NOT HAS_TERMINAL)
77+
78+
# GDI+
79+
set(GDIPLUS_LIBRARY gdiplus)
80+
target_link_libraries(${target} ${GDIPLUS_LIBRARY})
81+
82+
# Shlwapi
83+
set(SHLWAPI_LIBRARY shlwapi)
84+
target_link_libraries(${target} ${SHLWAPI_LIBRARY})
85+
86+
# Dwmapi
87+
set(DWMAPI_LIBRARY dwmapi)
88+
target_link_libraries(${target} ${DWMAPI_LIBRARY})
89+
90+
# stdc++fs
91+
target_link_libraries(${target} stdc++fs)
92+
93+
# debug mode!
94+
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>)
95+
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>)
96+
97+
endif()
98+
99+
######################################################################
100+
# Windows: Visual Studio / MSVC
101+
######################################################################
102+
if(WIN32 AND MSVC)
103+
104+
# OpenGL
105+
set(OpenGL_GL_PREFERENCE LEGACY)
106+
find_package(OpenGL REQUIRED)
107+
include_directories(${OpenGL_INCLUDE_DIRS})
108+
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)
109+
110+
# set the startup project to the target executable instead of ALL_BUILD
111+
set_property(
112+
DIRECTORY
113+
${CMAKE_CURRENT_SOURCE_DIR}
114+
PROPERTY
115+
VS_STARTUP_PROJECT
116+
${target}
117+
)
118+
119+
# set working directory for Visual Studio Debugger
120+
set_target_properties(
121+
${target} PROPERTIES
122+
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
123+
)
124+
125+
# set subsytem, console if HAS_TERMINAL is true. windows if not
126+
if (HAS_TERMINAL)
127+
target_link_options(${target} PRIVATE "/SUBSYSTEM:CONSOLE")
128+
else ()
129+
target_link_options(${target} PRIVATE "/SUBSYSTEM:WINDOWS")
130+
endif ()
131+
132+
# GDI+
133+
set(GDIPLUS_LIBRARY gdiplus)
134+
target_link_libraries(${target} ${GDIPLUS_LIBRARY})
135+
136+
# Shlwapi
137+
set(SHLWAPI_LIBRARY shlwapi)
138+
target_link_libraries(${target} ${SHLWAPI_LIBRARY})
139+
140+
# Dwmapi
141+
set(DWMAPI_LIBRARY dwmapi)
142+
target_link_libraries(${target} ${DWMAPI_LIBRARY})
143+
144+
# debug mode!
145+
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>)
146+
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>)
147+
148+
endif() # Visual Studio / MSVC
149+
150+
######################################################################
151+
# Linux: using anything?
152+
######################################################################
153+
if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)
154+
155+
# OpenGL
156+
set(OpenGL_GL_PREFERENCE LEGACY)
157+
find_package(OpenGL REQUIRED)
158+
include_directories(${OpenGL_INCLUDE_DIRS})
159+
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)
160+
161+
# X11
162+
find_package(X11 REQUIRED)
163+
target_link_libraries(${target} X11::X11)
164+
165+
include_directories(${X11_INCLUDE_DIRS})
166+
167+
# Threads
168+
find_package(Threads REQUIRED)
169+
target_link_libraries(${target} Threads::Threads)
170+
include_directories(${Threads_INCLUDE_DIRS})
171+
172+
find_package(PNG REQUIRED)
173+
target_link_libraries(${target} PNG::PNG)
174+
include_directories(${PNG_INCLUDE_DIRS})
175+
176+
# stdc++fs
177+
target_link_libraries(${target} stdc++fs)
178+
179+
# dl, for miniaudio
180+
target_link_libraries(${target} dl)
181+
182+
# debug mode!
183+
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>)
184+
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>)
185+
186+
endif() # Linux
187+
188+
######################################################################
189+
# Emscripten
190+
######################################################################
191+
if (EMSCRIPTEN)
192+
193+
# build Cache: libpng, zlib
194+
execute_process(COMMAND "${EMSCRIPTEN_ROOT_PATH}/embuilder${EMCC_SUFFIX}" build libpng zlib)
195+
196+
# debug mode!
197+
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>)
198+
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>)
199+
200+
target_link_options(${target} PRIVATE -sALLOW_MEMORY_GROWTH=1)
201+
target_link_options(${target} PRIVATE -sSTACK_SIZE=131072)
202+
target_link_options(${target} PRIVATE -sMAX_WEBGL_VERSION=2)
203+
target_link_options(${target} PRIVATE -sMIN_WEBGL_VERSION=2)
204+
target_link_options(${target} PRIVATE -sUSE_LIBPNG=1)
205+
target_link_options(${target} PRIVATE -sLLD_REPORT_UNDEFINED)
206+
target_link_options(${target} PRIVATE --shell-file "${CMAKE_CURRENT_SOURCE_DIR}/shell.html")
207+
target_link_options(${target} PRIVATE --preload-file ${CMAKE_SOURCE_DIR}/demo/assets@assets)
208+
209+
endif() # Emscripten
210+
211+
include_directories(${CMAKE_SOURCE_DIR})
212+
include_directories(third_party/miniaudio)
213+
include_directories(third_party/olcPixelGameEngine)
214+
215+
216+
if (NOT EMSCRIPTEN)
217+
add_custom_command(
218+
TARGET ${target}
219+
POST_BUILD
220+
COMMAND ${CMAKE_COMMAND}
221+
ARGS -E copy_directory ${CMAKE_SOURCE_DIR}/demo/assets ${CMAKE_BINARY_DIR}/assets
222+
)
223+
endif()
224+
225+
endfunction()
226+
227+
# Executable aka binary output
228+
add_executable(
229+
demo
230+
demo/demo.cpp
231+
demo/common.cpp
232+
olcPGEX_MiniAudio.h
233+
third_party/olcPixelGameEngine/olcPixelGameEngine.h
234+
third_party/miniaudio/miniaudio.h
235+
)
236+
237+
add_executable(
238+
demo_synthesis
239+
demo/demo_synthesis.cpp
240+
demo/common.cpp
241+
olcPGEX_MiniAudio.h
242+
third_party/olcPixelGameEngine/olcPixelGameEngine.h
243+
third_party/miniaudio/miniaudio.h
244+
)
245+
246+
add_executable(
247+
demo_waveform
248+
demo/demo_waveform.cpp
249+
demo/common.cpp
250+
olcPGEX_MiniAudio.h
251+
third_party/olcPixelGameEngine/olcPixelGameEngine.h
252+
third_party/miniaudio/miniaudio.h
253+
)
254+
255+
if (EMSCRIPTEN)
256+
# generate an HTML file
257+
set(CMAKE_EXECUTABLE_SUFFIX .html)
258+
endif()
259+
260+
add_common_settings(demo)
261+
add_common_settings(demo_synthesis)
262+
add_common_settings(demo_waveform)

demo/assets/pack.pak

5.72 MB
Binary file not shown.

demo/common.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#define OLC_PGE_APPLICATION
2+
#include "olcPixelGameEngine.h"
3+
4+
#define OLC_PGEX_MINIAUDIO
5+
#include "olcPGEX_MiniAudio.h"

demo/demo.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#define OLC_PGE_APPLICATION
21
#include "olcPixelGameEngine.h"
3-
4-
#define OLC_PGEX_MINIAUDIO
52
#include "olcPGEX_MiniAudio.h"
63

74
constexpr float thirtyFramesPerSecond = 1.0f / 30.f;
@@ -28,6 +25,7 @@ class Demo : public olc::PixelGameEngine
2825
//
2926
// see how we get a pointer of the song1 sound?
3027
ma_sound_set_position(ma.GetSounds()[song1], 0.0f, 0.0f, 0.0f);
28+
std::cout << "This demo was built with the latest workflow.\n";
3129
return true;
3230
}
3331

demo/demo_synthesis.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
#define OLC_PGE_APPLICATION
21
#include "olcPixelGameEngine.h"
3-
4-
#define OLC_PGEX_MINIAUDIO
52
#include "olcPGEX_MiniAudio.h"
63

74
constexpr int NOTE_COUNT = 17;

demo/demo_waveform.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#define OLC_PGE_APPLICATION
21
#include "olcPixelGameEngine.h"
3-
4-
#define OLC_PGEX_MINIAUDIO
52
#include "olcPGEX_MiniAudio.h"
63

4+
75
constexpr int NOTE_COUNT = 17;
86
constexpr float thirtyFramesPerSecond = 1.0f / 30.f;
97

demo/shell.html shell.html

File renamed without changes.

0 commit comments

Comments
 (0)