-
Notifications
You must be signed in to change notification settings - Fork 184
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
[Help] SDL2 addon libraries #144
Comments
Hey, unfortunately, SLD2 and its plugins don't seem to have great CMake support, so while it should be possible using CPM.cmake, in this case I'd recommend using the traditional approach of installing them locally on your system using a package manager such as brew or apt-get and using Some notes in case you still want to go forward using CPM.cmake:
if (SDL2_ADDED)
add_library(SDL2::SDL2 ALIAS SDL2)
endif()
The final script could look something like this (assuming a cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
# ---- Project ----
project(Playground LANGUAGES CXX C)
# ---- Fetch CPM ----
set(CPM_DOWNLOAD_VERSION 0.27.1)
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake")
file(DOWNLOAD
https://github.com/TheLartians/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endif()
include(${CPM_DOWNLOAD_LOCATION})
# ---- Add dependencies via CPM ----
# See https://github.com/TheLartians/CPM.cmake for details and examples
CPMAddPackage(
NAME SDL2
VERSION 2.0.12
URL https://libsdl.org/release/SDL2-2.0.12.zip
)
if (SDL2_ADDED)
add_library(SDL2::SDL2 ALIAS SDL2)
endif()
CPMAddPackage(
NAME freetype
GIT_REPOSITORY https://github.com/aseprite/freetype2.git
GIT_TAG VER-2-10-0
VERSION 2.10.0
)
if (freetype_ADDED)
add_library(Freetype::Freetype ALIAS freetype)
endif()
CPMAddPackage(
NAME SDL2_ttf
VERSION 2.0.15
URL https://libsdl.org/projects/SDL_ttf/release/SDL2_ttf-2.0.15.zip
)
CPMAddPackage(
NAME SDL2_mixer
VERSION 2.0.15
URL https://libsdl.org/projects/SDL_mixer/release/SDL2_mixer-2.0.4.zip
DOWNLOAD_ONLY TRUE
)
if (SDL2_mixer_ADDED)
# quick and dirty target definitions
# might need extra configuration and install commands to work properly
file(GLOB SDL2_mixer_SOURCES "${SDL2_mixer_SOURCE_DIR}/*.c")
add_library(SDL2_mixer ${SDL2_mixer_SOURCES})
target_link_libraries(SDL2_mixer SDL2::SDL2)
target_include_directories(SDL2_mixer PUBLIC ${SDL2_mixer_SOURCE_DIR})
endif()
# ---- Create executable target ----
add_executable(test main.cpp)
target_link_libraries(test SDL2 SDL2_ttf SDL2_mixer) I hope this helps you move forward with your project! |
I wanted to use CPM.cmake for the convenience on multi-platform build, so I'll insist on it. The option you mentioned on Thanks for the help! |
Sounds good. I'll close the issue for now, but feel free to re-open if you run into further SDL2/CPM.cmake related problems! |
I'm having a hard time using CPM with the SDL2 libraries.
I've used the ModerCppStarter repository to start this project.
Adding
SDL2
works fine:But I can't make
TTF
andMixer
libraries to work as intended:When linking the
SDL2_ttf
andSDL2_mixer
libraries to the project, in the CMakeLists.txt file of the standalone source, I've get the following error:Apparently, I need to build the SDL2_ttf and SDL2_mixer linking to the SDL2 target, but I have no clue of how to do that.
Thanks in advance.
The text was updated successfully, but these errors were encountered: