find_package different result/searches between top CMakelists and cmake file

I am trying to use a vcpkg port (“vulkan-headers”) and their usage instruction didn’t work.

Well it does work (find_package find the port) if I do find_package(VulkanHeaders CONFIG REQUIRED) in a CMakelist but fails if I do it in an included cmake file like /Project/CMake/VulkanDependencies.cmake

Is that an expected behaviour?
I am doing find_packages for other ports like GTest and those are working. so I am inclined to say it is an issue with the port itself?

I finally found my stupid mistake. When I tried find_package(VulkanHeaders) in a cmake file it was included before the project cmake command.

find_package has to be called after the call to project.

Sorry for the noise!

What is the Output of

CMake … —debug-find-pkg=VulkanHeaders

I found the issue, find_package was called before the call to project.
The output of debug-find didn’t contain the path to the vcpkg installed directory.

I wish the cmake command that can’t be called before project would error out on it. Or at least be documented. I have been bitten way too often by just moving around include cmake file and breaking the build.

Maybe this issue is with vcpkg. I mean maybe find_package can be called before project but not for vcpkg package? I don’t know enough on the internals here.

Thanks for trying to help!

find_packge() needs to know the languages, toolchain, binary format, search paths, …

So I guess it is only usable after Project()

Ya it makes sense, when include file does the find_package to bring in dependencies, it is easy when moving around the include directive to fall into this trap. :slight_smile: