[CMake] find_package Config vs Module mode

Johannes Zarl-Zierl johannes at zarl-zierl.at
Sat Oct 20 09:46:49 EDT 2018


Hi Joachim,

Am Samstag, 20. Oktober 2018, 13:22:04 CEST schrieb Joachim Wuttke:
> If Config mode is the newer, preferred way to find a package, I would expect
> find_package to first try Config mode, and only fall back to Module mode if
> no config scripts can be found. However, according to the find_package doc
> page, it is just the other way round.
> 
> Why?

The reason as far as I understand it is that you, as the consumer of a 
library, might want to customize the find_package process. Since find_package 
modules are usually shipped by your own code[1], it's not a problem that the 
module eclipses the config package.

> How to enforce that new config scripts are used if there are still FindXXX
> modules around?

First of all, purge the FindXXX modules from your own code base if you don't 
use them.
Otherwise, append the "CONFIG" keyword to the find_package call as described 
in the docs[2].

If you want to keep the FindXXX module around for compatibility with older 
versions of a library, then an even better solution is to fix your FindXXX 
module to call find_package(...CONFIG) and skip the search if a config file is 
found.

Cheers,
  Johannes



[1] apart from the modules shipped with cmake
[2] https://cmake.org/cmake/help/latest/command/find_package.html#full-signature-and-config-mode




More information about the CMake mailing list