Visual Studio: Unnecessary compile dependencies w/ target_link_libraries
Hi - This is related to #15555 (closed) but with a different generator. We're using the VS2015 Generator, and have the exact same problem.
Using a slightly different CMakeLists.txt
file;
project(libDependencyTest C)
add_library ( a STATIC a.c )
target_include_directories(a PUBLIC "A")
target_compile_definitions(a PUBLIC A_DEFINE=1)
# b.c includes a file in "A", and uses A_DEFINE=1
add_library ( b STATIC b.c )
target_link_libraries ( b a )
add_executable ( e e.c )
target_link_libraries ( e b )
Generating for Visual Studio with cmake -H. -Bbuild -G"Visual Studio 14 2015 Win64"
and opening the solution tells me that:
e
depends on a
and b
b
depends on a
(which is unnecessary)
This is a problem for us for the same reason it was a problem in 15555 - our build time is getting very long, we have very parallel developer machines, but our builds appear to be practically serial.
I've tried implementing my own function add_soft_dependency
that looks like this
function(add_soft_dependency target)
foreach(arg ${ARGN})
target_link_libraries(${target} INTERFACE ${arg})
target_include_directories(${target} PUBLIC $<TARGET_PROPERTY:${arg},INCLUDE_DIRECTORIES>)
target_compile_definitions(${target} PUBLIC $<TARGET_PROPERTY:${arg},COMPILE_DEFINITIONS>)
endforeach()
endfunction()
and then using it for the dependency between b
and a
, but it's generating invalid VS projects for us (with non-ascii characters in it), which means it's unusable.
Verified with cmake 3.7 and with cmake 3.10