Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are CMake variables case-sensitive but commands are not?

Popular languages such as C, C++, python, ksh are always case-sensitive for both variables and functions. So, I'm surprised to learn that CMake treats that differently. What's the reason? Thank you.

like image 696
AcBap Avatar asked Dec 06 '25 20:12

AcBap


1 Answers

CMake variables are case-sensitive, as in other popular languages. However, the CMake commands are case-insensitive for historical reasons, and due to CMake's strict adherence to backwards-compatibility. A quote from CMake maintainer, Brad King:

Ancient CMake versions required upper-case commands. Later command names became case-insensitive. Now the preferred style is lower-case.

indicates that CMake commands used to be upper-case. However, the convention now is to use lower-case commands.

Many behaviors and conventions from older versions of CMake have been maintained (and aged-out) using CMake policies. The cmake_policy command gives developers control over whether the old or new behavior should be used. However, as far as I know, there is no policy dictating case-sensitivity for CMake commands.

like image 60
Kevin Avatar answered Dec 08 '25 21:12

Kevin