CMake : how to have CPack put all component files into a single directory?

44 views Asked by At

I'm making an NSIS installer for Windows. I want the DLLs to be in the same directory as the executable, so that Windows can find the DLLs.

Any clean solution ?

1

There are 1 answers

0
dpeng On

I solved the issue by first setting the destination folder for libraries to the destination folder for executables (see GNUInstallDirs) :

set(CMAKE_INSTALL_LIBDIR ${CMAKE_INSTALL_BINDIR})

An second, by setting the type to LIB in subsequent install() commands :

install(DIRECTORY ${COMPILER_PROGRAM_DIRECTORY}/
    TYPE LIB
    COMPONENT libraries
    FILES_MATCHING
        PATTERN "libgcc*.dll"
        PATTERN "libstdc++*.dll"
        PATTERN "libwinpthread*.dll"
    )

The LIB type tells CPack to copy the files to the library directory set earlier. With the combination of the two, the executable and the DLLs all end up in the same bin/ subdirectory.