Skip to content

Commit

Permalink
[CMake] Fixed build when windowing is disabled
Browse files Browse the repository at this point in the history
- Replaced the RAZ_USE_GLFW CMake option by RAZ_USE_WINDOW

- Added a windowless CI job for each platform

- OpenAL-Soft is downloaded from the GitHub's repo
  - The website is currently down, so this may avoid similar issues later on
  - The downloaded version is now the 1.23.1 (was 1.21.0)
  - Added the --show-error curl option so that errors such as that one are shown in the future

- Added caching for OpenAL-Soft to avoid downloading it every time

- Added informative status logs at generation for optional features
  • Loading branch information
Razakhel committed Dec 30, 2023
1 parent 5583e41 commit b8354bc
Show file tree
Hide file tree
Showing 12 changed files with 162 additions and 87 deletions.
108 changes: 76 additions & 32 deletions .github/workflows/RaZ.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ jobs:
#########

linux:
name: Linux (${{ matrix.compiler.c }}, ${{ matrix.build_type }}${{ !matrix.use_audio && ', no audio' || '' }})
name: "Linux (${{ matrix.compiler.c }}, ${{ matrix.build_type }}\
${{ !matrix.use_audio && ', no audio' || '' }}\
${{ !matrix.use_window && ', no window' || '' }})"
runs-on: ubuntu-latest

strategy:
Expand All @@ -22,8 +24,11 @@ jobs:
- Release
use_audio:
- true
use_window:
- true
include:
- { compiler: { c: gcc, cpp: g++ }, build_type: Debug, use_audio: false }
- { compiler: { c: gcc, cpp: g++ }, build_type: Debug, use_audio: false, use_window: true }
- { compiler: { c: gcc, cpp: g++ }, build_type: Debug, use_audio: true, use_window: false }

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -70,7 +75,10 @@ jobs:
cmake -GNinja \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_C_COMPILER=${{ matrix.compiler.c }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cpp }} \
-DRAZ_BUILD_EXAMPLES=ON -DRAZ_GEN_DOC=ON -DRAZ_USE_AUDIO=${{ matrix.use_audio && 'ON' || 'OFF' }} \
-DRAZ_BUILD_EXAMPLES=ON -DRAZ_GEN_DOC=ON \
-DRAZ_USE_AUDIO=${{ matrix.use_audio && 'ON' || 'OFF' }} \
-DRAZ_USE_WINDOW=${{ matrix.use_window && 'ON' || 'OFF' }} \
-DRAZ_USE_IMGUI=${{ matrix.use_window && 'ON' || 'OFF' }} \
-DRAZ_USE_FBX=OFF -DRAZ_BUILD_TESTS=ON ${{ matrix.compiler.c == 'gcc' && '-DRAZ_ENABLE_COVERAGE=ON' || '' }} \
-DSKIP_RENDERER_ERRORS=ON -DENABLE_DEBUG_INFO=ON \
${{ github.workspace }} &&
Expand All @@ -83,26 +91,27 @@ jobs:
cmake --build . --config ${{ matrix.build_type }} &&
pwd && find .
# Running the tests using gdb to catch potential segfaults
# Running the tests using GDB to catch potential segfaults; only done if windowing is enabled, as many tests depend on a graphical context
- name: Test
if: matrix.use_window
shell: bash
working-directory: ${{ runner.workspace }}/build-${{ matrix.compiler.c }}
run: |
ALSOFT_DRIVERS=null xvfb-run -a --server-args='-screen 0 1280x720x16' \
gdb --batch --return-child-result -x '${{ github.workspace }}/tests/assets/debug/gdb_commands.txt' ./tests/RaZ_Tests
# Preparing code coverage; only done with GCC in Debug with audio enabled
# Preparing code coverage; only done with GCC in Debug with all features enabled
- name: Coverage setup
if: matrix.compiler.c == 'gcc' && matrix.build_type == 'Debug' && matrix.use_audio
if: matrix.compiler.c == 'gcc' && matrix.build_type == 'Debug' && matrix.use_audio && matrix.use_window
working-directory: ${{ runner.workspace }}/build-${{ matrix.compiler.c }}
run: |
lcov -d ./CMakeFiles/RaZ.dir/src/ -c -o coverage.info &&
lcov -r coverage.info '/usr/*' -o coverage.info &&
lcov -l coverage.info
# Processing code coverage; only done with GCC in Debug with audio enabled
# Processing code coverage; only done with GCC in Debug with all features enabled
- name: Coverage processing
if: matrix.compiler.c == 'gcc' && matrix.build_type == 'Debug' && matrix.use_audio
if: matrix.compiler.c == 'gcc' && matrix.build_type == 'Debug' && matrix.use_audio && matrix.use_window
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -115,7 +124,7 @@ jobs:
run: sudo cmake --install . --prefix ./ --config ${{ matrix.build_type }}

