8

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 Answers 3

9

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
2

The WiX capability was added in CMake 2.8.11

1
  • What Steve wants to say: Change you minimum required CMake version to at least 2.8.11 and make sure to have at least this version.
    – usr1234567
    Commented Oct 20, 2015 at 6:34
0

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
  • 1
    The WIX generator has been mainlined sometime during CMake development . When no CMAKE_GENERATOR is supplied a CPACK_BINARY_WIX is provided to enable it.
    – ceztko
    Commented Dec 29, 2022 at 8:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.