Could you please advise what causes cmake to fail finding existing imported library target when generating build.make _EXTERNAL_OBJECTS list.
cmake generates file
./build/mingw64/myprjsrc/CMakeFiles/myshared.dir/build.make
with target shown as NOTFOUND:
myshared_EXTERNAL_OBJECTS =
myprjsrc/libmyshared.dll: myprjsrc/CMakeFiles/myshared.dir/build.make
myprjsrc/libmyshared.dll: **qq-NOTFOUND**
Despite that configuiration-generation was successful and target qq was configured - added, had valid target properties, target_link_libraries linked it successfully and had valid file location and type.
sample code snippet is below.
Note: this build is running on linux and uses mingw64 build chain to cross compile dll to run on Windows. The same cmake code is used for cross compiling to another linux and works fine with .so. However library property IMPORTED_LOCATION ${LIBQQ_LIBRARY} .dll.a or .a file, doesn’t fix the problem.
FindQQ.cmake
set(LIBQQ_LIBRARY "${LIBQQ_LIBRARY_DIRS}/lib${QQ_LIB_NAME}.dll" CACHE STRING "Link libraries ..." FORCE )
set(qqShared "qq" CACHE STRING "QQ target name")
# log confirms library target added at ${LIBQQ_LIBRARY} in ${LIBQQ_LIBRARY_DIRS}
if(NOT TARGET ${qqShared} )
add_library( ${qqShared} SHARED IMPORTED GLOBAL ) # <---- NOTE
set_target_properties( ${qqShared} PROPERTIES IMPORTED_LOCATION ${LIBQQ_LIBRARY} )
target_include_directories( ${qqShared}
INTERFACE
${LIBQQ_INCLUDE_DIRS}
)
message(STATUS "<<____ FindQQ cmake Added! Lib '${qqShared}' LIBQQ_LIBRARY '${LIBQQ_LIBRARY}' LIBQQ_LIBRARY_DIRS '${LIBQQ_LIBRARY_DIRS}' ")
else()
message(....has been already added ...)
endif()
#check shows target exists
if(TARGET ${qqShared})
..
CMakeLists.txt
#finds lib and adds target lib ${qqShared}
set(QQ_LIB_NAME qq CACHE STRING "QQ base library name" FORCE ) # used by FindQQ.cmake
find_package(QQ)
#check ${qqShared} target exists before and after target_link_libraries
if(TARGET ${qqShared}) ...
# link top lib myshared with extrernal dependencies
target_link_libraries(myshared
PUBLIC
${qqShared}
...
PRIVATE
...
)
#DEBUG log file check shows correct path ${LIBQQ_LIBRARY_DIRS}/lib${QQ_LIB_NAME}.dll :
get_target_property(include_path_defs ${qqShared} LOCATION )
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${qqShared}_target_prop_loc.txt ${include_path_defs})