CMake can't find IMPORTED library
As it mentioned above by Angew the visibility for imported library differs, though you can extend it using GLOBAL
modifier. It might be enough for you to modify add_library
call next way:
ADD_LIBRARY(avcodec-debug STATIC IMPORTED GLOBAL)
Imported targets do not follow the same visibility rules as non-imported targets. While non-imported targets are global (visible and accessible from anywhere after they're defined), imported targets are only visible in the CMakeLists.txt
where they are defined and below (in directories added by add_subdirectory()
in this defining CMakeList).
Since foo
is a sibling of bar
in your case, the target name avcodec-debug
is not visible inside bar/CMakeLists.txt
, so it's treated as a normal library name.
It's generally preferred to define imported targets in files you include rather than in their own projects. So change (or extract the relevant parts of) foo/CMakeLists.txt
into foo/avcodec.cmake
and then in the top-level CMakeList, replace
add_subdirectory(foo)
with
include(foo/avcodec.cmake)