# \[43998\] How to implement different CMake functions with the same name?

**URL:** https://discourse.cmake.org/t/43998-how-to-implement-different-cmake-functions-with-the-same-name/13349
**Category:** Code
**Created:** [January 8, 2025, 10:03am UTC](https://discourse.cmake.org/t/43998-how-to-implement-different-cmake-functions-with-the-same-name/13349 "2025-01-08T10:03:50Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [January 8, 2025, 10:13am UTC](https://discourse.cmake.org/t/43998-how-to-implement-different-cmake-functions-with-the-same-name/13349/2 "2025-01-08T10:13:42Z")

</div>

You can’t, CMake only has one scope for functions, and no overloading.

If you need a customisation point for a shared piece of CMake code (as in your case), you must make it a variable, not a function. For a simple case like your example, this could work:

- common.cmake:

```auto
set(MACRO_EXTENSION ${INJECTED_MACRO_EXTENSION}) # or just use INJECTED_MACRO_EXTENSION directly

```

- cpp/CMakeLists.txt:

```auto
set(INJECTED_MACRO_EXTENSION C)
include(common.cmake)

```

For something more complicated, you can inject the name of a command to call:

- common.cmake:

```auto
cmake_language(CALL ${INJECTED_COMMAND_NAME})

```

- cpp/CMakeListstxt

```auto
function(cpp_func)
  # whatever
endfunction()
set(INJECTED_COMMAND_NAME cpp_func)
include(common.cmake)

```

- python/CMakeListstxt

```auto
function(py_func)
  # whatever
endfunction()
set(INJECTED_COMMAND_NAME py_func)
include(common.cmake)

```

---

_[View the full topic](https://discourse.cmake.org/t/43998-how-to-implement-different-cmake-functions-with-the-same-name/13349)._
