FIND_PACKAGE working at main level, failing on dependencies

I’m bringing my CMake world under the Visual Studio umbrella. Lots of things are working, including the finding of packages that I explicitly invoke (whew!). But now I’m having strange problems with FIND_PACKAGE operating on dependencies. Seeing this error:

[CMake] CMake Error at C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
1> [CMake] Could NOT find libxmp (missing: libxmp_LIBRARY libxmp_INCLUDE_PATH)
1> [CMake] Call Stack (most recent call first):
1> [CMake] C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.29/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
1> [CMake] C:/msys64/ucrt64/lib/cmake/SDL2_mixer/Findlibxmp.cmake:28 (find_package_handle_standard_args)
1> [CMake] C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/share/cmake-3.29/Modules/CMakeFindDependencyMacro.cmake:76 (find_package)
1> [CMake] C:/msys64/ucrt64/lib/cmake/SDL2_mixer/sdl2_mixer-config.cmake:98 (find_dependency)
1> [CMake] CMakeLists.txt:21 (find_package)

I can confirm that “C:\msys64\ucrt64\lib\cmake\libxmp\libxmp-config.cmake” exists, and I would have expected it to be used. But some confusion is getting in the way.

I have little doubt that this is some sort of environment problem. My system was confused for a while with two different flavors of MSYS2 installed, but I have cleaned out every version now except ucrt64. To try to set the environment straight I have configured CMakeSettings.json to make sure that Visual Studio (and presumably CMake) knows to look in ucrt64 places:

{
“configurations”: [
{
“name”: “Debug”,
“generator”: “Ninja”,
“configurationType”: “Debug”,
“inheritEnvironments”: [ “msvc_arm64_x64” ],
“buildRoot”: “${projectDir}\build\${name}”,
“installRoot”: “${projectDir}\out\install\${name}”,
“cmakeCommandArgs”: “”,
“buildCommandArgs”: “”,
“ctestCommandArgs”: “”,
“environment”: {
“MSYSTEM”: “UCRT64”,
“PATH”: “C:/msys64/ucrt64/bin;C:/msys64/usr/bin;${env:PATH}”,
“PKG_CONFIG_PATH”: “C:/msys64/ucrt64/lib/pkgconfig”
}
}
]
}

So what might I still be missing?

Here’s my command line generated by VS:

1> Command line: “C:\WINDOWS\system32\cmd.exe” /c “%SYSTEMROOT%\System32\``chcp.com`` 65001 >NUL && “C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\CMake\bin\cmake.exe” -G “Ninja” -DCMAKE_BUILD_TYPE:STRING=“Debug” -DCMAKE_INSTALL_PREFIX:PATH=“C:\Users\ken\Desktop\prog24\HallOfMirrors\out\install\Debug” -DCMAKE_C_COMPILER:FILEPATH=“C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/arm64/cl.exe” -DCMAKE_CXX_COMPILER:FILEPATH=“C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.41.34120/bin/Hostx64/arm64/cl.exe” -DCMAKE_MAKE_PROGRAM=“C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\CMAKE\Ninja\ninja.exe” “C:\Users\ken\Desktop\prog24\HallOfMirrors” 2>&1”
1> Working directory: C:\Users\ken\Desktop\prog24\HallOfMirrors\build\Debug

Here’s CMakeLists.txt. It’s a bit messy with various attempts to get libraries to be found, but I’m hoping that you can see past this to understand the more basic question of what would be throwing off the finding of dependencies:

cmake_minimum_required(VERSION 3.28)
project(my-project)

set (HALL_OF_MIRRORS 
    HallOfMirrors.cpp
    MirrorCore.cpp
    MirrorThings.cpp
    Thief.cpp
    Laser.cpp 
    Ray.cpp
    LogMe.cpp
    SetupScreen.cpp
    Keyboards.cpp
    InputCode.cpp)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")

# These all succeed:
find_package(SDL2 REQUIRED COMPONENTS SDL2)  # recommended in Readme
find_package(SDL2_mixer REQUIRED)
find_package(SDL2_ttf REQUIRED)
find_package(SDL2_image REQUIRED)

find_package(Freetype REQUIRED)

set (SDL2_gfx_LIBRARIES C:/msys64/ucrt64/lib/libSDL2_gfx.dll.a)
link_directories(${SDL2_LIBRARY_DIRS} /opt/homebrew/lib/)

include_directories(/opt/homebrew/include . ../Drawbox/Library ../Drawbox/Tools 
                        ../Drawbox/APClass Library/jpeg
                        ./SDL_ttf
                        /opt/local/include/freetype2)
message( STATUS SDL2_INCLUDE_DIRS=${SDL2_INCLUDE_DIRS} )
message( STATUS SDL2_LIBRARIES=${SDL2_LIBRARIES} )

include(../Drawbox/Library/CMakeLists.txt)
include(../Drawbox/Tools/CMakeLists.txt)
include(../Drawbox/APClass/CMakeLists.txt)

add_executable(HallOfMirrors ../Drawbox/DrawboxMain.cpp ${HALL_OF_MIRRORS} 
                    "../Drawbox/SDL2_gfx-1.0.1/SDL2_gfxPrimitives.c"
                    "../Drawbox/SDL2_gfx-1.0.1/SDL2_rotozoom.c"
                    ${DRAWBOX} ${APCLASS} ${TOOLS}) 

target_compile_features(HallOfMirrors PUBLIC cxx_std_11)
target_compile_options(HallOfMirrors PRIVATE 
        -Wno-switch -Wno-deprecated-declarations -Wno-write-strings)

if (WIN32)  
    target_link_libraries(HallOfMirrors 
            ${SDL2_LIBRARIES} 
            SDL2_ttf::SDL2_ttf
            SDL2_image::SDL2_image
            ${SDL2_gfx_LIBRARIES}
            fmt) 
endif()
   

Details: Visual Studio 17.11.4 running on Windows 11.

It looks like SDL uses find_dependency() without CONFIG mode, plus it vendors a Find* module for that libxmp thing, so it does not consider the CMake config that you have at C:\msys64\ucrt64\lib\cmake\libxmp\libxmp-config.cmake.

So you’d either need to patch SDL files to force the CONFIG mode (assuming that C:\msys64\ucrt64\lib\cmake is part of the CMAKE_PREFIX_PATH) or provide values for libxmp_LIBRARY and libxmp_INCLUDE_PATH variables to help their module find stuff looking at their current Findlibxmp.cmake I actually can’t say what needs to be provided to help it find the package, as it seems to rely on results from pkg-config. Maybe you don’t have pkg-config installed?

…Ah yes, also this:

Visual Studio
MSYS2

is probably not something that is meant to work together? Or at least I’ve never seen Visual Studio / MSVC being used with MSYS environment.

1 Like

OK so how do I use SDL2 libraries without MSYS2? Early on, I was told that’s what I needed to install to get and support those libraries. To be more precise, can I use SDL2 libraries and cmake without MSYS2? I build this project using cmake on other systems, and VS looks well set up to cooperate with cmake, so I’d like to take advantage of that if possible.

Just like any other library: either build it from sources or get pre-built binaries. MSYS2 (or any other environment) has never been a requirement for that, don’t know who told you otherwise, maybe they meant something different.

Try the vcpkg package manager ( vcpkg.io )