# FIND\_PACKAGE working at main level, failing on dependencies

**URL:** https://discourse.cmake.org/t/find-package-working-at-main-level-failing-on-dependencies/15414
**Category:** Code
**Tags:** os:windows, comp:msvc, gen:ninja
**Created:** [December 21, 2025, 8:17pm UTC](https://discourse.cmake.org/t/find-package-working-at-main-level-failing-on-dependencies/15414 "2025-12-21T20:17:10Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Joymaker](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@Joymaker](https://discourse.cmake.org/u/Joymaker)
#### Post date: [December 21, 2025, 8:17pm UTC](https://discourse.cmake.org/t/find-package-working-at-main-level-failing-on-dependencies/15414/1 "2025-12-21T20:17:10Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

### Author: ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)
#### Post date: [December 22, 2025, 1:38pm UTC](https://discourse.cmake.org/t/find-package-working-at-main-level-failing-on-dependencies/15414/2 "2025-12-22T13:38:49Z")

</div>

It looks like SDL uses `find_dependency()` without `CONFIG` [mode](https://cmake.org/cmake/help/latest/command/find_package.html#search-modes), 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](https://github.com/libsdl-org/SDL_mixer/blob/cccd5f726570154ec1c09a9340afce87d9828c39/cmake/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.

---

<div class="post-metadata">

### Author: ![Joymaker](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/59ef9b/32.png) [@Joymaker](https://discourse.cmake.org/u/Joymaker)
#### Post date: [December 30, 2025, 7:04pm UTC](https://discourse.cmake.org/t/find-package-working-at-main-level-failing-on-dependencies/15414/3 "2025-12-30T19:04:31Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![retif](https://discourse.cmake.org/user_avatar/discourse.cmake.org/retif/32/1776_2.png) [@retif](https://discourse.cmake.org/u/retif)
#### Post date: [December 31, 2025, 9:19am UTC](https://discourse.cmake.org/t/find-package-working-at-main-level-failing-on-dependencies/15414/4 "2025-12-31T09:19:20Z")

</div>

> [@Joymaker](#):
>
> how do I use SDL2 libraries without MSYS2

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.

---

<div class="post-metadata">

### Author: ![leha-bot](https://discourse.cmake.org/user_avatar/discourse.cmake.org/leha-bot/32/921_2.png) [@leha-bot](https://discourse.cmake.org/u/leha-bot)
#### Post date: [January 3, 2026, 7:08am UTC](https://discourse.cmake.org/t/find-package-working-at-main-level-failing-on-dependencies/15414/5 "2026-01-03T07:08:16Z")

</div>

Try the vcpkg package manager ( [vcpkg.io](http://vcpkg.io) )
