CMake make files generation for imported SHARED lib is incorrect when crosscompiling DLL on Ubuntu
PROBLEM: CMake writes make file with -NOTFOUND values for a target while no error reported during configuration and generation.
CMake runs on Ubuntu 14.04 to generate make files for building Windows DLL. This DLL is dependent on 3rd party external library target being added as SHARED IMPORTED. CMake completes configuration and generation without successfully without any errors, finds this target and sets its properties correctly. However it writes target properties as -NOTFOUND: in build.make _EXTERNAL_OBJECTS list
./build/mingw64/myprjsrc/CMakeFiles/myshared.dir/build.make
myshared_EXTERNAL_OBJECTS =
myprjsrc/libmyshared.dll: myprjsrc/CMakeFiles/myshared.dir/build.make
myprjsrc/libmyshared.dll: qq-NOTFOUND
Despite that configuration-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 When SHARED attribute is replaced with STATIC, generation is done correctly allowing to make static library, but the issue is crosscompiling to SHARED .dll, & .dll.a
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 )
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})
Issue was initially submitted to cmake.org message: https://discourse.cmake.org/t/cmake-17-0-generates-target-notfound-for-configured-target/1642