The output of my cmake is a static library. I'm creating it as such:
add_library(myMainLib STATIC ${BACKEND_SOURCES})
Problems arise when I try to get myMainLib to link against a third party lib/dll. The dll file will be found at run time, however, I'm trying to import/link against the lib file, with no success. My third party library is SDL2 and SDL2 NET.
I would think this is straight forward and have exhausted all methods I've found online. All fail. A list of what I've tried is below. Please inform me what I'm doing wrong.
Simple method, using target_link_libraries
add_library(myMainLib STATIC ${BACKEND_SOURCES}) target_link_libraries(myMainLib path_to_thirdPartyLib/thirdParty.lib)
According to cmake docs
add_library(myMainLib STATIC ${BACKEND_SOURCES}) add_library(Third_Party SHARED IMPORTED) set_property(TARGET Third_Party PROPERTY IMPORTED_LOCATION path_to_thirdPartyLib/thirdParty.dll) set_property(TARGET Third_Party PROPERTY IMPORTED_IMPLIB path_to_thirdPartyLib/thirdParty.lib) target_link_libraries(myMainLib Third_Party)
Set path to library using link directories
add_library(myMainLib STATIC ${BACKEND_SOURCES}) set(LIB_DIR path_to_thirdPartyLib) LINK_DIRECTORIES(${LIB_DIR}) target_link_libraries(myMainLib ${LIB_DIR}/thirdParty.lib)
Try finding the library
add_library(myMainLib STATIC ${BACKEND_SOURCES}) find_library(Third_Party thirdParty.lib) if(Third_Party) #never gets in here target_link_libraries(myMainLib ${Third_Party}) endif()