How to generate .msi installer with cmake?

12.1k views Asked by At

I am trying to generate .msi installer with cmake. I am able to generate .dll and .lib files with some configuration in CMakeLists.txt. Please provide an example CMakeLists.txt to generate an .msi installer. What are the commands that I need to use in the command prompt ?

The commands that I am using so far are:

> cmake -G"Visual Studio 10" -H"Root CMakeLists.txt path" -B"path to generate the sln"
> cmake --build "path of the sln" --config Release
> cpack -C Release
output: CPack Error: CPack generator not specified 

I used the following configuration to generate the .dll and .lib files.

Here is my CMakeLists.txt:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
PROJECT(mydll)
INCLUDE_DIRECTORIES(common/include) 
SET(my_lib_src dllmain.cpp mydll.cpp )
SET_SOURCE_FILES_PROPERTIES(${my_lib_src} PROPERTIES LANGUAGE C)
ADD_LIBRARY(mydll  SHARED ${my_lib_src})
SET_TARGET_PROPERTIES(mydll PROPERTIES 
LINKER_LANGUAGE C
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/common/bin                      
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/common/bin
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/common/lib
ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/common/lib)
install(TARGETS mydll 
  ARCHIVE
  DESTINATION lib
  COMPONENT libraries)
install(FILES mydll.h
  DESTINATION include
  COMPONENT headers)
set(CPACK_GENERATOR WIX)
set(CPACK_PACKAGE_NAME "mydll")
set(CPACK_PACKAGE_VENDOR "CMake.org")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "MyLib - CPack Component Installation Example")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_VERSION_MAJOR "1")
set(CPACK_PACKAGE_VERSION_MINOR "0")
set(CPACK_PACKAGE_VERSION_PATCH "0")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "CPack Component Example")

INCLUDE(CPack)
3

There are 3 answers

0
drescherjm On

You need to set the generator when you run cpack so instead of

3) cpack -C Release
output: CPack Error: CPack generator not specified

You should specify

cpack -G WIX -C Release
1
JonnyRo On

It appears that MSI is not in the list of CPack Generators, although there are patches to CPack that enable this functionality.

See: http://annealingtechnologies.blogspot.com/2010/02/wix-and-cpack-integration.html

1
Steve Huston On

The WiX capability was added in CMake 2.8.11