libsdl-org / SDL_mixer

An audio mixer that supports various file formats for Simple Directmedia Layer.
zlib License
399 stars 134 forks source link

how do I use cmake with this library? #624

Closed sakgoyal closed 1 month ago

sakgoyal commented 1 month ago

I am trying to use the CPM package manager with this but I am having issues getting it to work.

this is my current CMakeLists.txt

CPMAddPackage("gh:libsdl-org/SDL#release-2.30.5")
CPMAddPackage("gh:libsdl-org/SDL_image#release-2.8.2")
CPMAddPackage("gh:libsdl-org/SDL_mixer#release-2.8.0")
CPMAddPackage("gh:libsdl-org/SDL_ttf#release-2.22.0")
target_link_libraries(${PROJECT_NAME} PRIVATE
    SDL2::SDL2
    SDL2_image::SDL2_image
    SDL2_mixer::SDL2_mixer
    SDL2_ttf::SDL2_ttf
)

and this is what I have in my pch.h file:

#include <SDL2/SDL.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <SDL_ttf.h>

image everything works except the mixer library. it fails to find the correct path and work correctly. im not sure if I am doing something wrong or not since the other libraries are working as expected.

I am building on:

madebr commented 1 month ago

I cannot reproduce this on Linux, using this CMakeLists.txt:

cmake_minimum_required(VERSION 3.22)
project(my_project LANGUAGES C)

file(WRITE main.c [[
#include <SDL.h>
#include <SDL_mixer.h>

int main(int argc, char *argv[]) {
 SDL_Init(SDL_INIT_VIDEO);
  Mix_Init(0);
  Mix_Quit();
 SDL_Quit();
 return 0;
}
]])

add_executable(main main.c)

include("${CMAKE_CURRENT_LIST_DIR}/CPM.cmake")
CPMAddPackage("gh:libsdl-org/SDL#release-2.30.5")
CPMAddPackage("gh:libsdl-org/SDL_mixer#release-2.8.0")
target_link_libraries(main PRIVATE
    SDL2::SDL2
    SDL2_mixer::SDL2_mixer
)
sakgoyal commented 1 month ago

sorry yea im not entirely sure what happened. I deleted the build folder and started again and the error went away. /shrug

sakgoyal commented 1 month ago

I did however have to add the WIN32 specific stuff to make it build.

this was my final cmakelist:


include_directories(${SDL2_INCLUDE_DIRS})

CPMAddPackage("gh:libsdl-org/SDL#release-2.30.5")
CPMAddPackage("gh:libsdl-org/SDL_image#release-2.8.2")
CPMAddPackage("gh:libsdl-org/SDL_mixer#release-2.8.0")
CPMAddPackage("gh:libsdl-org/SDL_ttf#release-2.22.0")
target_link_libraries(${PROJECT_NAME} PRIVATE
    SDL2::SDL2
    SDL2_image::SDL2_image
    SDL2_mixer::SDL2_mixer
    SDL2_ttf::SDL2_ttf
    SDL2main # DONT FORGET THIS PART OR ELSE YOU GET LINKER ERRORS!!
)