[CMake] Are the current scoping rules for functions intended and documented?

Mario Werner mario.werner at iaik.tugraz.at
Wed Nov 16 08:32:46 EST 2016


Hi Brad,

unfortunately I failed to file an issue to keep track of this feature
request. Gitlab always recognizes the text as spam and discards it.

I tried the following title and text:

````````````````````````````````````````````````````````````
Title
-----
Function and macro definitions should obey the same scoping rules as
variables

Text
----
Hi all,

as Brad confirmed on the [mailing
list](https://www.mail-archive.com/cmake@cmake.org/msg55886.html),
functions and macros are currently scoped globally. This means that any
function definition in a sub scope (e.g., created via
`add_subdirectory`) can redefine functions for the parent. The fact that
CMake also always picks the last definition it encounters additionally
introduces the problem that the order in which CMakeLists are processed
can change the behaviour of the build system.

This feature request therefore propose that function and macro
definitions should obey the same  scoping rules as variables to mitigate
this potential pitfall.
````````````````````````````````````````````````````````````

Do you have any recommendations on how I can resolve this?

Cheers,
Mario




More information about the CMake mailing list