30 lines
1.6 KiB
CMake
30 lines
1.6 KiB
CMake
# Specifies the minimum version of CMake required to configure the project.
|
|
cmake_minimum_required(VERSION 3.10)
|
|
|
|
set(SMAKE_CXX_STANDARD 20)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
# Defines the name of the project. This name is used for various CMake targets and variables.
|
|
project(cmake_tutorial C CXX)
|
|
|
|
# Configures CMake to generate a 'compile_commands.json' file in the build directory.
|
|
# This file is used by many IDEs and language servers (e.g., VS Code, CLion)
|
|
# to provide intelligent code features like autocompletion, go-to-definition, and static analysis.
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "Export compile commands for IDEs." FORCE)
|
|
|
|
# Includes the CMakeLists.txt files from the specified subdirectories.
|
|
# This makes the targets (libraries) defined in those subdirectories available in the current scope.
|
|
# The order is important: libraries must be defined before they are linked.
|
|
add_subdirectory(libs/lib1)
|
|
add_subdirectory(libs/lib2)
|
|
add_subdirectory(libs/lib3)
|
|
|
|
# Defines an executable target named 'cmake_tutorialApp' from the source file 'src/app.c'.
|
|
add_executable(cmake_tutorial src/app.cpp)
|
|
|
|
# Links the executable target 'cmake_tutorialApp' to the specified libraries.
|
|
# - PRIVATE: Indicates that 'cmake_tutorialApp' needs these libraries for its own compilation/linking,
|
|
# but targets that link to 'cmake_tutorialApp' do NOT need them.
|
|
# CMake automatically propagates the PUBLIC/INTERFACE include directories from lib1, lib2, and lib3
|
|
# to cmake_tutorialApp, so explicit target_include_directories is not needed here.
|
|
target_link_libraries(cmake_tutorial PRIVATE lib1 lib2 lib3)
|