# Calling CMake "default" Find\<Module\> from a user defined one

**URL:** https://discourse.cmake.org/t/calling-cmake-default-find-module-from-a-user-defined-one/10723
**Category:** Usage
**Created:** [April 23, 2024, 11:47am UTC](https://discourse.cmake.org/t/calling-cmake-default-find-module-from-a-user-defined-one/10723 "2024-04-23T11:47:06Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [April 23, 2024, 11:47am UTC](https://discourse.cmake.org/t/calling-cmake-default-find-module-from-a-user-defined-one/10723/1 "2024-04-23T11:47:06Z")

</div>

Hi,

Due to some peculiar setup, I need to add a bit of custom logic to the behavior of CMake provided Find.

The expected behavior for my projects would be: when calling `find_package(<Module> ...` it should call my version of Find which, in turn, according to some conditions, may call the CMake provided version of Find.

Besides, how can I make a `find_dependency` call in a configuration file to use the same logic?

I found [this proposal](https://stackoverflow.com/a/57185195) (not tested yet) and I was wondering if there could be another (“better”) solution.  
NB If I understand correctly the documentation, `find_dependency` may call `return()` thus getting back to the “caller” before resetting `CMAKE_MODULE_PATH `.

Regards,  
A.

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [June 12, 2024, 12:41pm UTC](https://discourse.cmake.org/t/calling-cmake-default-find-module-from-a-user-defined-one/10723/2 "2024-06-12T12:41:03Z")

</div>

Help still needed.

A special case is: A depends privately on B that depends privately on C that comes in 2 flavors: A cl compliant version and a gcc one (on the same machine).

In B `CMakeLists`, according to the compiler, I check different user environment variables to set `C_DIR` accordingly, `find_package` then find the desired C version. In A, I’ve got a linker error, because the `find_package(B)` loads B configuration file that does not embedded any special logic, it only does `find_dependency(C)` which may find a different, non-compliant, version of C.

My configuration file is automatically generated from a template that only lists the dependencies.

So my first idea has been the motivation for my question: I’m considering that, on some machine, `find_package` for a given library, must follow some logic. Yet it might not be a good approach as, how will it know, for instance, the compiler in use or other information required to chose the right version?

Another idea would be to be able to embed some special code in the template-generated configuration file. If it should be considered the right way to go, I may open a new question to this goal.

Regards,  
A.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [January 1, 2025, 9:16pm UTC](https://discourse.cmake.org/t/calling-cmake-default-find-module-from-a-user-defined-one/10723/3 "2025-01-01T21:16:58Z")

</div>

> [@adaldev](#):
>
> Another idea would be to be able to embed some special code in the template-generated configuration file. If it should be considered the right way to go, I may open a new question to this goal.

You might need to detect the target platform and report the `_FOUND` as `0` to reject itself. Note that this can’t be global because sometimes projects need host tools (e.g., Python interpreters), not just target things.
