What is the different between target_sources and target_include_directory when I add a header file to a target

I watched some videos about modern cmake.
for example
######################## 1
add_library(timer SHARED)
target_source(timer
PRIVATE src/timer.cpp
PUBLIC include/timer.h)
############################
############################2
add_library(timer SHARED)
target_source(timer
PRIVATE src/timer.cpp)
target_include_directory(timer PUBLIC include)
#############################
what is the different?
target_source with hearder file can emplace target_include ?

Public sources get added to consuming target’s source lists. I think what you want here is target_sources(FILE_SET) which also facilitates filling out the include usage interface.

Cc: @kyle.edwards

when I usr the first method to write my cmakelist ,
target_link_library(exe PUBLIC timer)

exe can’t find timer’s header file !!!

so I have to usr method 2 to write my cmakelists .

target_souce(FILESET) is useful in this stage ?

Getting a file added to a target’s source list does not mean that it can be included by any given name. One still needs include directory usage interfaces in order to make headers of a target work.