Generating an installer using CMake + CPack + Wix

Summary:

How to generate Wix installer with CMake/CPack?

Details:

I am trying to generate an installer out from a project that uses Wix, but apparently, cmake/cpack insist to use nsis, for example, from the repo https://github.com/ngladitz/cmake-wix-testsuite I picked the first example "basic" folder with the following contents for CMakeLists.txt

add_executable(hw hw.cpp)
install(TARGETS hw DESTINATION bin)

install(FILES hw.cpp DESTINATION src)

set(CPACK_WIX_UPGRADE_GUID "F9AAAAE2-D6AF-4EA4-BF46-B3E265400CC7")

include(CPack)

After generating the cmake:

cd <basic-root-folder>
mkdir MY_BUILD
cd MY_BUILD
cmake ..

I tried to run the package.vcxproj generated with

msbuild package.vcxproj

and got the error

"C:\src\Samples\CPack\cmake-wix-testsuite-master\basic\MY_BUILD\PACKAGE.vcxproj " (default target) (1) -> (PostBuildEvent target) -> EXEC : CPack error : Cannot find NSIS compiler makensis: likely it is not ins talled, or not in your PATH [C:\src\Samples\CPack\cmake-wix-testsuite-master\ba sic\MY_BUILD\PACKAGE.vcxproj]

So it looks like it insist in using the NSIS generator.

Upvotes: 6

Views: 11165

Answers (3)

Ok, I found how

By specifying the CPack generator like

cmake -DCPACK_GENERATOR=WIX ..

Then running

msbuild package.vcxproj 

Invokes wix like this extract from the log (and a bunch of .wixobj files)

PostBuildEvent:
  setlocal
  cd C:\src\Samples\CPack\cmake-wix-testsuite-master\basic\MY_BUILD.wix
  if %errorlevel% neq 0 goto :cmEnd
  C:
  if %errorlevel% neq 0 goto :cmEnd
  "C:\Program Files (x86)\CMake 3.1.3\bin\cpack.exe" -C Debug --config ./CPackC
  onfig.cmake
  if %errorlevel% neq 0 goto :cmEnd
  :cmEnd
  endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
  :cmErrorLevel
  exit /b %1
  :cmDone
  if %errorlevel% neq 0 goto :VCEnd
  :VCEnd
  CPack: Create package using WIX
  CPack: Install projects
  CPack: - Install project: Project
  CPack: Create package
  CPack: - package: C:/src/Samples/CPack/cmake-wix-testsuite-master/basic/MY_BU
  ILD.wix/Project-0.1.1-win32.msi generated.
FinalizeBuildStatus:
  Deleting file "Win32\Debug\PACKAGE\PACKAGE.tlog\unsuccessfulbuild".
  Touching "Win32\Debug\PACKAGE\PACKAGE.tlog\PACKAGE.lastbuildstate".
Done Building Project "C:\src\Samples\CPack\cmake-wix-testsuite-master\basic\MY
_BUILD.wix\PACKAGE.vcxproj" (default targets).


Build succeeded.
    0 Warning(s)
    0 Error(s)

Also the .wix source files are generated at C:\src\Samples\CPack\cmake-wix-testsuite-master\basic\MY_BUILD.wix\\_CPack_Packages\win32\WIX

I found out about this arg (CPACK_GENERATOR) by inspecting CPackConfig.cmake generated by the original cmake.

Upvotes: 3

TingQian LI
TingQian LI

Reputation: 680

Simply add following line before include(CPack)

set(CPACK_GENERATOR WIX)

Upvotes: 6

Andrey G.A
Andrey G.A

Reputation: 305

You can also do this:

cmake ..
cpack -G WIX

By default, CPack uses the NSIS Generator on Windows.

Upvotes: 5

Related Questions