CMake - install 3rd party dll dependency

I am using a precompiled third party library that has several DLLs (one for the actual third party and some more of its own dependencies) My directory structure is as follows

MyApp
    CMakeLists.txt // Root CMake file
    src
        MyCode.cpp
    thirdpartydep // Precompiled thirdparty dependency
        FindThirdPartyDep.cmake
        bin/
            thirdparty.dll
            thirdparty_dep1.dll
            thirdparty_dep2.dll
        include/
            thirdparty.h
        lib/
            thirdparty.lib // this is the importlibrary that loads thirdparty.dll

      

So far, we have copied all the DLLs in the directory thirdpartydep/bin

with copy_if_different

and manually enumerated the paths to the DLLs. I am trying to set up the target correctly install

to copy the dll in thirdpartydep/bin

to CMAKE_INSTALL_PREFIX/bin

, but I cannot figure out how to tell cmake about the additional binaries owned by thirdpartydep.

+3


source to share


1 answer


If instead of MODULES (Find * .cmake) you are using modern CMake with properly compiled 3rd party CONFIG packages (* -config.cmake), then this will work:

MACRO(INSTALL_ADD_IMPORTED_DLLS target_list target_component destination_folder)
  foreach(one_trg ${target_list})
    get_target_property(one_trg_type ${one_trg} TYPE)
    if (NOT one_trg_type STREQUAL "INTERFACE_LIBRARY")
       get_target_property(one_trg_dll_location ${one_trg} IMPORTED_LOCATION_RELEASE)
       if( one_trg_dll_location MATCHES ".dll$")
          install(FILES ${one_trg_dll_location} DESTINATION ${destination_folder} CONFIGURATIONS Release COMPONENT ${target_component})
       endif()
       get_target_property(one_trg_dll_location ${one_trg} IMPORTED_LOCATION_DEBUG)
       if( one_trg_dll_location MATCHES ".dll$")
          install(FILES ${one_trg_dll_location} DESTINATION ${destination_folder} CONFIGURATIONS Debug COMPONENT ${target_component})
       endif()
    endif()
  endforeach()
ENDMACRO()

      



it is used like this:

set(THIRDPARTY_TARGETS "example_target1 example_target2 opencv_core")
INSTALL_ADD_IMPORTED_DLLS("${THIRDPARTY_TARGETS}" bin bin)

      

0


source







All Articles