When creating targets in CMake using the add_executable
or add_library
commands, do I need to explicitly specify header files in order to create the dependency tree for automatic build triggering, or does CMake handle this automatically?
For example, consider the following CMake configuration:
cmake_minimum_required(VERSION 3.10)
project(ExampleProject)
add_executable(ExampleApp main.cpp utils.cpp)
# Should I list the headers here too?
# target_sources(ExampleApp PRIVATE main.cpp utils.cpp utils.h)
In this example, main.cpp
includes utils.h
. If I modify utils.h
, will CMake automatically detect this change and trigger a rebuild of ExampleApp
, or do I need to specify utils.h
in the add_executable
command or another command to ensure the dependency is tracked?