link two static libraries to a shared library

The structure of my project:


Root CmakeLists.txt adds imgui, imgui_glfw, and core as subdirectory:

add_executable(palka "main.cpp")
target_link_libraries(palka Core)

CMakeLists for the core directory links imgui and imgui_glfw:

add_library(Core SHARED ${CORE_SRC} ${HEADER_SOURCE})
target_link_libraries(Core PUBLIC IMGUI IMGUI_GLFW)

imgui CmakeLists:

file(GLOB IMGUI_SRC RELATIVE "${CMAKE_SOURCE_DIR}/palka_core/imgui" "*.cpp")
add_library(IMGUI STATIC ${IMGUI_SRC})
target_include_directories(IMGUI PUBLIC ".")

Imgui_glfw has almost the same CMakeLists:


find_package(glfw3 REQUIRED)
target_link_libraries(IMGUI_GLFW PRIVATE glfw IMGUI)
target_include_directories(IMGUI_GLFW PUBLIC ".")

The assembly of all the goals is successful, but the linking is .exe returns an error:

imgui/libIMGUI.a: in function `ImGui::TreePop(): multiple definition 
of `ImGui::TreePop() libPalkaCore.dll.a: first defined here

Apparently libIMGUI is linked not only for the Core target, but also for the palka target(the CMakeList list in the root directory). This can be avoided by specifying add_library Object instead of Static.
This will work if you specify Object not for all targets at once (imgui and imgui_glfw), but only for the imgui_glfw target, I don’t quite understand this either, yes imgui_glfw links to imgui, but I specify PRIVATE for target_link_libraries and there should be no problems with imgui also linking to the core target, but they occur (the error example above)
What am I doing wrong?

Did you mean for this to be Public? Your description suggests that this should have been Private.

There is a file in the Root that uses the Core library, if I make it PRIVATE, I will have to connect all the Core dependencies again. And this will not help, anyway, the multiple definition error for Core and IMGUI occurs during the build.
I don’t understand where it can appear at all when linking .exe, I connect the static libraries IMGUI and IMGUI_GLFW to Core 1 time, the Core - shared library and it is added as a target_link in the root directory, from where the conflict between Core and IMGUI is created, if IMGUI to .the exe is not linked 2 times for sure
In the root directory, all libraries are added via add_subdirectory, maybe this affects something. I tried changing the structure so that imgui and imgui_glfw lie inside the Core and are added to it via add_subdirectory, this solves the problem, but this project structure is not correct for me