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

Provide packaging routines / CMake target #135

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ jobs:

- name: Install system dependencies
run: |
sudo apt install cmake \
sudo apt-get update
sudo apt-get install cmake \
ninja-build \
xvfb \
gnome-desktop-testing \
Expand Down Expand Up @@ -276,19 +277,13 @@ jobs:
fail-fast: false
matrix:
SDL_VERSION: [ 2.24.0, 2.26.0 ]
TTF_VERSION: [ 2.0.18, 2.20.1 ]
IMG_VERSION: [ 2.0.5, 2.6.2 ]
TTF_VERSION: [ 2.20.1 ]
IMG_VERSION: [ 2.6.2 ]
MIX_VERSION: [ 2.6.3 ]
CPP_VERSION: [ 20 ]
include:
- { SDL_VERSION: 2.0.10, TTF_VERSION: 2.0.18, IMG_VERSION: 2.0.5, MIX_VERSION: 2.6.3, CPP_VERSION: 17 }
- { SDL_VERSION: 2.0.12, TTF_VERSION: 2.0.18, IMG_VERSION: 2.0.5, MIX_VERSION: 2.6.3, CPP_VERSION: 17 }
- { SDL_VERSION: 2.0.14, TTF_VERSION: 2.0.18, IMG_VERSION: 2.0.5, MIX_VERSION: 2.6.3, CPP_VERSION: 17 }
- { SDL_VERSION: 2.0.16, TTF_VERSION: 2.0.18, IMG_VERSION: 2.0.5, MIX_VERSION: 2.6.3, CPP_VERSION: 17 }
- { SDL_VERSION: 2.0.18, TTF_VERSION: 2.0.18, IMG_VERSION: 2.0.5, MIX_VERSION: 2.6.3, CPP_VERSION: 17 }
- { SDL_VERSION: 2.0.20, TTF_VERSION: 2.0.18, IMG_VERSION: 2.0.5, MIX_VERSION: 2.6.3, CPP_VERSION: 17 }
- { SDL_VERSION: 2.0.22, TTF_VERSION: 2.0.18, IMG_VERSION: 2.0.5, MIX_VERSION: 2.6.3, CPP_VERSION: 17 }
- { SDL_VERSION: 2.24.0, TTF_VERSION: 2.0.18, IMG_VERSION: 2.0.5, MIX_VERSION: 2.6.3, CPP_VERSION: 20 }
- { SDL_VERSION: 2.24.0, TTF_VERSION: 2.20.1, IMG_VERSION: 2.6.2, MIX_VERSION: 2.6.3, CPP_VERSION: 17 }
- { SDL_VERSION: 2.24.0, TTF_VERSION: 2.20.1, IMG_VERSION: 2.6.2, MIX_VERSION: 2.6.3, CPP_VERSION: 20 }
- { SDL_VERSION: 2.26.0, TTF_VERSION: 2.20.1, IMG_VERSION: 2.6.2, MIX_VERSION: 2.6.3, CPP_VERSION: 23 }
env:
VCPKG_ROOT: ${{github.workspace}}/vcpkg
Expand Down Expand Up @@ -377,4 +372,4 @@ jobs:
- name: Run mocked tests
shell: cmd
working-directory: ./build/test/mocked-tests
run: centurion-mocks
run: centurion-mocks
96 changes: 89 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.15)
cmake_minimum_required(VERSION 3.23)

