Posts

Showing posts with the label CMake

Constructing C++ Projects via CMake

1. Installing CMake CMake Download 2. Building Source Code Files hello.cc #include <iostream> int main(void) { std::cout << "Hello World!" << std::endl; return 0; } 3. Building CMakeLists.txt File # Specify the minimum version of CMake cmake_minimum_required(VERSION 3.10) # Project name project(hello) # Source code files add_executable(hello hello.cpp) 4. Building Project In the above code, cmake_minimum_required specifies the minimum required version of CMake, while project specifies the name of the project. add_executable specifies the name of the generated executable file and the path of the source code files. 5. Running Project Open the terminal in the project folder and enter the following command to build: mkdir build # Create a "build" folder cd build # Enter "build" cmake .. # Generate Makefile make # Compile the source code and generate the executable file 6. Building Cross-Platform Project ...