-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: install SDL2_sound + test installation
- Loading branch information
Showing
3 changed files
with
77 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |