find_package: <PackageName>_ROOT not searched for alternate NAMES
find_package(QT NAMES Qt6)
cannot search in the variable Qt6_ROOT
.
Problem Descriptions
I specified the Cache/Environment Variable "Qt6_ROOT": "C:\\Qt\\6.3.2\\msvc2019_64"
in the CMakePresets.json.
However, I found that it cannot search the config file with the following code:
find_package(QT NAMES Qt6 Qt6 CONFIG REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} CONFIG REQUIRED
COMPONENTS
Core Widgets
)
Here is the error message reported:
Click to expand
CMake Error at CMakeLists.txt:6 (find_package):
Could not find a package configuration file provided by "QT" with any of
the following names:
Qt6Config.cmake
qt6-config.cmake
Qt6Config.cmake
qt6-config.cmake
Add the installation prefix of "QT" to CMAKE_PREFIX_PATH or set "QT_DIR" to
a directory containing one of the above files. If "QT" provides a separate
development package or SDK, be sure it has been installed.
-- Configuring incomplete, errors occurred!
Instead, if I specified the Cache/Environment Variable "CMAKE_PREFIX_PATH": "C:\\Qt\\6.3.2\\msvc2019_64"
, it worked successfully.
Click to expand
-- The C compiler identification is MSVC 19.29.30146.0
-- The CXX compiler identification is MSVC 19.29.30146.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - not found
-- Found Threads: TRUE
-- Performing Test HAVE_STDATOMIC
-- Performing Test HAVE_STDATOMIC - Success
-- Found WrapAtomic: TRUE
-- Could NOT find WrapVulkanHeaders (missing: Vulkan_INCLUDE_DIR)
-- Configuring done
-- Generating done
-- Build files have been written to: D:/Code/Cpp/Udemy-Qt6-Parwiz/GuiAndMobile/build/win32-msvc-x64-ninja
My Opinion
According to the Documentation of find_package(), the syntax find_package(<PackageName> NAMES <name1>)
will search <name1>-config.cmake
. Therefore, the Environment Variable <name1>_ROOT
should be searched. This is what I thought.
If the
NAMES
option is given, the names following it are used instead of<PackageName>
.
Although the documentation about the search path only mentioned the Environment Variable <PackageName>_ROOT
not including Cache Variable, I found the following code can search the Qt6Config.cmake
with the Cache Variable Qt6_ROOT
specified:
find_package(Qt6 CONFIG REQUIRED
COMPONENTS
Core Widgets
)
Is this a bug?