- name: Upload build
if: matrix.use_audio
if: matrix.use_audio && matrix.use_window
uses: actions/upload-artifact@v3
with:
name: linux-${{ matrix.compiler.c }}-${{ matrix.build_type }}-${{ github.run_id }}
Expand All @@ -128,8 +137,12 @@ jobs:
###########

windows:
name: Windows (${{ matrix.compiler.c }}, ${{ matrix.build_type }}${{ !matrix.use_audio && ', no audio' || '' }})
name: "Windows (${{ matrix.compiler.c }}, ${{ matrix.build_type }}\
${{ !matrix.use_audio && ', no audio' || '' }}\
${{ !matrix.use_window && ', no window' || '' }})"
runs-on: windows-2022
env:
OPENAL_VERSION: 1.23.1

strategy:
fail-fast: false
Expand All @@ -141,27 +154,47 @@ jobs:
- Release
use_audio:
- true
use_window:
- true
include:
- { compiler: { c: cl, cpp: cl }, build_type: Debug, use_audio: false }
- { compiler: { c: cl, cpp: cl }, build_type: Debug, use_audio: false, use_window: true }
- { compiler: { c: cl, cpp: cl }, build_type: Debug, use_audio: true, use_window: false }

steps:
- uses: actions/checkout@v3

# Installing OpenAL-soft to handle the audio part
- name: Build setup
# Caching OpenAL-Soft's installation; this avoids reinstalling it on every build
- name: OpenAL-Soft caching
if: matrix.use_audio
uses: actions/cache@v3
id: openal-soft
with:
path: C:/OpenAL
key: openal-soft-${{ env.OPENAL_VERSION }}
restore-keys: |
openal-soft-${{ env.OPENAL_VERSION }}
# Downloading & installing OpenAL-Soft to handle the audio part; only done when failed to find its cached installation
- name: OpenAL-Soft setup
if: matrix.use_audio && steps.openal-soft.outputs.cache-hit != 'true'
run: |
curl --silent --insecure https://www.openal-soft.org/openal-binaries/openal-soft-1.21.0-bin.zip -O &&
7z x openal-soft-1.21.0-bin.zip &&
mv openal-soft-1.21.0-bin C:/OpenAL;
cmake -E make_directory ${{ runner.workspace }}/build-${{ matrix.compiler.c }}
curl -sSkLO https://github.com/kcat/openal-soft/releases/download/${{ env.OPENAL_VERSION }}/openal-soft-${{ env.OPENAL_VERSION }}-bin.zip &&
7z x openal-soft-${{ env.OPENAL_VERSION }}-bin.zip &&
mv openal-soft-${{ env.OPENAL_VERSION }}-bin C:/OpenAL
- name: Build setup
run: cmake -E make_directory ${{ runner.workspace }}/build-${{ matrix.compiler.c }}

- name: Configuration
shell: bash
working-directory: ${{ runner.workspace }}/build-${{ matrix.compiler.c }}
run: |
cmake -G"Visual Studio 17 2022" -A x64 \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DRAZ_BUILD_EXAMPLES=ON -DRAZ_GEN_DOC=OFF -DRAZ_USE_AUDIO=${{ matrix.use_audio && 'ON' || 'OFF' }} \
-DRAZ_BUILD_EXAMPLES=ON -DRAZ_GEN_DOC=OFF \
-DRAZ_USE_AUDIO=${{ matrix.use_audio && 'ON' || 'OFF' }} \
-DRAZ_USE_WINDOW=${{ matrix.use_window && 'ON' || 'OFF' }} \
-DRAZ_USE_IMGUI=${{ matrix.use_window && 'ON' || 'OFF' }} \
-DRAZ_USE_FBX=OFF -DRAZ_BUILD_TESTS=ON \
-DSKIP_RENDERER_ERRORS=ON -DENABLE_DEBUG_INFO=ON \
$GITHUB_WORKSPACE &&
Expand All @@ -179,7 +212,7 @@ jobs:
run: cmake --install . --prefix C:/RaZ --config ${{ matrix.build_type }}

