# cmake-learning **Repository Path**: mmdjiji/cmake-learning ## Basic Information - **Project Name**: cmake-learning - **Description**: CMake Learning - **Primary Language**: Unknown - **License**: GPL-3.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-03-13 - **Last Updated**: 2021-05-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # CMake Learning GitHub: [mmdjiji/cmake-learning](https://github.com/mmdjiji/cmake-learning) ## Introduction After I learned [how to write makefile](https://github.com/mmdjiji/makefile-learning), I found that this was not enough to enable me to build all projects, such as [KDE](https://kde.org/), [OpenCV](https://opencv.org/) and so on. So I determined to learn [CMake](https://cmake.org/), an awesome building tool, which can be use on all platforms. You can download CMake by [this page](https://cmake.org/download/). ## Hello CMake Create a file named `CMakeLists.txt` and write as follows: ```cmake cmake_minimum_required (VERSION 2.8) project (hello) add_executable(hello hello.c) ``` Maybe you should finish `hello.c` with main function. Then, use `cmake .` to generate `Makefile`. After done, use `make` to build all the project. Then you can use `./hello` to run the program. ## Multi Source Build If you have two or more source files, you can use following: ```cmake cmake_minimum_required (VERSION 2.8) project (hello) add_executable (hello hello1.c hello2.c) ``` But this is trouble when you build a big project, not elegant enough. So use follows instead: ```cmake cmake_minimum_required (VERSION 2.8) project (fruits) aux_source_directory (. DIR_SRCS) add_executable (fruits ${DIR_SRCS}) ``` This used `aux_source_directory (