Basics of CMake: CMakeLists.txt

# File name: CMakeLists.txt
# Set the minimum required CMake version to 3.15
cmake_minimum_required(VERSION 3.15)

# Set the project name to MyProject, version number to 1.0
project(MyProject VERSION 1.0)

# Set compilation options, set C++ standard to C++17
set(CMAKE_CXX_STANDARD 17)

# Force the compiler to support the specified C++ standard (C++17 in this case),
# if not supported, an error will be reported.
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Create an executable named my_app, with the source file main.cpp.
add_executable(my_app main.cpp)

# Include header file directories, add header search paths for the my_app target
# target_include_directories(my_app PRIVATE include)

# Installation rules (optional), install the executable my_app to the bin directory,
# the default installation path is ${CMAKE_INSTALL_PREFIX}/bin
# If CMAKE_INSTALL_PREFIX is not explicitly set, the system default value will be used, e.g., /usr/local
install(TARGETS my_app DESTINATION bin)

Basics of CMake: CMakeLists.txt

Leave a Comment