Compiling source files
// main.cpp
#include <iostream>
int main() {
std::cout << "Hello, CMake!" << std::endl;
return 0;
}
// CMakeLists.txt
cmake_minimum_required(VERSION 3.10) #CMake version
project(MyProject) #project-name
add_executable(MyExecutable main.cpp) #(exe_name generate_from_main.cpp)
$ mkdir build
$ cd build
build$ cmake ..
build$ ls
cmake_install.cmake Makefile CMakeFiles CMakeCache.txt
build$ make
[ 50%] Building CXX object CMakeFiles/MyExecutable.dir/main.cpp.o
[100%] Linking CXX executable MyExecutable
[100%] Built target MyExecutable
build$ ls
CMakeCache.txt CMakeFiles Makefile MyExecutable cmake_install.cmake
$ ./MyExecutable
Files Generated
- Once (cmake ..) is run following files are generated
|
1. cmake_install.cmake: instructions for installing built targets to their final locations when we run 'make install' or cmake --install |
|
|
2.
Makefile: The actual build script generated for your chosen platform |
|
|
3. CMakeFiles directory:
Contains metadata, intermediate files and auxiliary scripts needed for the build system to operate. |
|
|
4.CMakeCache.txt Persistent Cache and stores key-value pairs for internal and user-defined variables such as compiler paths, options, and feature flags |
|