Issue about PRIVATE in target_link_libraries

I create a static lib project called TCore and dependent many thirdparty lib project :

  • glslang
  • VulkanMemoryAllocator
  • SPIRV-Cross
project(TCore)

aux_source_directory(./src/ SRCS)

add_library(${PROJECT_NAME} STATIC ${SRCS})

add_subdirectory(./thirdparty)

target_include_directories(${PROJECT_NAME}
PUBLIC ./include
)

target_link_directories(${PROJECT_NAME} 
PRIVATE ./thirdparty/VulkanMemoryAllocator/src
PRIVATE ./thirdparty/glslang/glslang
PRIVATE ./thirdparty/glslang/glslang/OSDependent

PRIVATE ./thirdparty/glslang/hlsl
PRIVATE ./thirdparty/glslang/OGLCompilersDLL
PRIVATE ./thirdparty/glslang/SPIRV

PRIVATE ./thirdparty/SPIRV-Cross
)

target_link_libraries(${PROJECT_NAME}  
PRIVATE VulkanMemoryAllocator
PRIVATE glslang
PRIVATE OGLCompiler
PRIVATE OSDependent
PRIVATE SPIRV
PRIVATE spirv-cross-core
PRIVATE spirv-cross-glsl
PRIVATE spirv-cross-hlsl
)

And then I use this TCore lib to create executable app named PureHelloTriangle

project(TSample)

set(INCLUDE_PARTH 
PUBLIC ../engine/framegraph/include 
PUBLIC ../engine/core/include
PUBLIC ../thirdparty/glm/
PUBLIC ../thirdparty/tinygltf/
PUBLIC ../thirdparty/imgui/
PUBLIC ../thirdparty/imgui/backends/
PUBLIC ../thirdparty/KTX-Software/include/
)

set(LINK_PARTH 
PUBLIC /engine/framegraph/ 
PUBLIC /engine/core/
PUBLIC /thirdparty/glfw/src/
PUBLIC /thirdparty/KTX-Software/
)

set(LIBS 
TCore ###<<<-- this TCore lib
TFrameGraph
glfw
ktx
)

add_executable(PureHelloTriangle ./PureHelloTriangle.cpp)
target_include_directories(PureHelloTriangle PUBLIC ${INCLUDE_PARTH})
target_link_directories(PureHelloTriangle PUBLIC ${LINK_PARTH})
target_link_libraries(PureHelloTriangle PUBLIC ${LIBS})

then use CMake-GUI to create Visual Studio project:

the question is: I have use PRIVATE in target_link_libraries to create TCore lib. Normally when I use TCore in PureHelloTriangle just link TCore is enough, but in Visual Studio the PureHelloTriangle also link the dependent library of TCore. Why?

It’s how linking CMake targets works in general. This thread is very similar to your question:

private linking just means that cmake doesn’t propagate include paths and compiler flags

It doesn’t mean that linking to the library itself doesn’t propagate.