libsdl-org / SDL_mixer

An audio mixer that supports various file formats for Simple Directmedia Layer.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CMake cannot find PkgConfigHelper when using find_package()

micahfolsom opened this issue · comments

Having an issue when trying to configure CMake in a project using SDL3_mixer. I've compiled and installed the latest SDL3 and SDL3_mixer (static libs) myself to the default system locations (Ubuntu 22.04) and I'm using find_package() to bring it into my project. I get the following error:

CMake Error at /usr/local/lib/cmake/SDL3_mixer/SDL3_mixerConfig.cmake:92 (include):
  include could not find requested file:

    PkgConfigHelper
Call Stack (most recent call first):
  CMakeLists.txt:14 (find_package)

Just to make sure I wasn't doing something really silly, I made a simple example where the CMakeLists.txt includes (beyond the usual project boilerplate) this:

find_package(SDL3 3.0.0 REQUIRED)
find_package(SDL3_mixer 3.0.0 REQUIRED)

include_directories(${PROJECT_SOURCE_DIR}/include)
file(GLOB MYPROJ_SOURCES ${PROJECT_SOURCE_DIR}/src/test/*.cpp)
add_executable(${EXE_NAME}
  ${PROJECT_SOURCE_DIR}/src/main.cpp
  ${MYPROJ_SOURCES}
)
target_link_libraries(${EXE_NAME} SDL3::SDL3-static)
target_link_libraries(${EXE_NAME} SDL3_mixer::SDL3_mixer-static)

There's only one header, and one trivial object in a .cpp that don't really matter. In main() we've got:

int main(int argc, char* argv[]) {
  if (SDL_Init(SDL_INIT_VIDEO) == -1) {
    cout << SDL_GetError() << endl;
    return 1;
  }

  SDL_AudioSpec spec = {.format = SDL_AUDIO_S16LE,
                        .channels = MIX_DEFAULT_CHANNELS,
                        .freq = MIX_DEFAULT_FREQUENCY};
  if (Mix_OpenAudio(0, &spec) < 0) {
    cout << "Error opening audio" << endl;
    return 1;
  }

  Mix_CloseAudio();
  SDL_Quit();
  return 0;
}

/usr/local/lib/cmake/SDL3_mixer/PkgConfigHelper.cmake exists - the problem is it's not finding it. If I go to the cited section of the code (SDL3_mixerConfig.cmake:92):

        include(CMakeFindDependencyMacro)
        include(PkgConfigHelper)

        set(_sdl_cmake_module_path "${CMAKE_MODULE_PATH}")
        list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")

Is this ordering incorrect or is there an issue with CMakeFindDependencyMacro? If I move the include() statements to after CMAKE_MODULE_PATH is set, it works, since PkgConfigHelper.cmake is then included.

Fixed in eebcbea

Looks like we only build shared libraries with system dependencies on ci.

Thanks for opening this issue!