3

I'm porting some of our projects at work over to cmake/cpack, and while our current stuff is using Inno Setup, there does not appear to be a built-in CPack generator for Inno Setup. It seems to be either zip files or NSIS. Are there any CPack generators out there which use Inno Setup (and if so, where can I find them)? And if not, is there another way to use Inno Setup with cmake other than writing a script to do it and have cmake run that for its package target?

Jonathan M Davis
  • 37,181
  • 17
  • 72
  • 102
  • 1
    I'm not really familiar with cmake, but presumably it has a command to run an arbitrary console app. You can use that to run the command-line compiler `iscc`. – Miral Feb 12 '13 at 20:04
  • It's far more complicated than that. It has plugins for properly configuring and running the various packaging programs. If it were simply a matter of configuring Inno Setup myself and having cmake run it with a single command, that would be one thing, but it's cmake/cpack which does the configuration. It's all encapsulated. So, what I really need is a CPack generator plugin for Inno Setup. Also, if I have that, I don't even have to know much about configuring Inno Setup, since it does it for me, whereas if all cmake did was run it, I'd have to configure it, which I don't know how to do yet. – Jonathan M Davis Feb 12 '13 at 20:11
  • I very much doubt that you're going to find some sort of "magic bullet" to write install scripts for you, if that's what you're talking about. I did find [some talk of getting cmake to run custom programs](http://stackoverflow.com/questions/2354473/cmake-add-custom-command/), which may help you build an existing script, but someone (presumably you) will have to write that script. – Miral Feb 13 '13 at 03:44
  • Or, if you prefer, to write a script generator -- but I've personally never liked the idea of autogenerated install scripts. Remember, installers typically get run with super-user permissions on someone else's PC. You want to be **very** sure what it is actually doing at all times. – Miral Feb 13 '13 at 03:45
  • 1
    With cmake, you give it install commands, which tell it where to install the files, and cpack uses those with whatever generator you tell it to use to generate an actual installer. So, you tell it where to put stuff, but for the most part, you don't have to care about how the specific packager/installer works or how it's configured. So, for instance, you can generate an RPM on Linux and an NSIS installer on Windows with almost exactly the same commands in cmake. My problem is that I need an Inno Setup installer, and cmake comes with a generator for NSIS but not Inno Setup. – Jonathan M Davis Feb 13 '13 at 03:48
  • Ok. I think then your choices are fairly simple: either convince someone on the cmake/cpack team to write an Inno generator for you, write one yourself, or just make a script manually. – Miral Feb 13 '13 at 11:27
  • @Miral Probably, but someone might have already written one that's being used for a project out there somewhere, and I just haven't been able to find it. – Jonathan M Davis Feb 13 '13 at 16:36

1 Answers1

0

The question is now over 10 years old, but there's great news for Inno setup users. Kitware recently released CMake 3.27, which now includes a generator for Inno Setup. https://cmake.org/cmake/help/latest/cpack_gen/innosetup.html

I edited my answer to include an example, below.

[MyProject]
 |- Make.bat
 |- [source]
     |- CMakeLists.txt
     |- [hello]
     |    |- hello.cpp
     |    |- CMakeLists.txt
     |- [installer] 
          |- CMakeLists.txt
          |- config.xml
          |- Copyright.txt
          |- InstallerIcon.ico
          |- InstallerIcon.bmp
          |- UninstallIco.ico

make.bat:

md build
cd build
del *.* /S /Q
cmake -G "Visual Studio 17 2022" . "../source" -A x64

rem Firing up Build......................
cmake --build . --config Release
cd..

rem Run CPack
cpack --config build/CPackConfig.cmake

./source.CMakeLists.txt:

cmake_minimum_required(VERSION 3.27)

project(HelloWorld)

add_subdirectory(Hello)
add_subdirectory(Installer)

./hello/hello.cpp:

#include <iostream>

int main ()
{
    std::cout << "hello world";
}

./hello/CMakeLists.txt

cmake_minimum_required(VERSION 3.27)
project(Hello)
add_executable(Hello hello.cpp)

./installer/CMakeLists.txt

cmake_minimum_required(VERSION 3.27)

# We tell CMake which files to add the program and the C++ runtime  
install(TARGETS Hello DESTINATION .) # Dot means we install directly in target folder, not a subfolder
set (CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP TRUE) # override default path of Microsoft libraries
include (InstallRequiredSystemLibraries)  # Install Microsoft runtime libraries    
install (PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION .)  # Override default folder for system libraries.
# Add other files too: installing a config file (just as example, real application will rather use %ProgramData% )
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/Config.xml" DESTINATION .) # Dot sets directly in target folder.  

# Generic CPack settings
set(CPACK_PACKAGE_NAME Hello)               
set(CPACK_PACKAGE_VENDOR "My Name")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Hello World Program")
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})  # Name of subfolder under 'Program Files'
set(CPACK_PACKAGE_VERSION_MAJOR    ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR    ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH    ${PROJECT_VERSION_PATCH})
set(CPACK_VERBATIM_VARIABLES       TRUE)         # Ensure correct escaping - always set to true

#Set resources used by the Windows installer
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright.txt") # Location of license file
set(CPACK_PACKAGE_ICON "${CMAKE_CURRENT_SOURCE_DIR}/InstallIcon.bmp") # Logo in installer window

#Start Menu Shortcuts: executable without .exe and text label
set(CPACK_PACKAGE_EXECUTABLES "Hello" "Hello World") 
set(CPACK_CREATE_DESKTOP_LINKS "Hello") # Desktop link
 
# Define which generator to use
if (WIN32)
    # Inno Setup is supported from CMake 3.27. 
    set(CPACK_GENERATOR  INNOSETUP)   
    set(CPACK_INNOSETUP_SETUP_UninstallDisplayIcon "${CMAKE_CURRENT_SOURCE_DIR}/UninstallIco.ico") 
    set(CPACK_INNOSETUP_SETUP_SetupIconFile "${CMAKE_CURRENT_SOURCE_DIR}/InstallerIcon.ico")
       
    #Executable that user can run at end of install. It refers CPACK_PACKAGE_EXECUTABLES above.
    set ( CPACK_INNOSETUP_RUN_EXECUTABLES "Hello") 
    
    # OPTIONAL: Set up custom script for Inno Setup. Your Pascal functions to add in [code] block  
    # set (CPACK_INNOSETUP_CODE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/codefile.iss")  
else()
    set(CPACK_GENERATOR  STGZ )
endif()

# This must always be after all CPACK\_\* variables are defined
include(CPack)  

The other files in the install folder should be self-evident: icons, license text and a config file, each with your own content as you see fit.

CppDev
  • 49
  • 5