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
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)
1条答案
按热度按时间eivnm1vs1#
这个问题现在已经有10多年的历史了,但对于Inno安装程序用户来说,这是一个好消息。Kitware最近发布了CMake 3.27,它现在包括一个用于Inno Setup的生成器。https://cmake.org/cmake/help/latest/cpack_gen/innosetup.html
我编辑了我的回答,包括一个例子,下面。
make.bat:
./source.CMakeLists.txt:
./hello/hello.cpp:
./hello/CMakeLists.txt
./installer/CMakeLists.txt
安装文件夹中的其他文件应该是不言自明的:图标,许可文本和配置文件,每个都有你自己的内容,你认为合适的。