|
| 1 | +--- |
| 2 | +author: "Phong Nguyen" |
| 3 | +title: "CMake Guide" |
| 4 | +date: "2025-08-21" |
| 5 | +description: "CMake Learning." |
| 6 | +tags: ["cmake"] #tags search |
| 7 | +FAcategories: ["syntax"] #The category of the post, similar to tags but usually for broader classification. |
| 8 | +FAseries: ["Themes Guide"] #indicates that this post is part of a series of related posts |
| 9 | +aliases: ["migrate-from-jekyl"] #Alternative URLs or paths that can be used to access this post, useful for redirects from old posts or similar content. |
| 10 | +ShowToc: true # Determines whether to display the Table of Contents (TOC) for the post. |
| 11 | +TocOpen: true # Controls whether the TOC is expanded when the post is loaded. |
| 12 | +weight: 2 # The order in which the post appears in a list of posts. Lower numbers make the post appear earlier. |
| 13 | +--- |
| 14 | +## 1. Introduction |
| 15 | +- It's a meta-build system generator. |
| 16 | +- How it works: |
| 17 | + - We write high-level instructions in a CMakeLists.txt file (platform-agnostic).Then CMake generates build system files for the platform we choose: |
| 18 | + - On Linux/Unix → generates Makefile (for make) or build.ninja (for ninja). |
| 19 | + - On Windows → generates Visual Studio solutions (.sln). |
| 20 | + - On macOS → can generate Xcode projects. |
| 21 | + |
| 22 | +## 2. Setup |
| 23 | +- Linux: Install: `sudo apt install cmake` , Verify: `cmake --version` |
| 24 | + |
| 25 | +## 3. How to work with CMake |
| 26 | + |
| 27 | +1. Create CMakeLists.txt and resources file |
| 28 | +2. Run `cmake <dir-contain-CMakeLists.txt>` to set up & generate build system. |
| 29 | +3. Run `cmake --build <dir-contain-buildsystem>` to actually build/compile the project. |
| 30 | +4. Run the target build (e.g. `./targetName`) |
| 31 | + |
| 32 | + |
| 33 | +### 3.1. |
| 34 | +> CMakeLists.txt |
| 35 | +```makefile |
| 36 | +cmake_minimum_required(VERSION 3.0) // specifying a minimum CMake version |
| 37 | +project(CmakeprojectName) // set the project name |
| 38 | +add_executeable(targetName "headerfile.h" "sourcefile1.cpp" "sourcefile2.cpp") // specified source code files |
| 39 | +``` |
0 commit comments