diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 79b936647..00d491e61 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 \ @@ -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 @@ -377,4 +372,4 @@ jobs: - name: Run mocked tests shell: cmd working-directory: ./build/test/mocked-tests - run: centurion-mocks \ No newline at end of file + run: centurion-mocks diff --git a/CMakeLists.txt b/CMakeLists.txt index b9a70c5eb..1da486cbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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 + $<$:SDL2::SDL2main> + $,SDL2::SDL2,SDL2::SDL2-static> + $,SDL2_image::SDL2_image,SDL2_image::SDL2_image-static> + $,SDL2_mixer::SDL2_mixer,SDL2_mixer::SDL2_mixer-static> + $,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 + $<$: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 @@ -54,4 +97,43 @@ endif () if (BUILD_EXAMPLES) add_subdirectory(examples) -endif () \ No newline at end of file +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" +) diff --git a/README.md b/README.md index d8f26a5ec..01ec88017 100644 --- a/README.md +++ b/README.md @@ -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; @@ -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. diff --git a/cmake/FindSDL2.cmake b/cmake/FindSDL2.cmake deleted file mode 100644 index 1cdfdaa80..000000000 --- a/cmake/FindSDL2.cmake +++ /dev/null @@ -1,173 +0,0 @@ - -# This module defines -# SDL2_LIBRARY, the name of the library to link against -# SDL2_FOUND, if false, do not try to link to SDL2 -# SDL2_INCLUDE_DIR, where to find SDL.h -# -# This module responds to the the flag: -# SDL2_BUILDING_LIBRARY -# If this is defined, then no SDL2main will be linked in because -# only applications need main(). -# Otherwise, it is assumed you are building an application and this -# module will attempt to locate and set the the proper link flags -# as part of the returned SDL2_LIBRARY variable. -# -# Don't forget to include SDLmain.h and SDLmain.m your project for the -# OS X framework based version. (Other versions link to -lSDL2main which -# this module will try to find on your behalf.) Also for OS X, this -# module will automatically add the -framework Cocoa on your behalf. -# -# -# Additional Note: If you see an empty SDL2_LIBRARY_TEMP in your configuration -# and no SDL2_LIBRARY, it means CMake did not find your SDL2 library -# (SDL2.dll, libsdl2.so, SDL2.framework, etc). -# Set SDL2_LIBRARY_TEMP to point to your SDL2 library, and configure again. -# Similarly, if you see an empty SDL2MAIN_LIBRARY, you should set this value -# as appropriate. These values are used to generate the final SDL2_LIBRARY -# variable, but when these values are unset, SDL2_LIBRARY does not get created. -# -# -# $SDL2DIR is an environment variable that would -# correspond to the ./configure --prefix=$SDL2DIR -# used in building SDL2. -# l.e.galup 9-20-02 -# -# Modified by Eric Wing. -# Added code to assist with automated building by using environmental variables -# and providing a more controlled/consistent search behavior. -# Added new modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). -# Also corrected the header search path to follow "proper" SDL guidelines. -# Added a search for SDL2main which is needed by some platforms. -# Added a search for threads which is needed by some platforms. -# Added needed compile switches for MinGW. -# -# On OSX, this will prefer the Framework version (if found) over others. -# People will have to manually change the cache values of -# SDL2_LIBRARY to override this selection or set the CMake environment -# CMAKE_INCLUDE_PATH to modify the search paths. -# -# Note that the header path has changed from SDL2/SDL.h to just SDL.h -# This needed to change because "proper" SDL convention -# is #include "SDL.h", not . This is done for portability -# reasons because not all systems place things in SDL2/ (see FreeBSD). - -#============================================================================= -# Copyright 2003-2009 Kitware, Inc. -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -# message("") - -SET(SDL2_SEARCH_PATHS - ~/Library/Frameworks - /Library/Frameworks - /usr/local - /usr - /sw # Fink - /opt/local # DarwinPorts - /opt/csw # Blastwave - /opt - ${SDL2_PATH} - ) - -FIND_PATH(SDL2_INCLUDE_DIR SDL.h - HINTS - $ENV{SDL2DIR} - PATH_SUFFIXES include/SDL2 include - PATHS ${SDL2_SEARCH_PATHS} - ) - -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(PATH_SUFFIXES lib64 lib/x64 lib) -else() - set(PATH_SUFFIXES lib/x86 lib) -endif() - -FIND_LIBRARY(SDL2_LIBRARY_TEMP - NAMES SDL2 - HINTS - $ENV{SDL2DIR} - PATH_SUFFIXES ${PATH_SUFFIXES} - PATHS ${SDL2_SEARCH_PATHS} - ) - -IF(NOT SDL2_BUILDING_LIBRARY) - IF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") - # Non-OS X framework versions expect you to also dynamically link to - # SDL2main. This is mainly for Windows and OS X. Other (Unix) platforms - # seem to provide SDL2main for compatibility even though they don't - # necessarily need it. - FIND_LIBRARY(SDL2MAIN_LIBRARY - NAMES SDL2main - HINTS - $ENV{SDL2DIR} - PATH_SUFFIXES ${PATH_SUFFIXES} - PATHS ${SDL2_SEARCH_PATHS} - ) - ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework") -ENDIF(NOT SDL2_BUILDING_LIBRARY) - -# SDL2 may require threads on your system. -# The Apple build may not need an explicit flag because one of the -# frameworks may already provide it. -# But for non-OSX systems, I will use the CMake Threads package. -IF(NOT APPLE) - FIND_PACKAGE(Threads) -ENDIF(NOT APPLE) - -# MinGW needs an additional link flag, -mwindows -# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows -IF(MINGW) - SET(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "mwindows for MinGW") -ENDIF(MINGW) - -IF(SDL2_LIBRARY_TEMP) - # For SDL2main - IF(NOT SDL2_BUILDING_LIBRARY) - IF(SDL2MAIN_LIBRARY) - SET(SDL2_LIBRARY_TEMP ${SDL2MAIN_LIBRARY} ${SDL2_LIBRARY_TEMP}) - ENDIF(SDL2MAIN_LIBRARY) - ENDIF(NOT SDL2_BUILDING_LIBRARY) - - # For OS X, SDL2 uses Cocoa as a backend so it must link to Cocoa. - # CMake doesn't display the -framework Cocoa string in the UI even - # though it actually is there if I modify a pre-used variable. - # I think it has something to do with the CACHE STRING. - # So I use a temporary variable until the end so I can set the - # "real" variable in one-shot. - IF(APPLE) - SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} "-framework Cocoa") - ENDIF(APPLE) - - # For threads, as mentioned Apple doesn't need this. - # In fact, there seems to be a problem if I used the Threads package - # and try using this line, so I'm just skipping it entirely for OS X. - IF(NOT APPLE) - SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${CMAKE_THREAD_LIBS_INIT}) - ENDIF(NOT APPLE) - - # For MinGW library - IF(MINGW) - SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP}) - ENDIF(MINGW) - - # Set the final string here so the GUI reflects the final state. - SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found") - # Set the temp variable to INTERNAL so it is not seen in the CMake GUI - SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "") -ENDIF(SDL2_LIBRARY_TEMP) - -# message("") - -INCLUDE(FindPackageHandleStandardArgs) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR) diff --git a/cmake/FindSDL2_image.cmake b/cmake/FindSDL2_image.cmake deleted file mode 100644 index 591c1e6b0..000000000 --- a/cmake/FindSDL2_image.cmake +++ /dev/null @@ -1,102 +0,0 @@ -# Locate SDL_image library -# -# This module defines: -# -# :: -# -# SDL2_IMAGE_LIBRARIES, the name of the library to link against -# SDL2_IMAGE_INCLUDE_DIRS, where to find the headers -# SDL2_IMAGE_FOUND, if false, do not try to link against -# SDL2_IMAGE_VERSION_STRING - human-readable string containing the version of SDL_image -# -# -# -# For backward compatibility the following variables are also set: -# -# :: -# -# SDLIMAGE_LIBRARY (same value as SDL2_IMAGE_LIBRARIES) -# SDLIMAGE_INCLUDE_DIR (same value as SDL2_IMAGE_INCLUDE_DIRS) -# SDLIMAGE_FOUND (same value as SDL2_IMAGE_FOUND) -# -# -# -# $SDLDIR is an environment variable that would correspond to the -# ./configure --prefix=$SDLDIR used in building SDL. -# -# Created by Eric Wing. This was influenced by the FindSDL.cmake -# module, but with modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# Copyright 2012 Benjamin Eikel -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -find_path(SDL2_IMAGE_INCLUDE_DIR SDL_image.h - HINTS - C:/ - ENV SDL2IMAGEDIR - ENV SDL2DIR - PATH_SUFFIXES SDL2 - # path suffixes to search inside ENV{SDLDIR} - include/SDL2 include - PATHS ${SDL2_IMAGE_PATH} - ) - -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(VC_LIB_PATH_SUFFIX lib/x64) -else() - set(VC_LIB_PATH_SUFFIX lib/x86) -endif() - -find_library(SDL2_IMAGE_LIBRARY - NAMES SDL2_image - HINTS - C:/SDL_image - ENV SDL2IMAGEDIR - ENV SDL2DIR - PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} - PATHS ${SDL2_IMAGE_PATH} - ) - -if(SDL2_IMAGE_INCLUDE_DIR AND EXISTS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h") - file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_IMAGE_INCLUDE_DIR}/SDL_image.h" SDL2_IMAGE_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+[0-9]+$") - string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MAJOR "${SDL2_IMAGE_VERSION_MAJOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_MINOR "${SDL2_IMAGE_VERSION_MINOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_IMAGE_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_IMAGE_VERSION_PATCH "${SDL2_IMAGE_VERSION_PATCH_LINE}") - set(SDL2_IMAGE_VERSION_STRING ${SDL2_IMAGE_VERSION_MAJOR}.${SDL2_IMAGE_VERSION_MINOR}.${SDL2_IMAGE_VERSION_PATCH}) - unset(SDL2_IMAGE_VERSION_MAJOR_LINE) - unset(SDL2_IMAGE_VERSION_MINOR_LINE) - unset(SDL2_IMAGE_VERSION_PATCH_LINE) - unset(SDL2_IMAGE_VERSION_MAJOR) - unset(SDL2_IMAGE_VERSION_MINOR) - unset(SDL2_IMAGE_VERSION_PATCH) -endif() - -set(SDL2_IMAGE_LIBRARIES ${SDL2_IMAGE_LIBRARY}) -set(SDL2_IMAGE_INCLUDE_DIRS ${SDL2_IMAGE_INCLUDE_DIR}) - -include(FindPackageHandleStandardArgs) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_image - REQUIRED_VARS SDL2_IMAGE_LIBRARIES SDL2_IMAGE_INCLUDE_DIRS - VERSION_VAR SDL2_IMAGE_VERSION_STRING) - -# for backward compatibility -set(SDLIMAGE_LIBRARY ${SDL2_IMAGE_LIBRARIES}) -set(SDLIMAGE_INCLUDE_DIR ${SDL2_IMAGE_INCLUDE_DIRS}) -set(SDLIMAGE_FOUND ${SDL2_IMAGE_FOUND}) - -mark_as_advanced(SDL2_IMAGE_LIBRARY SDL2_IMAGE_INCLUDE_DIR) diff --git a/cmake/FindSDL2_mixer.cmake b/cmake/FindSDL2_mixer.cmake deleted file mode 100644 index f3fc4f9b7..000000000 --- a/cmake/FindSDL2_mixer.cmake +++ /dev/null @@ -1,101 +0,0 @@ -# Locate SDL_MIXER library -# -# This module defines: -# -# :: -# -# SDL2_MIXER_LIBRARIES, the name of the library to link against -# SDL2_MIXER_INCLUDE_DIRS, where to find the headers -# SDL2_MIXER_FOUND, if false, do not try to link against -# SDL2_MIXER_VERSION_STRING - human-readable string containing the version of SDL_MIXER -# -# -# -# For backward compatibility the following variables are also set: -# -# :: -# -# SDLMIXER_LIBRARY (same value as SDL2_MIXER_LIBRARIES) -# SDLMIXER_INCLUDE_DIR (same value as SDL2_MIXER_INCLUDE_DIRS) -# SDLMIXER_FOUND (same value as SDL2_MIXER_FOUND) -# -# -# -# $SDLDIR is an environment variable that would correspond to the -# ./configure --prefix=$SDLDIR used in building SDL. -# -# Created by Eric Wing. This was influenced by the FindSDL.cmake -# module, but with modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# Copyright 2012 Benjamin Eikel -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -find_path(SDL2_MIXER_INCLUDE_DIR SDL_mixer.h - HINTS - ENV SDL2MIXERDIR - ENV SDL2DIR - PATH_SUFFIXES SDL2 - # path suffixes to search inside ENV{SDLDIR} - include/SDL2 include - PATHS ${SDL2_MIXER_PATH} - ) - -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(VC_LIB_PATH_SUFFIX lib/x64) -else() - set(VC_LIB_PATH_SUFFIX lib/x86) -endif() - -find_library(SDL2_MIXER_LIBRARY - NAMES SDL2_mixer - HINTS - C:/SDL_mixer - ENV SDL2MIXERDIR - ENV SDL2DIR - PATH_SUFFIXES lib bin ${VC_LIB_PATH_SUFFIX} - PATHS ${SDL2_MIXER_PATH} - ) - -if(SDL2_MIXER_INCLUDE_DIR AND EXISTS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h") - file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_MIXER_INCLUDE_DIR}/SDL_mixer.h" SDL2_MIXER_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+[0-9]+$") - string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MAJOR "${SDL2_MIXER_VERSION_MAJOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_MINOR "${SDL2_MIXER_VERSION_MINOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_MIXER_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_MIXER_VERSION_PATCH "${SDL2_MIXER_VERSION_PATCH_LINE}") - set(SDL2_MIXER_VERSION_STRING ${SDL2_MIXER_VERSION_MAJOR}.${SDL2_MIXER_VERSION_MINOR}.${SDL2_MIXER_VERSION_PATCH}) - unset(SDL2_MIXER_VERSION_MAJOR_LINE) - unset(SDL2_MIXER_VERSION_MINOR_LINE) - unset(SDL2_MIXER_VERSION_PATCH_LINE) - unset(SDL2_MIXER_VERSION_MAJOR) - unset(SDL2_MIXER_VERSION_MINOR) - unset(SDL2_MIXER_VERSION_PATCH) -endif() - -set(SDL2_MIXER_LIBRARIES ${SDL2_MIXER_LIBRARY}) -set(SDL2_MIXER_INCLUDE_DIRS ${SDL2_MIXER_INCLUDE_DIR}) - -include(FindPackageHandleStandardArgs) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_mixer - REQUIRED_VARS SDL2_MIXER_LIBRARIES SDL2_MIXER_INCLUDE_DIRS - VERSION_VAR SDL2_MIXER_VERSION_STRING) - -# for backward compatibility -set(SDLMIXER_LIBRARY ${SDL2_MIXER_LIBRARIES}) -set(SDLMIXER_INCLUDE_DIR ${SDL2_MIXER_INCLUDE_DIRS}) -set(SDLMIXER_FOUND ${SDL2_MIXER_FOUND}) - -mark_as_advanced(SDL2_MIXER_LIBRARY SDL2_MIXER_INCLUDE_DIR) diff --git a/cmake/FindSDL2_ttf.cmake b/cmake/FindSDL2_ttf.cmake deleted file mode 100644 index 4b0774dd7..000000000 --- a/cmake/FindSDL2_ttf.cmake +++ /dev/null @@ -1,99 +0,0 @@ -# Locate SDL_ttf library -# -# This module defines: -# -# :: -# -# SDL2_TTF_LIBRARIES, the name of the library to link against -# SDL2_TTF_INCLUDE_DIRS, where to find the headers -# SDL2_TTF_FOUND, if false, do not try to link against -# SDL2_TTF_VERSION_STRING - human-readable string containing the version of SDL_ttf -# -# -# -# For backward compatibility the following variables are also set: -# -# :: -# -# SDLTTF_LIBRARY (same value as SDL2_TTF_LIBRARIES) -# SDLTTF_INCLUDE_DIR (same value as SDL2_TTF_INCLUDE_DIRS) -# SDLTTF_FOUND (same value as SDL2_TTF_FOUND) -# -# -# -# $SDLDIR is an environment variable that would correspond to the -# ./configure --prefix=$SDLDIR used in building SDL. -# -# Created by Eric Wing. This was influenced by the FindSDL.cmake -# module, but with modifications to recognize OS X frameworks and -# additional Unix paths (FreeBSD, etc). - -#============================================================================= -# Copyright 2005-2009 Kitware, Inc. -# Copyright 2012 Benjamin Eikel -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -find_path(SDL2_TTF_INCLUDE_DIR SDL_ttf.h - HINTS - C:/SDL_ttf - ENV SDL2TTFDIR - ENV SDL2DIR - PATH_SUFFIXES SDL2 - # path suffixes to search inside ENV{SDLDIR} - include/SDL2 include - PATHS ${SDL2_TTF_PATH} - ) - -if (CMAKE_SIZEOF_VOID_P EQUAL 8) - set(VC_LIB_PATH_SUFFIX lib/x64) -else () - set(VC_LIB_PATH_SUFFIX lib/x86) -endif () - -find_library(SDL2_TTF_LIBRARY - NAMES SDL2_ttf - HINTS - ENV SDL2TTFDIR - ENV SDL2DIR - PATH_SUFFIXES lib ${VC_LIB_PATH_SUFFIX} - PATHS ${SDL2_TTF_PATH} - ) - -if (SDL2_TTF_INCLUDE_DIR AND EXISTS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h") - file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+[0-9]+$") - file(STRINGS "${SDL2_TTF_INCLUDE_DIR}/SDL_ttf.h" SDL2_TTF_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+[0-9]+$") - string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MAJOR "${SDL2_TTF_VERSION_MAJOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_TTF_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_MINOR "${SDL2_TTF_VERSION_MINOR_LINE}") - string(REGEX REPLACE "^#define[ \t]+SDL_TTF_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_TTF_VERSION_PATCH "${SDL2_TTF_VERSION_PATCH_LINE}") - set(SDL2_TTF_VERSION_STRING ${SDL2_TTF_VERSION_MAJOR}.${SDL2_TTF_VERSION_MINOR}.${SDL2_TTF_VERSION_PATCH}) - unset(SDL2_TTF_VERSION_MAJOR_LINE) - unset(SDL2_TTF_VERSION_MINOR_LINE) - unset(SDL2_TTF_VERSION_PATCH_LINE) - unset(SDL2_TTF_VERSION_MAJOR) - unset(SDL2_TTF_VERSION_MINOR) - unset(SDL2_TTF_VERSION_PATCH) -endif () - -set(SDL2_TTF_LIBRARIES ${SDL2_TTF_LIBRARY}) -set(SDL2_TTF_INCLUDE_DIRS ${SDL2_TTF_INCLUDE_DIR}) - -include(FindPackageHandleStandardArgs) - -FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2_ttf - REQUIRED_VARS SDL2_TTF_LIBRARIES SDL2_TTF_INCLUDE_DIRS - VERSION_VAR SDL2_TTF_VERSION_STRING) - -# for backward compatibility -set(SDLTTF_LIBRARY ${SDL2_TTF_LIBRARIES}) -set(SDLTTF_INCLUDE_DIR ${SDL2_TTF_INCLUDE_DIRS}) -set(SDLTTF_FOUND ${SDL2_TTF_FOUND}) diff --git a/cmake/centurion-config.cmake b/cmake/centurion-config.cmake new file mode 100644 index 000000000..4ed69d198 --- /dev/null +++ b/cmake/centurion-config.cmake @@ -0,0 +1,6 @@ +find_package(SDL2 CONFIG) +find_package(SDL2_image CONFIG) +find_package(SDL2_mixer CONFIG) +find_package(SDL2_ttf CONFIG) + +include("${CMAKE_CURRENT_LIST_DIR}/centurionTargets.cmake") diff --git a/cmake/centurion.cmake b/cmake/centurion.cmake index 81eafc905..611d1cfe1 100644 --- a/cmake/centurion.cmake +++ b/cmake/centurion.cmake @@ -22,24 +22,6 @@ function(cen_copy_directory_post_build target from to) ${to}) endfunction() -function(cen_include_sdl_headers target) - target_include_directories(${target} - SYSTEM PRIVATE - ${SDL2_INCLUDE_DIR} - ${SDL2_IMAGE_INCLUDE_DIRS} - ${SDL2_TTF_INCLUDE_DIRS} - ${SDL2_MIXER_INCLUDE_DIRS}) -endfunction() - -function(cen_link_sdl_libs target) - target_link_libraries(${target} - PRIVATE - ${SDL2_LIBRARY} - ${SDL2_IMAGE_LIBRARIES} - ${SDL2_TTF_LIBRARIES} - ${SDL2_MIXER_LIBRARIES}) -endfunction() - function(cen_set_basic_compiler_options target) if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_options(${target} PRIVATE @@ -70,4 +52,50 @@ function(cen_set_basic_compiler_options target) target_compile_options(${target} PRIVATE -Werror) endif () endif () -endfunction() \ No newline at end of file +endfunction() + +# Checks if targets exists and stores the result in a variable. +# var: the name of the result variable +# ARGN: list of targets to check the existence of +function(cen_has_targets var) + set(${var} FALSE PARENT_SCOPE) + foreach(target IN LISTS ARGN) + if (NOT TARGET ${target}) + return() + endif () + endforeach () + set(${var} TRUE PARENT_SCOPE) +endfunction() + +# Checks if the relevant SDL targets exist and stores the result in the +# corresponding variable +# shared: the name of the shared libraries variable +# static: the name of the static libraries variable +function(cen_has_SDL shared static) + cen_has_targets(_shared + SDL2::SDL2 + SDL2_image::SDL2_image + SDL2_mixer::SDL2_mixer + SDL2_ttf::SDL2_ttf + ) + set(${shared} ${_shared} PARENT_SCOPE) + cen_has_targets(_static + SDL2::SDL2-static + SDL2_image::SDL2_image-static + SDL2_mixer::SDL2_mixer-static + SDL2_ttf::SDL2_ttf-static + ) + set(${static} ${_static} PARENT_SCOPE) +endfunction() + +# Finds a package using an environment variable path hint +# pkg: package to find +# hint: environment variable name +function(cen_find_env_package pkg hint) + if (DEFINED ENV{${hint}}) + file(TO_CMAKE_PATH $ENV{${hint}} hint_path) + find_package(${pkg} PATHS ${hint_path}) + else () + find_package(${pkg} CONFIG) + endif () +endfunction() diff --git a/cmake/centurion.pc.in b/cmake/centurion.pc.in new file mode 100644 index 000000000..445349b7b --- /dev/null +++ b/cmake/centurion.pc.in @@ -0,0 +1,7 @@ +prefix=${pcfiledir}/../.. +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: @PROJECT_NAME@ +Description: A modern C++ wrapper library for SDL2 +Version: @PROJECT_VERSION@ +Cflags: -I${includedir} diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 9bf373408..247e9f395 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -6,10 +6,7 @@ project(centurion-examples CXX) add_compile_definitions(RESOURCE_DIR="${CEN_RESOURCES_DIR}/") function(cen_add_example target) - target_include_directories(${target} PRIVATE ${CEN_SOURCE_DIR}) - - cen_include_sdl_headers(${target}) - cen_link_sdl_libs(${target}) + target_link_libraries(${target} PRIVATE centurion::centurion) cen_set_basic_compiler_options(${target}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..adf02c54a --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,7 @@ +target_sources(centurion-headers-only PUBLIC + FILE_SET HEADERS + BASE_DIRS ${CEN_SOURCE_DIR} + FILES centurion.hpp +) + +add_subdirectory(centurion) diff --git a/src/centurion/CMakeLists.txt b/src/centurion/CMakeLists.txt new file mode 100644 index 000000000..22cb00718 --- /dev/null +++ b/src/centurion/CMakeLists.txt @@ -0,0 +1,27 @@ +target_sources(centurion-headers-only PUBLIC + FILE_SET HEADERS + FILES + audio.hpp + common.hpp + concurrency.hpp + events.hpp + features.hpp + fonts.hpp + fwd.hpp + initialization.hpp + input.hpp + io.hpp + system.hpp + video.hpp +) + +add_subdirectory(audio) +add_subdirectory(common) +add_subdirectory(concurrency) +add_subdirectory(detail) +add_subdirectory(events) +add_subdirectory(fonts) +add_subdirectory(input) +add_subdirectory(io) +add_subdirectory(system) +add_subdirectory(video) diff --git a/src/centurion/audio/CMakeLists.txt b/src/centurion/audio/CMakeLists.txt new file mode 100644 index 000000000..cd21244a8 --- /dev/null +++ b/src/centurion/audio/CMakeLists.txt @@ -0,0 +1,8 @@ +target_sources(centurion-headers-only PUBLIC + FILE_SET HEADERS + FILES + fade_status.hpp + music_type.hpp + music.hpp + sound_effect.hpp +) diff --git a/src/centurion/common/CMakeLists.txt b/src/centurion/common/CMakeLists.txt new file mode 100644 index 000000000..1b6e5f33f --- /dev/null +++ b/src/centurion/common/CMakeLists.txt @@ -0,0 +1,15 @@ +target_sources(centurion-headers-only PUBLIC + FILE_SET HEADERS + FILES + errors.hpp + literals.hpp + logging.hpp + math.hpp + memory.hpp + primitives.hpp + result.hpp + sdl_string.hpp + traits.hpp + utils.hpp + version.hpp +) diff --git a/src/centurion/concurrency/CMakeLists.txt b/src/centurion/concurrency/CMakeLists.txt new file mode 100644 index 000000000..b1c08797c --- /dev/null +++ b/src/centurion/concurrency/CMakeLists.txt @@ -0,0 +1,9 @@ +target_sources(centurion-headers-only PUBLIC + FILE_SET HEADERS + FILES + condition.hpp + locks.hpp + mutex.hpp + semaphore.hpp + thread.hpp +) diff --git a/src/centurion/detail/CMakeLists.txt b/src/centurion/detail/CMakeLists.txt new file mode 100644 index 000000000..c7fabbf0e --- /dev/null +++ b/src/centurion/detail/CMakeLists.txt @@ -0,0 +1,10 @@ +target_sources(centurion-headers-only PUBLIC + FILE_SET HEADERS + FILES + array_utils.hpp + owner_handle_api.hpp + sdl_deleter.hpp + sdl_version_at_least.hpp + stdlib.hpp + tuple_type_index.hpp +) diff --git a/src/centurion/events/CMakeLists.txt b/src/centurion/events/CMakeLists.txt new file mode 100644 index 000000000..6f0afbac7 --- /dev/null +++ b/src/centurion/events/CMakeLists.txt @@ -0,0 +1,15 @@ +target_sources(centurion-headers-only PUBLIC + FILE_SET HEADERS + FILES + audio_events.hpp + controller_events.hpp + event_base.hpp + event_dispatcher.hpp + event_handler.hpp + event_sink.hpp + event_type.hpp + joystick_events.hpp + misc_events.hpp + mouse_events.hpp + window_events.hpp +) diff --git a/src/centurion/fonts/CMakeLists.txt b/src/centurion/fonts/CMakeLists.txt new file mode 100644 index 000000000..6eeead045 --- /dev/null +++ b/src/centurion/fonts/CMakeLists.txt @@ -0,0 +1,11 @@ +target_sources(centurion-headers-only PUBLIC + FILE_SET HEADERS + FILES + font_cache.hpp + font_direction.hpp + font_hint.hpp + font.hpp + wrap_alignment.hpp + + experimental/font_bundle.hpp +) diff --git a/src/centurion/input/CMakeLists.txt b/src/centurion/input/CMakeLists.txt new file mode 100644 index 000000000..449837b3e --- /dev/null +++ b/src/centurion/input/CMakeLists.txt @@ -0,0 +1,11 @@ +target_sources(centurion-headers-only PUBLIC + FILE_SET HEADERS + FILES + button_state.hpp + controller.hpp + joystick.hpp + keyboard.hpp + mouse.hpp + sensor.hpp + touch.hpp +) diff --git a/src/centurion/io/CMakeLists.txt b/src/centurion/io/CMakeLists.txt new file mode 100644 index 000000000..3552281dd --- /dev/null +++ b/src/centurion/io/CMakeLists.txt @@ -0,0 +1,9 @@ +target_sources(centurion-headers-only PUBLIC + FILE_SET HEADERS + FILES + file_mode.hpp + file_type.hpp + file.hpp + paths.hpp + seek_mode.hpp +) diff --git a/src/centurion/system/CMakeLists.txt b/src/centurion/system/CMakeLists.txt new file mode 100644 index 000000000..16caaf4f3 --- /dev/null +++ b/src/centurion/system/CMakeLists.txt @@ -0,0 +1,12 @@ +target_sources(centurion-headers-only PUBLIC + FILE_SET HEADERS + FILES + clipboard.hpp + endian.hpp + locale.hpp + memory.hpp + platform.hpp + power.hpp + shared_object.hpp + timer.hpp +) diff --git a/src/centurion/video/CMakeLists.txt b/src/centurion/video/CMakeLists.txt new file mode 100644 index 000000000..b9a4fe6ac --- /dev/null +++ b/src/centurion/video/CMakeLists.txt @@ -0,0 +1,19 @@ +target_sources(centurion-headers-only PUBLIC + FILE_SET HEADERS + FILES + animation.hpp + blend.hpp + color.hpp + display.hpp + flash_op.hpp + message_box.hpp + opengl.hpp + pixels.hpp + renderer_info.hpp + renderer.hpp + surface.hpp + texture.hpp + unicode_string.hpp + vulkan.hpp + window.hpp +) diff --git a/test/mocked-tests/CMakeLists.txt b/test/mocked-tests/CMakeLists.txt index d7db43b1f..b68370c91 100644 --- a/test/mocked-tests/CMakeLists.txt +++ b/test/mocked-tests/CMakeLists.txt @@ -67,14 +67,11 @@ cen_add_header_only_lib(libFFF ${CEN_FFF_DIR} ${CEN_FFF_DIR}/fff.h) target_include_directories(${CENTURION_MOCK_TARGET} PRIVATE ${PROJECT_SOURCE_DIR} - ${CEN_SOURCE_DIR} ) -cen_include_sdl_headers(${CENTURION_MOCK_TARGET}) -cen_link_sdl_libs(${CENTURION_MOCK_TARGET}) - target_link_libraries(${CENTURION_MOCK_TARGET} PRIVATE + centurion::centurion GTest::gtest libFFF) diff --git a/test/unit-tests/CMakeLists.txt b/test/unit-tests/CMakeLists.txt index 29c952972..d36361d83 100644 --- a/test/unit-tests/CMakeLists.txt +++ b/test/unit-tests/CMakeLists.txt @@ -201,18 +201,14 @@ add_executable(${CENTURION_TEST_TARGET} ${SOURCE_FILES}) target_include_directories(${CENTURION_TEST_TARGET} PRIVATE ${PROJECT_SOURCE_DIR} - ${CEN_SOURCE_DIR} ) -cen_include_sdl_headers(${CENTURION_TEST_TARGET}) - -cen_link_sdl_libs(${CENTURION_TEST_TARGET}) - target_link_libraries(${CENTURION_TEST_TARGET} PRIVATE cereal::cereal GLEW::GLEW GTest::gtest + centurion::centurion ) cen_set_basic_compiler_options(${CENTURION_TEST_TARGET}) @@ -258,4 +254,4 @@ cen_copy_directory_post_build(${CENTURION_TEST_TARGET} if (WIN32) cen_copy_directory_post_build(${CENTURION_TEST_TARGET} ${CEN_BINARIES_DIR} ${CMAKE_CURRENT_BINARY_DIR}) -endif () \ No newline at end of file +endif ()