On Thursday 16 February 2012, Alexander Neundorf wrote: > Hi, > > when I use a Find-module to search for a package, I get a nice error > message if the package could not be found.
I collected the various error messages which can be produced in the different cases: * package not found * package found, but version doesn't match * REQUIRED * without REQUIRED * find_package() with no Find-module present * find_package(NO_MODULE) * find_package() with a wrapper Find-module which does: find_package(ecm QUIET NO_MODULE) fphsa(ecm CONFIG_MODE) Here we go: package not found, REQUIRED: -------------------------------------------------------- 1.) find_package() with no Find-module present: CMake Error at CMakeLists.txt:4 (find_package): Could not find module Findecm.cmake or a configuration file for package ecm. Adjust CMAKE_MODULE_PATH to find Findecm.cmake or set ecm_DIR to the directory containing a CMake configuration file for ecm. The file will have one of the following names: ecmConfig.cmake ecm-config.cmake ***** processing continues, but with error -------------------------------------------------------- 2.) find_package(NO_MODULE): CMake Error at CMakeLists.txt:4 (find_package): Could not find a configuration file for package ecm. Set ecm_DIR to the directory containing a CMake configuration file for ecm. The file will have one of the following names: ecmConfig.cmake ecm-config.cmake ***** processing continues, but with error -------------------------------------------------------- 3.) find_package() with a wrapper Find-module: CMake Error at /opt/cmakeHEAD/share/cmake-2.8/Modules/ FindPackageHandleStandardArgs.cmake:91 (MESSAGE): Could NOT find ecm: found neither ecmConfig.cmake nor ecm-config.cmake (Required is at least version "0.0.4") Call Stack (most recent call first): /opt/cmakeHEAD/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:121 /opt/cmakeHEAD/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:247 Findecm.cmake:4 (find_package_handle_standard_args) CMakeLists.txt:7 (find_package) ***** processing stops -------------------------------------------------------- Without REQUIRED the messages are the same (with the wrapper Find-module the callstack is not printed), but processing continues without error. Now the cases where the Config file was found, but the version didn't match: -------------------------------------------------------- 4.) find_package() with no Find-module present, same with NO_MODULE: CMake Error at CMakeLists.txt:4 (find_package): Could not find a configuration file for package "ecm" that is compatible with requested version "0.0.4". The following configuration files were considered but not accepted: /opt/ecm/share/ecm-0.0.2/cmake/ecm-config.cmake, version: 0.0.2 /opt/ecm/share/ecm-0.0.3/cmake/ecm-config.cmake, version: 0.0.3 ***** processing continues, but with error -------------------------------------------------------- 5.) find_package() with a wrapper Find-module: CMake Error at /opt/cmakeHEAD/share/cmake-2.8/Modules/ FindPackageHandleStandardArgs.cmake:91 (MESSAGE): Could NOT find ecm (Required is at least version "0.0.4"), checked the following files: /opt/ecm/share/ecm-0.0.2/cmake/ecm-config.cmake (version 0.0.2) /opt/ecm/share/ecm-0.0.3/cmake/ecm-config.cmake (version 0.0.3) Call Stack (most recent call first): /opt/cmakeHEAD/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:117 /opt/cmakeHEAD/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:247 Findecm.cmake:4 (find_package_handle_standard_args) CMakeLists.txt:7 (find_package) ***** processing stops -------------------------------------------------------- What should be improved: 1.), 2.), 4.) processing should stop if REQUIRED was used 2.) CMAKE_PREFIX_PATH should be mentioned 1.), 2.) if a version number was used, this should be printed in the error message 1.) CMAKE_PREFIX_PATH should be mentioned at least. This is the one error message which is IMO problematic. It basically only says "it did not work", and I don't know whether the package is missing or whether the buildsystem of the project is broken, which are two significantly different problems - one requires installing a package, the other requires hacking the buildsystem of an unknown project. This could be avoided by making NO_MODULE required when the intention is to search for a Config file (I would have preferred from the beginning if find_package() would use only Find-modules, and for searching Config-files there would have been a separate command like find_config()). In general, I would still recommend everybody to use the small wrapper Find- modules also for packages which install a Config.file, if only for the purpose to contain some documentation or to set up information for FeatureSummary.cmake. Alex -- Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers