CMakeListstxt
CMakeLists.txt is the primary input file used by the CMake build system. It is a plain text file that contains a sequence of CMake commands describing a project’s build configuration. The file is usually located at the root of a source tree and is read by CMake to generate platform-specific build files such as Makefiles or Ninja build files. CMakeLists.txt supports multiple languages, dependencies, and targets, and is designed to be portable across Windows, macOS, and Linux.
A typical project begins with cmake_minimum_required and project commands, followed by definitions of targets created with
A minimal example might look like:
cmake_minimum_required(VERSION 3.14)
add_executable(myapp src/main.cpp)
target_include_directories(myapp PRIVATE include)
target_link_libraries(myapp PRIVATE someLib)
Beyond basic targets, CMakeLists.txt can perform conditional logic with if, foreach, and find_package, manage dependencies with
Usage generally involves creating a separate build directory, running cmake pointing at the source tree, and