find_dependency from CMakeFindDependencyMacro should forward any hints
If I use find_package(name CONFIG REQUIRED HINTS "path/to/where/I/think/it/is")
, and it has dependencies it finds via find_dependency
, it only searches the regular paths, not the extra ones specified with HINTS
. It's reasonably likely that these dependencies will be installed to the same place, so if the hints are needed for the outer package, they'll probably be needed for the inner one, too.
I ran into this when trying to link with glslang. On Windows, the Vulkan SDK provides glslang, and if you've got the latest version, intact CMake config for it too (although older versions have none or not enough to accomplish anything productive) Nope, the CMake config it provides is still missing a file as of 1.3.283.0. The regular Vulkan-finding module can find the Vulkan SDK based on the environment variable its installer sets even if it's not included in CMAKE_PREFIX_PATH
, so in principle, one could find glslang in the Vulkan SDK, too, with
# For Windows and MacOS, the Vulkan SDK provides glslang, but CMake doesn't necessarily look there for anything except Vulkan
foreach(vulkan_lib ${Vulkan_LIBRARIES})
get_filename_component(vulkan_lib_dir "${vulkan_lib}" DIRECTORY)
list(APPEND glslang_hints ${vulkan_lib_dir})
get_filename_component(vulkan_lib_dir "${vulkan_lib_dir}" DIRECTORY)
list(APPEND glslang_hints ${vulkan_lib_dir})
endforeach(vulkan_lib ${Vulkan_LIBRARIES})
find_package(glslang 14 CONFIG REQUIRED HINTS ${glslang_hints})
For me, this does find glslang itself, but it depends on SPIRV-Tools-opt
, also in the same location, and without the hints for the nested find_dependency
call, that location isn't checked.
Instead, I have to use the prefix path:
# For Windows and MacOS, the Vulkan SDK provides glslang, but CMake doesn't necessarily look there for anything except Vulkan
foreach(vulkan_lib ${Vulkan_LIBRARIES})
get_filename_component(vulkan_lib_dir "${vulkan_lib}" DIRECTORY)
list(APPEND CMAKE_PREFIX_PATH ${vulkan_lib_dir})
get_filename_component(vulkan_lib_dir "${vulkan_lib_dir}" DIRECTORY)
list(APPEND CMAKE_PREFIX_PATH ${vulkan_lib_dir})
endforeach(vulkan_lib ${Vulkan_LIBRARIES})
find_package(glslang 14 CONFIG REQUIRED)
That's less than ideal as it also adds the search path(s) for everything that comes later unless it's surrounded with block
.