I try to find a package (SDL2 and SDL2_image) I know exists and is installed in a custom directory. Since I am on Linux it should search all of these subdirectories, but it just does not and I see no reason why.
<prefix>/(lib/<arch>|lib*|share)/cmake/<name>*/ (U)
<prefix>/(lib/<arch>|lib*|share)/<name>*/ (U)
<prefix>/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/ (U)
<prefix>/<name>*/(lib/<arch>|lib*|share)/cmake/<name>*/ (W/U)
<prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/ (W/U)
<prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/ (W/U)
I tried CMAKE_PREFIX_PATH
, SDL2_ROOT
, HINTS
, PATHS
etc. and also checked the NO_*
variables, but even with set(CMAKE_FIND_DEBUG_MODE TRUE)
it just shows <prefix>/SDL2Config.cmake
and <prefix>/sdl2-config.cmake
as guesses for all of the prefixes it found.
I am at a loss, why it just refuses to search the documented subdirectories. I don't want to specify the full path, because that just hardcodes something that could change in the future and is different depending on the system.
I am using CMake 3.24.1. Any help is appreciated.
Code:
set(CMAKE_PREFIX_PATH ${SDL_INSTALL_DIR})
set(CMAKE_FIND_DEBUG_MODE TRUE)
find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
set(CMAKE_FIND_DEBUG_MODE FALSE)
Several things I learned during debugging this problem:
CMAKE_FIND_DEBUG_MODE
for find_package(..)
doesn't actually show if it tried path suffixes or not. And you also don't see if it took the shown path as prefix path or absolute path. Path suffixes only get appended to prefix paths like CMAKE_PREFIX_PATH
or <package>_ROOT
. This is true for CMake 3.24.1. find_library(..)
for example has a much more comprehensive debug output.
If you are in a cross-compiling all the usual "good guesses" go out of the window or don't work. Be very careful and check EVERYTHING when setting up the environment. Even things like the selected compiler matter, since it is used to determine the library path (32/64bit for example, through CMAKE_SIZEOF_VOID_P
)
You cannot fix a broken environment by setting variables locally. They usually don't have any effect for reasons only the underlying code can explain to you. Example FIND_LIBRARY_USE_LIB64_PATHS
is documented, but enabling it usually doesn't have any effect since the underlying check looks like below. If your environment doesn't advertise 64-bit nothing will happen. And if it
already is 64-bit this flag is most likely already set automatically.
if (this->Makefile->PlatformIs64Bit() &&
this->Makefile->GetState()->GetGlobalPropertyAsBool(
"FIND_LIBRARY_USE_LIB64_PATHS")) {
this->UseLib64Paths = true;
}
Read carefully what is said in the documentation. It is painful, but you might miss a crucial detail like that FIND_LIBRARY_USE_LIB64_PATHS
is a global property and not a variable.