- name: Upload build
if: matrix.use_audio
if: matrix.use_audio && matrix.use_window
uses: actions/upload-artifact@v3
with:
name: windows-${{ matrix.compiler.c }}-${{ matrix.build_type }}-${{ github.run_id }}
Expand All @@ -191,7 +224,9 @@ jobs:
#########

macos:
name: macOS (${{ matrix.compiler.c }}, ${{ matrix.build_type }}${{ !matrix.use_audio && ', no audio' || '' }})
name: "macOS (${{ matrix.compiler.c }}, ${{ matrix.build_type }}\
${{ !matrix.use_audio && ', no audio' || '' }}\
${{ !matrix.use_window && ', no window' || '' }})"
runs-on: macos-latest

strategy:
Expand All @@ -204,8 +239,11 @@ jobs:
- Release
use_audio:
- true
use_window:
- true
include:
- { compiler: { c: clang, cpp: clang++ }, build_type: Debug, use_audio: false }
- { compiler: { c: clang, cpp: clang++ }, build_type: Debug, use_audio: false, use_window: true }
- { compiler: { c: clang, cpp: clang++ }, build_type: Debug, use_audio: true, use_window: false }

steps:
- uses: actions/checkout@v3
Expand All @@ -229,7 +267,10 @@ jobs:
cmake -GNinja \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_C_COMPILER=${{ matrix.compiler.c }} -DCMAKE_CXX_COMPILER=${{ matrix.compiler.cpp }} \
-DRAZ_BUILD_EXAMPLES=ON -DRAZ_GEN_DOC=OFF -DRAZ_USE_AUDIO=${{ matrix.use_audio && 'ON' || 'OFF' }} \
-DRAZ_BUILD_EXAMPLES=ON -DRAZ_GEN_DOC=OFF \
-DRAZ_USE_AUDIO=${{ matrix.use_audio && 'ON' || 'OFF' }} \
-DRAZ_USE_WINDOW=${{ matrix.use_window && 'ON' || 'OFF' }} \
-DRAZ_USE_IMGUI=${{ matrix.use_window && 'ON' || 'OFF' }} \
-DRAZ_USE_FBX=OFF -DRAZ_BUILD_TESTS=ON \
-DSKIP_RENDERER_ERRORS=ON -DENABLE_DEBUG_INFO=ON \
$GITHUB_WORKSPACE &&
Expand All @@ -248,7 +289,7 @@ jobs:
run: sudo cmake --install . --prefix ./ --config ${{ matrix.build_type }}

- name: Upload build
if: matrix.use_audio
if: matrix.use_audio && matrix.use_window
uses: actions/upload-artifact@v3
with:
name: macos-${{ matrix.compiler.c }}-${{ matrix.build_type }}-${{ github.run_id }}
Expand All @@ -261,21 +302,24 @@ jobs:
##############

emscripten:
name: Emscripten (${{ matrix.compiler.c }}, ${{ matrix.build_type }}${{ !matrix.use_audio && ', no audio' || '' }})
name: "Emscripten (${{ matrix.compiler.c }}, ${{ matrix.build_type }}\
${{ !matrix.use_audio && ', no audio' || '' }})"
runs-on: ubuntu-latest
env:
EMSCRIPTEN_VERSION: 3.1.0 # The 'latest' version may fail to build

strategy:
fail-fast: false
matrix:
compiler:
- { c: emcc, cpp: em++, version: 3.1.0 } # The 'latest' version may fail to build
- { c: emcc, cpp: em++ }
build_type:
- Debug
- Release
use_audio:
- true
include:
- { compiler: { c: emcc, cpp: em++, version: 3.1.0 }, build_type: Debug, use_audio: false }
- { compiler: { c: emcc, cpp: em++ }, build_type: Debug, use_audio: false }

steps:
- uses: actions/checkout@v3
Expand All @@ -298,25 +342,24 @@ jobs:
# chmod +x ./fbx20190_fbxsdk_linux &&
# printf 'yes\nn' | ./fbx20190_fbxsdk_linux /usr

