Search code examples
configurationcmakeautotools

Exclude feature in CMake's configure


With autotool's configure every feature can be explicitly enabled by --with-feature=... / --enable-feature=... or explicitly disabled by --without-feature / --disable-feature.

Some CMake find packages scripts evaluate variablesfeature_ROOT to search there first, but it is uncommon and discouraged. CMake evaluates several paths and tries to find the libraries there. To add a feature that is not located in the default paths, the right path can be added.

How can a feature be disabled, that is installed on the system and thus is found by CMake's configure? For example Java is installed in the default below /usr and found by CMake without adding the path for CMake; how can I disable Java? It will always be found.

I don't want to manually modify the CMakeCache.txt.

To sum up: I have a project that I don't want/can modify, it has a find_package and I have the package (e.g. Java) installed but I don't want CMake to use this package. I want a switch/flag do deactivate the installed and usually found package.


Solution

  • As I discovered, it is not difficult at all. To prevent my feature from being found, I pass

    -DFEATURE_FOUND=FALSE
    

    to CMake and then it is not found, even when installed.

    Or one can pass

    -DCMAKE_DISABLE_FIND_PACKAGE_FEATURE=TRUE
    

    to suppress the find module completely.