Search code examples
windowscmakecpack

How do I zip an exe and a bunch of dll files together with CPack?


My CMake-based project consists of an .exe file and three .dlls when compiled with Visual Studio. I want to distribute those files together in a zip: no source code included, no fancy NSIS installers, just the four files in a handy zip archive. I know I could script the operation directly in CMake with add_custom_command, but CPack seems a better option. How can I do it?


Solution

  • If you specify the files to be installed using CMake (with install), you can easily leverage CPack to create a zip archive:

    # Specify to install your CMake targets
    install(TARGETS MyExe RUNTIME CONFIGURATIONS Release)
    install(TARGETS MySharedLib1 RUNTIME CONFIGURATIONS Release)
    ...
    
    # Specify the CPack generator for packaging files into an archive.
    set(CPACK_GENERATOR "ZIP")
    # Specify to exclude the top-level directory from the archive.
    set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
    # Now, add CPack to your project.
    include(CPack)