if (DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
file(TO_CMAKE_PATH $ENV{VCPKG_ROOT} VCPKG_ROOT)
set(CMAKE_TOOLCHAIN_FILE "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
endif ()

project(centurion
Expand Down Expand Up @@ -38,10 +39,52 @@ set(CENTURION_TEST_TARGET centurion-tests)
set(CENTURION_MOCK_TARGET centurion-mocks)

# System dependencies
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_mixer REQUIRED)
find_package(SDL2_ttf REQUIRED)
cen_find_env_package(SDL2 SDL2DIR)
cen_find_env_package(SDL2_image SDL2IMAGEDIR)
cen_find_env_package(SDL2_mixer SDL2MIXERDIR)
cen_find_env_package(SDL2_ttf SDL2TTFDIR)

# CMake Targets
add_library(centurion-headers-only INTERFACE)
add_library(centurion::centurion-headers-only ALIAS centurion-headers-only)
set(CEN_TARGETS centurion-headers-only)
add_subdirectory("${CEN_SOURCE_DIR}")

cen_has_SDL(SDL_SHARED SDL_STATIC)

if (SDL_SHARED OR SDL_STATIC)
add_library(centurion INTERFACE)
add_library(centurion::centurion ALIAS centurion)
list(APPEND CEN_TARGETS centurion)
target_link_libraries(centurion INTERFACE
centurion-headers-only
$<$<TARGET_EXISTS:SDL2::SDL2main>:SDL2::SDL2main>
$<IF:$<TARGET_EXISTS:SDL2::SDL2>,SDL2::SDL2,SDL2::SDL2-static>
$<IF:$<TARGET_EXISTS:SDL2_image::SDL2_image>,SDL2_image::SDL2_image,SDL2_image::SDL2_image-static>
$<IF:$<TARGET_EXISTS:SDL2_mixer::SDL2_mixer>,SDL2_mixer::SDL2_mixer,SDL2_mixer::SDL2_mixer-static>
$<IF:$<TARGET_EXISTS:SDL2_ttf::SDL2_ttf>,SDL2_ttf::SDL2_ttf,SDL2_ttf::SDL2_ttf-static>
)
endif ()

if (SDL_STATIC)
add_library(centurion-static INTERFACE)
add_library(centurion::centurion-static ALIAS centurion-static)
list(APPEND CEN_TARGETS centurion-static)
target_link_libraries(centurion-static INTERFACE
centurion-headers-only
$<$<TARGET_EXISTS:SDL2::SDL2main>:SDL2::SDL2main>
SDL2::SDL2-static
SDL2_image::SDL2_image-static
SDL2_mixer::SDL2_mixer-static
SDL2_ttf::SDL2_ttf-static
)
endif ()

if (BUILD_TESTS OR BUILD_EXAMPLES)
if (NOT TARGET centurion::centurion)
message(FATAL_ERROR "Unable to find required SDL libraries")
endif()
endif ()

if (BUILD_TESTS)
# Vcpkg test dependencies
Expand All @@ -54,4 +97,43 @@ endif ()

if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()
endif ()

# Installer
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

configure_file(
"${CMAKE_MODULE_PATH}/centurion.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/centurion.pc"
@ONLY
)

install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/centurion.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/centurion-config-version.cmake"
COMPATIBILITY AnyNewerVersion
ARCH_INDEPENDENT
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/centurion-config-version.cmake"
"${CMAKE_MODULE_PATH}/centurion-config.cmake"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/centurion"
)

install(
TARGETS ${CEN_TARGETS}
EXPORT centurionTargets
FILE_SET HEADERS
)

install(
EXPORT centurionTargets
NAMESPACE centurion::
DESTINATION "${CMAKE_INSTALL_DATADIR}/centurion"
)
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main(int argc, char* argv[])

cen::window window {"Centurion"};
cen::renderer renderer = window.make_renderer();

window.show();

bool running = true;
Expand Down Expand Up @@ -91,10 +91,13 @@ mandatory. The extension libraries can be disabled at compile-time, by defining

## Installation

The library is distributed as a header-only library, which can be found in the `src` directory. Just download the
**Header Only**: The library is distributed as a header-only library, which can be found in the `src` directory. Just download the
headers include them in your project, and the library it's ready to be used. You will of course also need to install
SDL2.

**CMake Subproject**: The library can be included as a subproject in your project. After integrating the code you can use
`add_subdirectory(path/to/centurion)` and then `target_link_libraries(program PRIVATE centurion::centurion)`

## Documentation

For additional documentation, see the [wiki](https://github.com/albin-johansson/centurion/wiki), hosted on GitHub.
173 changes: 0 additions & 173 deletions cmake/FindSDL2.cmake

This file was deleted.

Loading