maccard
maccard

Reputation: 1258

CMake - install third party dll dependency

I'm using a pre-compiled third party library that has multiple DLLs (one for the actual third party, and some more as 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

Until now, we've been copying over all the DLLs in the thirdpartydep/bin directory using copy_if_different and manually listing the paths to the DLLs. I'm trying to set up the install target correctly to copy the dlls in thirdpartydep/bin to CMAKE_INSTALL_PREFIX/bin but I can't figure out how to tell cmake about the extra binary files belonging to thirdpartydep.

Upvotes: 7

Views: 4912

Answers (2)

Matthieu H
Matthieu H

Reputation: 717

You can simply use the install() command like that:

install(FILES ${DLL_PATH} DESTINATION ${CMAKE_INSTALL_PREFIX}/dll 
                          CONFIGURATIONS Release COMPONENT ${LIBRARY_NAME})

Upvotes: -1

Oliver Zendel
Oliver Zendel

Reputation: 2901

If you use modern CMake with correctly build CONFIG thirdparty packages (* -config.cmake) instead of MODULES (Find*.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")
if(MSVC)
    INSTALL_ADD_IMPORTED_DLLS("${THIRDPARTY_TARGETS}" bin bin)
endif()

Upvotes: 3

Related Questions