Skip to content

Commit

Permalink
Build: Add SDL as link dependency for centurion
Browse files Browse the repository at this point in the history
Default is shared linkage, also provide -static and -headers-only (bring
your own SDL) targets.

Also ditch the FindModules hanging out in the CMake folder. SDL ships
with appropriate config mode module discovery and CMake ships with
FindModules for SDL components.
  • Loading branch information
nickelpro committed Jun 21, 2023
1 parent 7f1d3f5 commit 9d1945f
Show file tree
Hide file tree
Showing 23 changed files with 56 additions and 525 deletions.
40 changes: 33 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,37 @@ 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)
find_package(SDL2 CONFIG REQUIRED)
find_package(SDL2_image CONFIG REQUIRED)
find_package(SDL2_mixer CONFIG REQUIRED)
find_package(SDL2_ttf CONFIG REQUIRED)

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

# CMake Target
add_library(centurion INTERFACE)
add_subdirectory("${CEN_SOURCE_DIR}")
add_library(centurion::centurion ALIAS centurion)
target_link_libraries(centurion INTERFACE
centurion-headers-only
SDL2::SDL2
SDL2_image::SDL2_image
SDL2_mixer::SDL2_mixer
SDL2_ttf::SDL2_ttf
)

if (TARGET SDL2::SDL2-static)
add_library(centurion-static INTERFACE)
add_library(centurion::centurion-static ALIAS centurion-static)
target_link_libraries(centurion-static INTERFACE
centurion-headers-only
SDL2::SDL2-static
SDL2_image::SDL2_image-static
SDL2_mixer::SDL2_mixer-static
SDL2_ttf::SDL2_ttf-static
)
endif ()

if (BUILD_TESTS)
# Vcpkg test dependencies
Expand Down Expand Up @@ -89,11 +111,15 @@ install(FILES
)

install(
TARGETS centurion
TARGETS centurion-headers-only centurion
EXPORT centurionTargets
FILE_SET HEADERS
)

if(TARGET centurion-static)
install(TARGETS centurion-static EXPORT centurionTargets)
endif()

install(
EXPORT centurionTargets
NAMESPACE centurion::
Expand Down
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.

102 changes: 0 additions & 102 deletions cmake/FindSDL2_image.cmake

This file was deleted.

Loading

0 comments on commit 9d1945f

Please sign in to comment.