Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to CMake and Test new build and deployment workflows #15

Merged
merged 11 commits into from
Sep 20, 2024
10 changes: 4 additions & 6 deletions .github/workflows/emscripten-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ jobs:

steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: 'recursive'

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

Expand All @@ -36,8 +36,6 @@ jobs:
- name: Build with Emscripten
run: |
source emsdk/emsdk_env.sh
cd demo
make emscripten
emcmake cmake . -B emscripten-build
cmake --build emscripten-build --config=Release
shell: bash


14 changes: 7 additions & 7 deletions .github/workflows/emscripten-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ jobs:

steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
submodules: 'recursive'

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

Expand All @@ -32,8 +32,8 @@ jobs:
- name: Build with Emscripten
run: |
source emsdk/emsdk_env.sh
cd demo
make emscripten
emcmake cmake . -B emscripten-build
cmake --build emscripten-build --config=Release
shell: bash

- name: Deploy Main Demo
Expand All @@ -43,7 +43,7 @@ jobs:
username: ${{ secrets.REMOTE_SERVER_USER }}
key: ${{ secrets.REMOTE_SERVER_SSH_KEY }}
port: ${{ secrets.REMOTE_SERVER_PORT }}
source: "demo/demo.html,demo/demo.js,demo/demo.wasm,demo/demo.data"
source: "emscripten-build/demo.html,emscripten-build/demo.js,emscripten-builddemo.wasm,emscripten-build/demo.data"
target: ${{ secrets.REMOTE_SERVER_DIRECTORY }}
strip_components: 1

Expand All @@ -54,7 +54,7 @@ jobs:
username: ${{ secrets.REMOTE_SERVER_USER }}
key: ${{ secrets.REMOTE_SERVER_SSH_KEY }}
port: ${{ secrets.REMOTE_SERVER_PORT }}
source: "demo/demo_waveform.html,demo/demo_waveform.js,demo/demo_waveform.wasm,demo/demo_waveform.data"
source: "emscripten-build/demo_waveform.html,emscripten-build/demo_waveform.js,emscripten-build/demo_waveform.wasm,emscripten-build/demo_waveform.data"
target: ${{ secrets.REMOTE_SERVER_DIRECTORY }}
strip_components: 1

Expand All @@ -65,6 +65,6 @@ jobs:
username: ${{ secrets.REMOTE_SERVER_USER }}
key: ${{ secrets.REMOTE_SERVER_SSH_KEY }}
port: ${{ secrets.REMOTE_SERVER_PORT }}
source: "demo/demo_synthesis.html,demo/demo_synthesis.js,demo/demo_synthesis.wasm,demo/demo_synthesis.data"
source: "emscripten-build/demo_synthesis.html,emscripten-build/demo_synthesis.js,emscripten-build/demo_synthesis.wasm,emscripten-build/demo_synthesis.data"
target: ${{ secrets.REMOTE_SERVER_DIRECTORY }}
strip_components: 1
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.vscode
demo/demo*
!demo/demo.cpp

build
emscripten-build
262 changes: 262 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
# require version 3.10 or higher
cmake_minimum_required(VERSION 3.10)

project(olcPGEX_MiniAudio)

option(UPDATE_GIT_SUBMODULES "Update Git submodules" ON)

if (UPDATE_GIT_SUBMODULES)
message(STATUS "Updating Git submodules...")
execute_process(
COMMAND git submodule update --init --recursive
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE result
)

if(NOT result EQUAL 0)
message(FATAL_ERROR "Failed to update Git submodules")
endif()
endif()

# Set C++ Standards
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

function(add_common_settings target)

######################################################################
# MacOS
######################################################################
if(APPLE)

# OpenGL
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)

# Carbon
FIND_LIBRARY(CARBON_LIBRARY Carbon)
target_link_libraries(${target} ${CARBON_LIBRARY})

# GLUT
find_package(GLUT REQUIRED)
target_link_libraries(${target} ${GLUT_LIBRARIES})

# Threads
find_package(Threads REQUIRED)
target_link_libraries(${target} Threads::Threads)
include_directories(${Threads_INCLUDE_DIRS})

find_package(PNG REQUIRED)
target_link_libraries(${target} PNG::PNG)
include_directories(${PNG_INCLUDE_DIRS})

# debug mode!
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>)
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>)

endif() # APPLE


######################################################################
# Windows: MinGW
######################################################################
if(WIN32 AND MINGW)

# OpenGL
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)

if (NOT HAS_TERMINAL)
target_link_libraries(${target} -mwindows -municode)
endif (NOT HAS_TERMINAL)

# GDI+
set(GDIPLUS_LIBRARY gdiplus)
target_link_libraries(${target} ${GDIPLUS_LIBRARY})

# Shlwapi
set(SHLWAPI_LIBRARY shlwapi)
target_link_libraries(${target} ${SHLWAPI_LIBRARY})

# Dwmapi
set(DWMAPI_LIBRARY dwmapi)
target_link_libraries(${target} ${DWMAPI_LIBRARY})

# stdc++fs
target_link_libraries(${target} stdc++fs)

# debug mode!
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>)
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>)

endif()

######################################################################
# Windows: Visual Studio / MSVC
######################################################################
if(WIN32 AND MSVC)

# OpenGL
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)

# set the startup project to the target executable instead of ALL_BUILD
set_property(
DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}
PROPERTY
VS_STARTUP_PROJECT
${target}
)

# set working directory for Visual Studio Debugger
set_target_properties(
${target} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)

