Skip to content

Commit

Permalink
ci: install SDL2_sound + test installation
Browse files Browse the repository at this point in the history
  • Loading branch information
madebr authored and sezero committed Oct 14, 2022
1 parent d0a5dba commit 3dc2d1b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 5 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ jobs:
vcpkg install --triplet ${{ matrix.platform.vcpkg }} sdl2
- name: Get SDL_sound sources
uses: actions/checkout@v2
- name: Configure CMake
run: cmake -B build -DSDLSOUND_DECODER_MIDI=ON ${{ matrix.platform.flags }}
- name: Build
run: cmake --build build/
uses: actions/checkout@v3
- name: Configure (CMake)
run: cmake -B build -DSDLSOUND_DECODER_MIDI=ON ${{ matrix.platform.flags }} -DCMAKE_INSTALL_PREFIX=prefix -DCMAKE_BUILD_TYPE=Release
- name: Build (CMake)
run: cmake --build build/ --config Release
- name: Install (CMake)
run: |
cmake --install build/ --config Release
- name: Verify CMake configuration files
run: |
cmake -S cmake/test -B build_cmake_test ${{ matrix.platform.flags }} -DCMAKE_PREFIX_PATH="${{ github.workspace }}/prefix" -DCMAKE_BUILD_TYPE=Release
cmake --build build_cmake_test --verbose --config Release
47 changes: 47 additions & 0 deletions cmake/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This cmake build script is meant for verifying the various CMake configuration script.

cmake_minimum_required(VERSION 3.12)
project(sdl_test LANGUAGES C)

cmake_policy(SET CMP0074 NEW)

# Override CMAKE_FIND_ROOT_PATH_MODE to allow search for SDL2_sound outside of sysroot
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE NEVER)

include(FeatureSummary)

option(TEST_SHARED "Test linking to shared SDL2_sound library" ON)
add_feature_info("TEST_SHARED" TEST_SHARED "Test linking with shared library")

option(TEST_STATIC "Test linking to static SDL2_sound libary" ON)
add_feature_info("TEST_STATIC" TEST_STATIC "Test linking with static library")

macro(my_find_sdl2)
# FIXME: this should unconditionally use CMake config file
find_package(SDL2)
if(NOT TARGET SDL2::SDL2)
find_library(SDL2_LIBRARY NAMES SDL2)
find_path(SDL2_INCLUDE_DIRS FILES SDL.h SUFFIXES SDL2)
if(NOT SDL2_LIBRARY OR NOT SDL2_INCLUDE_DIRS)
message(FATAL_ERROR "Faild to find SDL2 (configure SDL2_LIBRARY and SDL2_INCLUDE_DIRS)")
endif()
add_library(SDL2::SDL2 SHARED IMPORTED)
set_target_properties(SDL2::SDL2 PROPERTIES IMPORTED_LOCATION "${SDL2_LIBRARY}" INTERFACE_INCLUDE_DIRECTORIES "${SDL2_INCLUDE_DIRS}")
endif()
endmacro()

if(TEST_SHARED)
find_package(SDL2_sound REQUIRED CONFIG)
my_find_sdl2()
add_executable(main_shared main.c)
target_link_libraries(main_shared PRIVATE SDL2_sound::SDL2_sound SDL2::SDL2)
endif()

if(TEST_STATIC)
find_package(SDL2_sound REQUIRED CONFIG)
my_find_sdl2()
add_executable(main_static main.c)
target_link_libraries(main_static PRIVATE SDL2_sound::SDL2_sound-static SDL2::SDL2)
endif()

feature_summary(WHAT ALL)
18 changes: 18 additions & 0 deletions cmake/test/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#define SDL_MAIN_HANDLED
#include "SDL.h"
#include "SDL_sound.h"
#include <stdio.h>

int main(int argc, char *argv[]) {
SDL_SetMainReady();
if (SDL_Init(0) < 0) {
fprintf(stderr, "SDL_Init: could not initialize SDL: %s\n", SDL_GetError());
return 1;
}
if (Sound_Init() == 0) {
fprintf(stderr, "Sound_Init: failed (%s)\n", Sound_GetError());
}
Sound_Quit();
SDL_Quit();
return 0;
}

0 comments on commit 3dc2d1b

Please sign in to comment.