# Caching Emscripten's installation; this avoids installing it on every build
# Caching Emscripten's installation; this avoids reinstalling it on every build
- name: Emscripten caching
uses: actions/cache@v3
id: emsdk
with:
path: ~/emsdk
key: emsdk-${{ matrix.compiler.version }}
key: emsdk-${{ env.EMSCRIPTEN_VERSION }}
restore-keys: |
emsdk-${{ matrix.compiler.version }}
emsdk-${{ env.EMSCRIPTEN_VERSION }}
# Downloading & installing Emscripten; only done when failed to find its cached installation
- name: Emscripten setup
if: steps.emsdk.outputs.cache-hit != 'true'
shell: bash
run: |
git clone --depth 1 https://github.com/emscripten-core/emsdk.git ~/emsdk &&
~/emsdk/emsdk install ${{ matrix.compiler.version }} && ~/emsdk/emsdk activate ${{ matrix.compiler.version }}
~/emsdk/emsdk install ${{ env.EMSCRIPTEN_VERSION }} && ~/emsdk/emsdk activate ${{ env.EMSCRIPTEN_VERSION }}
# Downloading & installing Emscripten, to build RaZ in WebAssembly
- name: Build setup
shell: bash
run: cmake -E make_directory ${{ runner.workspace }}/build-${{ matrix.compiler.c }}
Expand All @@ -328,7 +371,8 @@ jobs:
source ~/emsdk/emsdk_env.sh &&
emcmake cmake -GNinja \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DRAZ_BUILD_EXAMPLES=ON -DRAZ_GEN_DOC=OFF -DRAZ_USE_AUDIO=${{ matrix.use_audio && 'ON' || 'OFF' }} \
-DRAZ_BUILD_EXAMPLES=ON -DRAZ_GEN_DOC=OFF \
-DRAZ_USE_AUDIO=${{ matrix.use_audio && 'ON' || 'OFF' }} \
-DRAZ_USE_FBX=OFF -DRAZ_BUILD_TESTS=ON ${{ matrix.build_type == 'Debug' && '-DRAZ_EMSCRIPTEN_DEBUG_FAST_LINK=ON' || '' }} \
-DSKIP_RENDERER_ERRORS=ON -DENABLE_DEBUG_INFO=ON \
$GITHUB_WORKSPACE &&
Expand Down
32 changes: 22 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -404,22 +404,29 @@ if (RAZ_USE_GLEW)
target_link_libraries(RaZ PRIVATE GLEW)
endif ()

if (RAZ_USE_GLFW)
target_link_libraries(RaZ PRIVATE GLFW)
elseif (NOT RAZ_USE_EMSCRIPTEN) # Emscripten handles GLFW on its own, but still needs the Window to render into
list(
REMOVE_ITEM
RAZ_FILES
if (NOT RAZ_USE_EMSCRIPTEN) # Emscripten handles GLFW on its own, but still needs the Window to render into
if (RAZ_USE_WINDOW)
target_link_libraries(RaZ PRIVATE GLFW)
message(STATUS "[RaZ] Windowing ENABLED")
else ()
list(
REMOVE_ITEM
RAZ_FILES

"${PROJECT_SOURCE_DIR}/src/RaZ/Render/Window.cpp"
"${PROJECT_SOURCE_DIR}/include/RaZ/Render/Window.hpp"
)
"${PROJECT_SOURCE_DIR}/src/RaZ/Render/Window.cpp"
"${PROJECT_SOURCE_DIR}/src/RaZ/Script/LuaWindow.cpp"
"${PROJECT_SOURCE_DIR}/include/RaZ/Render/Window.hpp"
)

target_compile_definitions(RaZ PUBLIC RAZ_NO_WINDOW)

target_compile_definitions(RaZ PUBLIC RAZ_NO_WINDOW)
message(STATUS "[RaZ] Windowing DISABLED")
endif ()
endif ()

if (RAZ_USE_IMGUI)
target_link_libraries(RaZ PRIVATE ImGui)
message(STATUS "[RaZ] Overlay ENABLED")
else ()
list(
REMOVE_ITEM
Expand All @@ -430,6 +437,8 @@ else ()
)

target_compile_definitions(RaZ PUBLIC RAZ_NO_OVERLAY)

message(STATUS "[RaZ] Overlay DISABLED")
endif ()

if (RAZ_USE_LIBPNG)
Expand All @@ -438,6 +447,7 @@ endif ()

if (RAZ_USE_LUA)
target_link_libraries(RaZ PRIVATE Sol2 Lua)
message(STATUS "[RaZ] Lua scripting ENABLED")
else ()
file(
GLOB
Expand All @@ -449,6 +459,8 @@ else ()
list(REMOVE_ITEM RAZ_FILES ${RAZ_LUA_FILES})

target_compile_definitions(RaZ PUBLIC RAZ_NO_LUA)

message(STATUS "[RaZ] Lua scripting DISABLED")
endif ()

target_link_libraries(RaZ PRIVATE fastgltf simdjson stb)
Expand Down
Loading

0 comments on commit b8354bc

Please sign in to comment.