CPack: how to omit archive name from archived files' paths

project(foo VERSION 0.1.1)
install(
    TARGETS ${lib}
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION lib
    ARCHIVE DESTINATION lib)
set(CPACK_GENERATOR "ZIP")
include(CPack)

generates foo-0.1.1-Linux,zip, which contains

  • foo-0.1.1-Linux/lib/foo.dll
  • foo-0.1.1-Linux/lib/foo.lib

How to get rid of “foo-0.1.1-Linux/” in the archived files’ paths?

You can set CPACK_INCLUDE_TOPLEVEL_DIRECTORY to 0
this is a generic CPack variable used by all generators. Various generator may use different default value
when not specified though.

see: https://cmake.org/cmake/help/latest/variable/CPACK_INCLUDE_TOPLEVEL_DIRECTORY.html