Bruce Adams
Bruce Adams

Reputation: 5619

How do you run cpack from visual studio?

I am porting some packages from Linux to windows and I've found that visual studio has quite good integration with cmake. I am able to configure and build the project using cmake but I cannot figure out how to run cpack to create the installation package.

This question - How to create an installer with CMake + CPack + NSIS on Windows? - suggests that a PACKAGE.vcxproj file should be created by the build. It is but there doesn't appear to be anyway to build/run it from inside visual studio

It seems a strange oversight as:

Note I am trying to create ZIP or TGZ package and don't need the extra complication of NSIS at this time. I am using VS2019

Upvotes: 3

Views: 3058

Answers (1)

Bruce Adams
Bruce Adams

Reputation: 5619

The best solution I've come up with is you can't - at least not directly. Someone more enlightened may know better because it does indeed seem a strange oversight.

If you open a commmand prompt from tools/developer command prompt you can run cpack manually from there.

Another important point is that CPACK_PACKAGING_INSTALL_PREFIX should not be set on Windows. See https://gitlab.kitware.com/cmake/cmake/issues/17534

You can improve on this by adding a custom target (or targets) to your CMakeLists.txt which will be visible in the targets view. For example (base on https://cmake.org/pipermail/cmake/2017-January/064830.html) add:

SET( CPACK_OUTPUT_CONFIG_FILE "${CMAKE_BINARY_DIR}/BundleConfig.cmake" )
ADD_CUSTOM_TARGET( bundle
         COMMAND "${CMAKE_CPACK_COMMAND}"
                 "-C" "$<CONFIGURATION>"
            "--config" "${CMAKE_BINARY_DIR}/BundleConfig.cmake"
            COMMENT "Running CPack. Please wait..."
            DEPENDS ${PROJECT_NAME} doxygen)

Doxygen documentation to be included in the install package is an extra dependency in my case.

Upvotes: 3

Related Questions