Reputation: 155
I'm trying to use CMAKE_LINK_DEPENDS_NO_SHARED (discussion) on my project in visual studio. From my understanding I'd expect this option to cause cmake not to link against a shared libraries dependencies. I haven't found anything useful on google or here on that matter.
I've created a minimal example on github for this containing:
2 depends on 1. 3 depends on 2. But there shouldn't be a direct dependency from 3 to 1, because 2 is a shared library. The executable should only need to relink, when the interfacing headers of 2 change. Despite the cmake option stated above (CMAKE_LINK_DEPENDS_NO_SHARED) set in my projet setup the generated visual studio solution shows a dependency between the executable and the static library (lib_dep.lib in the following screenshot).
All files are available in the repository but here is the cmake file for quick access:
cmake_minimum_required(VERSION 2.8.11)
# This should do it, shouldn't it?
set(CMAKE_LINK_DEPENDS_NO_SHARED 1)
Project(Example)
# dependency of the shared library:
file (GLOB libdep "library_dep/*.cpp" "library_dep/*.h")
include_directories(library_dep)
add_library(lib_dep ${libdep})
# shared library:
file (GLOB libsrc "library_src/*.cpp" "library_src/*.h")
include_directories(library_src)
add_library(example_lib SHARED ${libsrc})
target_link_libraries(example_lib lib_dep)
set_target_properties(example_lib PROPERTIES LINK_FLAGS ${LINK_FLAGS} "/export:f")
# executable:
file (GLOB exesrc "executable_src/*.cpp")
add_executable(example ${exesrc})
target_link_libraries(example example_lib)
Can anyone point me to what I'm doing wrong? I'm using Visual Studio 2010 by the way.
Upvotes: 1
Views: 665
Reputation: 155
After a while I stumbled accross the Answer to my Question:
In CMAKE Help additional keywords are listed: PUBLIC, PRIVATE and INTERFACE. With those I can change the behavior described above to the one I wanted.
Building the shared library with target_link_libraries(example_lib PRIVATE lib_dep) causes the executable not to be linked against the static library again.
Upvotes: 1