I have a vendor supplied library archive which I have imported into my project:
add_library(
lib_foo
STATIC
IMPORTED GLOBAL
)
set_target_properties(
lib_foo
PROPERTIES IMPORTED_LOCATION
"${CMAKE_CURRENT_LIST_DIR}/vendor/foo.a"
)
set_target_properties(
lib_foo
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${CMAKE_CURRENT_LIST_DIR}/vendor"
)
When I try to link an application using this library, I get undefined reference to 'pthread_atfork' linker errors:
/usr/lib/libtcmalloc_minimal.a(libtcmalloc_minimal_internal_la-static_vars.o):
In function `SetupAtForkLocksHandler':
/tmp/gperftools-2.4/src/static_vars.cc:119:
undefined reference to `pthread_atfork'
../vendor/foo.a(platformLib.o): In function `foo::Thread::Impl::join()':
So vendor/foo.a has a dependency on pthread.
I tried target_link_libraries(lib_foo pthread) but that doesn't work because lib_foo is an IMPORTED target, rather than a built target
CMake Error at libfoo/CMakeLists.txt:41 (target_link_libraries): Attempt to add link library "pthread" to target "lib_foo" which is not built in this directory.
Question:
How do I link pthread to lib_foo, or specify that targets with a dependency on lib_foo also have a dependency on pthread?