Wildcards in PATHS or HINTS in find_file, file_path, etc.

Hi,

The following seems to work, but as far as I can see, the documentation does not indicate that wildcards are legal:

# I have a file called /Path/To/Stuff/Under/Other/Stuff/MyFile.txt
SET(MY_ROOT_DIR /Path/To/Stuff)
FIND_PATH(MY_PATH NAMES MyFile.txt PATHS ${MY_ROOT_DIR}/* PATH_SUFFIXES Other/Stuff NO_DEFAULT_PATHS)

However, putting a wildcard in PATH_SUFFIXES does not work:

FIND_PATH(MY_PATH NAMES MyFile.txt PATHS ${MY_ROOT_DIR} PATH_SUFFIXES */Other/Stuff NO_DEFAULT_PATHS)

Are wildcards an officially supported feature of HINTS and PATHS?

One use case would be a known directory structure where a file resides under a well-defined path, but only one subdirectory in the middle of the path might be system-specific such as lib, lib32, lib64, etc.

Thanks,

Alex

The lib directory difference is handled in find_library at least:

https://cmake.org/cmake/help/latest/command/find_library.html

If the CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX variable is set all search paths will be tested as normal, with the suffix appended, and with all matches of lib/ replaced with lib${CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX}/ . This variable overrides the FIND_LIBRARY_USE_LIB32_PATHS , FIND_LIBRARY_USE_LIBX32_PATHS , and FIND_LIBRARY_USE_LIB64_PATHS global properties.

It doesn’t happen for other find_X commands though. You could use find_library first and then manipulate its path to find its directory and use it as a HINTS path for the subsequent find_ calls though.

Thank you, this is indeed the proper solution for the lib vs. lib64. However, more generally, I was wondering why wildcards seem to work in HINTS and PATHS, but I can’t find and documentation stating that wildcards are supported in this context. Is it a side-effect of the implementation and not an officially supported feature, or are we supposed to be able to use wildcards in HINTS and PATHS in find_path(), find_library(), find_file(), etc?

It looks to be an implementation detail. For how long the behavior has been around, it should probably be documented (who knows who else discovered this and started depending on it). Please file an issue to track it.

Cc: @brad.king

I think this was just an oversight in the docs. I traced the expansion of globs back to commit 4650f78dd5 from 2006. It should be explicitly documented and tests added if missing. Please file an issue for this.

I’ve filed the issue here: https://gitlab.kitware.com/cmake/cmake/-/issues/21411