# set subsytem, console if HAS_TERMINAL is true. windows if not
if (HAS_TERMINAL)
target_link_options(${target} PRIVATE "/SUBSYSTEM:CONSOLE")
else ()
target_link_options(${target} PRIVATE "/SUBSYSTEM:WINDOWS")
endif ()

# GDI+
set(GDIPLUS_LIBRARY gdiplus)
target_link_libraries(${target} ${GDIPLUS_LIBRARY})

# Shlwapi
set(SHLWAPI_LIBRARY shlwapi)
target_link_libraries(${target} ${SHLWAPI_LIBRARY})

# Dwmapi
set(DWMAPI_LIBRARY dwmapi)
target_link_libraries(${target} ${DWMAPI_LIBRARY})

# debug mode!
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>)
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>)

endif() # Visual Studio / MSVC

######################################################################
# Linux: using anything?
######################################################################
if(UNIX AND NOT APPLE AND NOT EMSCRIPTEN)

# OpenGL
set(OpenGL_GL_PREFERENCE LEGACY)
find_package(OpenGL REQUIRED)
include_directories(${OpenGL_INCLUDE_DIRS})
target_link_libraries(${target} ${OpenGL_LIBRARIES} OpenGL::GL)

# X11
find_package(X11 REQUIRED)
target_link_libraries(${target} X11::X11)

include_directories(${X11_INCLUDE_DIRS})

# Threads
find_package(Threads REQUIRED)
target_link_libraries(${target} Threads::Threads)
include_directories(${Threads_INCLUDE_DIRS})

find_package(PNG REQUIRED)
target_link_libraries(${target} PNG::PNG)
include_directories(${PNG_INCLUDE_DIRS})

# stdc++fs
target_link_libraries(${target} stdc++fs)

# dl, for miniaudio
target_link_libraries(${target} dl)

# debug mode!
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>)
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>)

endif() # Linux

######################################################################
# Emscripten
######################################################################
if (EMSCRIPTEN)

# build Cache: libpng, zlib
execute_process(COMMAND "${EMSCRIPTEN_ROOT_PATH}/embuilder${EMCC_SUFFIX}" build libpng zlib)

# debug mode!
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DMA_DEBUG_OUTPUT>)
target_compile_definitions(${target} PRIVATE $<$<CONFIG:Debug>:-DDEBUG=1>)

target_link_options(${target} PRIVATE -sALLOW_MEMORY_GROWTH=1)
target_link_options(${target} PRIVATE -sSTACK_SIZE=131072)
target_link_options(${target} PRIVATE -sMAX_WEBGL_VERSION=2)
target_link_options(${target} PRIVATE -sMIN_WEBGL_VERSION=2)
target_link_options(${target} PRIVATE -sUSE_LIBPNG=1)
target_link_options(${target} PRIVATE -sLLD_REPORT_UNDEFINED)
target_link_options(${target} PRIVATE --shell-file "${CMAKE_CURRENT_SOURCE_DIR}/shell.html")
target_link_options(${target} PRIVATE --preload-file ${CMAKE_SOURCE_DIR}/demo/assets@assets)

endif() # Emscripten

include_directories(${CMAKE_SOURCE_DIR})
include_directories(third_party/miniaudio)
include_directories(third_party/olcPixelGameEngine)


if (NOT EMSCRIPTEN)
add_custom_command(
TARGET ${target}
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy_directory ${CMAKE_SOURCE_DIR}/demo/assets ${CMAKE_BINARY_DIR}/assets
)
endif()

endfunction()

# Executable aka binary output
add_executable(
demo
demo/demo.cpp
demo/common.cpp
olcPGEX_MiniAudio.h
third_party/olcPixelGameEngine/olcPixelGameEngine.h
third_party/miniaudio/miniaudio.h
)

add_executable(
demo_synthesis
demo/demo_synthesis.cpp
demo/common.cpp
olcPGEX_MiniAudio.h
third_party/olcPixelGameEngine/olcPixelGameEngine.h
third_party/miniaudio/miniaudio.h
)

add_executable(
demo_waveform
demo/demo_waveform.cpp
demo/common.cpp
olcPGEX_MiniAudio.h
third_party/olcPixelGameEngine/olcPixelGameEngine.h
third_party/miniaudio/miniaudio.h
)

if (EMSCRIPTEN)
# generate an HTML file
set(CMAKE_EXECUTABLE_SUFFIX .html)
endif()

add_common_settings(demo)
add_common_settings(demo_synthesis)
add_common_settings(demo_waveform)
Binary file added demo/assets/pack.pak
Binary file not shown.
5 changes: 5 additions & 0 deletions demo/common.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"

#define OLC_PGEX_MINIAUDIO
#include "olcPGEX_MiniAudio.h"
4 changes: 1 addition & 3 deletions demo/demo.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"

#define OLC_PGEX_MINIAUDIO
#include "olcPGEX_MiniAudio.h"

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

Expand Down
3 changes: 0 additions & 3 deletions demo/demo_synthesis.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"

#define OLC_PGEX_MINIAUDIO
#include "olcPGEX_MiniAudio.h"

constexpr int NOTE_COUNT = 17;
Expand Down
4 changes: 1 addition & 3 deletions demo/demo_waveform.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#define OLC_PGE_APPLICATION
#include "olcPixelGameEngine.h"

#define OLC_PGEX_MINIAUDIO
#include "olcPGEX_MiniAudio.h"


constexpr int NOTE_COUNT = 17;
constexpr float thirtyFramesPerSecond = 1.0f / 30.f;

Expand Down
File renamed without changes.