Issue
I'm trying to add some more structure to my CMake project. One step of this process is to move source additions to the CMakeLists.txt
s in a few subdirectories, whereas they are currently added during target creation via add_library
. Unlike add_library
, however, target_sources
gives you the choice between PUBLIC
, INFERFACE
, and PRIVATE
. The sources added by add_library
obviously aren't interfaces, but I'm unsure if they are PUBLIC
or PRIVATE
.
Solution
CMake command add_library
interprets its immediate sources as PRIVATE
: the sources belongs only to the created target and aren't propagated to the target linked with the library.
In general, non-PRIVATE sources has a very limited usage. If two or more targets are linked together and share a source file, then linker usually reports "multiple definitions" error about symbols defined in that file.
Answered By - Tsyvarev