cmake_tutorial/CMakeLists.txt
2025-07-03 17:29:32 +02:00

27 lines
1.5 KiB
CMake

# Specifies the minimum version of CMake required to configure the project.
cmake_minimum_required(VERSION 3.10)
# Defines the name of the project. This name is used for various CMake targets and variables.
project(cmake_tutorial C)
# 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.c)
# 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)