Tools for upper/lower case consistency in CMake source

微笑、不失礼 提交于 2019-12-05 07:57:20

The answer by steveire links to the right resources, but let me explain explicitly in case those links vanish.

CMake command are case insensitive but lower case is recommended according to CMake developer Brad King in 2012:

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

The shell code that allowed to convert my project CMakeLists.txt file to lower case was inspired by the code behind the links of steveire's answer:

cmake --help-command-list \
    | while read c; do
        echo 's/\([^a-zA-Z_]\|^\)'"$c"'\(\s*\)(/\1'"$c"'\2(/gI'
    done > convert.sed
git ls-files -z -- '*CMakeLists.txt' | xargs -0 sed -i -f convert.sed

It has the following improvements:

  • grep -v "cmake version" is not required anymore because it seems that the --help-command-list output does not contain that anymore
  • the original regex contained a \b which made it not match any thing with GNU sed 4.2.2
  • instead, the cmake command must be preceded by a non-letter/underscore or the start of the line
  • instead of converting the cmake command to all upper case, make the regex case insensitive. This will also find and convert mixed-case occurrences like Find_Package.
  • there are no parts specific to the cmake codebase. Modify to fit yours. This simple construct was enough for mine.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!