I have the following CMakeLists.txt:
cmake_minimum_required(VERSION 3.20.0 FATAL_ERROR)
project(link_test)
add_library(my_lib1 SHARED my_lib1.c)
add_library(my_lib2 SHARED my_lib2.c)
target_link_libraries(my_lib2 PRIVATE my_lib1)
From the CMake docs I understand that target_link_libraries
will create a dependency so that my_lib2
will be rebuilt if my_lib1.dll
changes:
A library target name: The generated link line will have the full path
to the linkable library file associated with the target. The
buildsystem will have a dependency to re-link if the library
file changes.
However, if I delete my_lib1.dll
and run cmake --build
, I only see my_lib1.dll
being built:
[1/2] Linking C shared library my_lib1.dll
Note the [1/2]
, as if there was a missing [2/2]
step there.
On the other hand, if I delete my_lib1.lib
(i.e. my_lib1
‘s import library), then I do see the expected outcome:
[1/2] Linking C shared library my_lib1.dll
[2/2] Linking C shared library my_lib2.dll
Am I misunderstanding something here? Is the idea that the re-building of my_lib2.dll
happens only when CMake detects that the symbols exported by my_lib1
may have changed (which would be reflected in my_lib1.lib
)? If so, what’s the deal with that lone [1/2]
?