3

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:

  • cmake integration is very good
  • ctest tests can be run via the tests menu
  • the install target can be run via the build menu but there is no menu option to create packages with cpack.

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

Bruce Adams
  • 4,953
  • 4
  • 48
  • 111
  • Does the `PACKAGE` project not show up in your Solution Explorer menu? It is often grouped with the other CMake predefined targets (e.g. `INSTALL`, `ZERO_CHECK`, etc.) – Kevin Jan 08 '20 at 14:30
  • There are no predefined targets at all in Solution Explorer. Perhaps I need to configure something? – Bruce Adams Jan 08 '20 at 14:40
  • Just tried adding the following based on your clue - no effect: set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake") – Bruce Adams Jan 08 '20 at 14:52
  • Are you using VS folders? (`set_property(GLOBAL PROPERTY USE_FOLDERS ON)`) It is possible that the predefined targets are in a collapsed folder. Without knowing the *specifics* of how you generated the solution file, it is difficult to say why these pre-defined CMake projects are not showing in your Solution Explorer. There is even a [question](https://stackoverflow.com/questions/49069493/is-it-possible-not-to-generate-all-build-project-in-cmake) for how to get rid of them, because they are almost **always** available. – Kevin Jan 08 '20 at 14:52
  • I'm letting cmake generate the solution file. – Bruce Adams Jan 08 '20 at 15:22

1 Answers1

3

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.

Bruce Adams
  • 4,953
  • 4
  • 48
  • 111
  • Accepting my own answer until/unless someone comes up with a better one. – Bruce Adams Jan 22 '20 at 12:40
  • This may not be helpful at this point, but the linked question uses the "old" way of using cmake with windows: run cmake to create visual studio solution file, then open that file in visual studio. From your references to cmake integration, I assume you use the new cmake integration with "open folder", which does not create solution or project(.vcxproj) files for visual studio (per default, it uses Ninja as a build-system instead of msbuild). So if you generate the solution the traditional way, you should still get the PACKAGE.vcxproj – tillh Apr 08 '20 at 05:46
  • Its helpful to know that there even was an old and a new way. – Bruce Adams Apr 13 '20 at 20:20