Writing your first very own CMake module
In the previous section, we learned about how to use functions and macros to provide useful utility in CMake projects, Now, we can learn about how we can move these functions and macros to a separate CMake module.
Creating and using a simple CMake module file is extremely simple:
- Create a
<module_name>.cmake
file under your project. - Define any macros/functions in the
<module_name>.cmake
file. - Include
<module_name>.cmake
in the desired file.
Alright, let's follow these steps and create a module together. As a follow-up to our previous git
branch name example, let's extend the scope and write a CMake module that provides the ability to retrieve the branch name, head commit hash, current author name, and current author email information by using the git
command. For this part, we will follow the chapter_13/ex01_git_utility
example. The example folder contains a CMakeLists.txt
file and a git...