summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2019-04-07 12:00:36 +0200
committerglx22 <glx22@users.noreply.github.com>2020-06-05 19:36:05 +0200
commitb7643b1d36cb41eb6712042761c13b9819fcbe74 (patch)
tree3bb422ed83832cf197692aef82f142a187a28af6 /cmake
parent56d54cf60eb5814f77dfcce91cf12879f01e1d1b (diff)
downloadopenttd-b7643b1d36cb41eb6712042761c13b9819fcbe74.tar.xz
Add: create bundles via CPack
CPack works closely together with CMake to do the right thing in terms of bundling (called 'package'). This generates all the packaging we need, and some more.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/InstallAndPackage.cmake109
-rw-r--r--cmake/PackageBundle.cmake24
-rw-r--r--cmake/PackageDeb.cmake4
-rw-r--r--cmake/PackageNSIS.cmake39
4 files changed, 176 insertions, 0 deletions
diff --git a/cmake/InstallAndPackage.cmake b/cmake/InstallAndPackage.cmake
new file mode 100644
index 000000000..d23fa92b7
--- /dev/null
+++ b/cmake/InstallAndPackage.cmake
@@ -0,0 +1,109 @@
+# If requested, use FHS layout; otherwise fall back to a flat layout.
+if (OPTION_INSTALL_FHS)
+ set(BINARY_DESTINATION_DIR "bin")
+ set(DATA_DESTINATION_DIR "share/games/openttd")
+ set(DOCS_DESTINATION_DIR "share/doc/openttd")
+ set(MAN_DESTINATION_DIR "share/man/openttd")
+else (OPTION_INSTALL_FHS)
+ set(BINARY_DESTINATION_DIR ".")
+ set(DATA_DESTINATION_DIR ".")
+ set(DOCS_DESTINATION_DIR ".")
+ set(MAN_DESTINATION_DIR ".")
+endif (OPTION_INSTALL_FHS)
+
+install(TARGETS openttd
+ RUNTIME
+ DESTINATION ${BINARY_DESTINATION_DIR}
+ COMPONENT Runtime
+ )
+
+install(DIRECTORY
+ ${CMAKE_BINARY_DIR}/lang
+ ${CMAKE_BINARY_DIR}/baseset
+ ${CMAKE_SOURCE_DIR}/bin/ai
+ ${CMAKE_SOURCE_DIR}/bin/game
+ ${CMAKE_SOURCE_DIR}/bin/scripts
+ DESTINATION ${DATA_DESTINATION_DIR}
+ COMPONENT language_files)
+
+install(FILES
+ ${CMAKE_SOURCE_DIR}/COPYING.md
+ ${CMAKE_SOURCE_DIR}/README.md
+ ${CMAKE_SOURCE_DIR}/changelog.txt
+ ${CMAKE_SOURCE_DIR}/docs/multiplayer.md
+ ${CMAKE_SOURCE_DIR}/known-bugs.txt
+ DESTINATION ${DOCS_DESTINATION_DIR}
+ COMPONENT docs)
+
+# A Linux manual only makes sense when using FHS. Otherwise it is a very odd
+# file with little context to what it is.
+if (OPTION_INSTALL_FHS)
+ install(FILES
+ ${CMAKE_SOURCE_DIR}/docs/openttd.6
+ DESTINATION ${MAN_DESTINATION_DIR}
+ COMPONENT manual)
+endif (OPTION_INSTALL_FHS)
+
+# TODO -- Media files
+# TODO -- Menu files
+
+if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ set(ARCHITECTURE "amd64")
+else (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+ string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" ARCHITECTURE)
+endif (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
+
+# Windows is a bit more annoying to detect; using the size of void pointer
+# seems to be the most robust.
+if (WIN32)
+ if (CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(ARCHITECTURE "win64")
+ else (CMAKE_SIZEOF_VOID_P EQUAL 8)
+ set(ARCHITECTURE "win32")
+ endif (CMAKE_SIZEOF_VOID_P EQUAL 8)
+endif (WIN32)
+
+set(CPACK_SYSTEM_NAME "${ARCHITECTURE}")
+
+set(CPACK_PACKAGE_NAME "openttd")
+set(CPACK_PACKAGE_VENDOR "OpenTTD")
+set(CPACK_PACKAGE_DESCRIPTION "OpenTTD")
+set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "OpenTTD")
+set(CPACK_PACKAGE_HOMEPAGE_URL "https://www.openttd.org/")
+set(CPACK_PACKAGE_CONTACT "OpenTTD <info@openttd.org>")
+set(CPACK_PACKAGE_INSTALL_DIRECTORY "OpenTTD")
+set(CPACK_PACKAGE_CHECKSUM "SHA256")
+set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING.md")
+set(CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md")
+set(CPACK_MONOLITHIC_INSTALL YES)
+set(CPACK_PACKAGE_EXECUTABLES "openttd;OpenTTD")
+set(CPACK_STRIP_FILES YES)
+set(CPACK_OUTPUT_FILE_PREFIX "bundles")
+
+if (APPLE)
+ set(CPACK_GENERATOR "Bundle")
+ include(PackageBundle)
+
+ set(CPACK_PACKAGE_FILE_NAME "openttd-#CPACK_PACKAGE_VERSION#-macosx")
+elseif (WIN32)
+ set(CPACK_GENERATOR "ZIP;NSIS")
+ include(PackageNSIS)
+
+ set(CPACK_PACKAGE_FILE_NAME "openttd-#CPACK_PACKAGE_VERSION#-windows-${CPACK_SYSTEM_NAME}")
+elseif (UNIX)
+ # With FHS, we can create deb/rpm/... Without it, they would be horribly broken
+ # and not work. The other way around is also true; with FHS they are not
+ # usable, and only flat formats work.
+ if (OPTION_INSTALL_FHS)
+ set(CPACK_GENERATOR "DEB")
+ include(PackageDeb)
+ else (OPTION_INSTALL_FHS)
+ set(CPACK_GENERATOR "TXZ")
+ endif (OPTION_INSTALL_FHS)
+
+ set(CPACK_PACKAGE_FILE_NAME "openttd-#CPACK_PACKAGE_VERSION#-linux-${CPACK_SYSTEM_NAME}")
+else ()
+ message(FATAL_ERROR "Unknown OS found for packaging; please consider creating a Pull Request to add support for this OS.")
+endif ()
+
+include(CPack)
diff --git a/cmake/PackageBundle.cmake b/cmake/PackageBundle.cmake
new file mode 100644
index 000000000..6d0085a32
--- /dev/null
+++ b/cmake/PackageBundle.cmake
@@ -0,0 +1,24 @@
+string(TIMESTAMP CURRENT_YEAR "%Y")
+
+set(CPACK_BUNDLE_NAME "OpenTTD")
+set(CPACK_BUNDLE_ICON "${CMAKE_SOURCE_DIR}/os/macosx/openttd.icns")
+set(CPACK_BUNDLE_PLIST "${CMAKE_CURRENT_BINARY_DIR}/Info.plist")
+set(CPACK_BUNDLE_STARTUP_COMMAND "${CMAKE_SOURCE_DIR}/os/macosx/launch.sh")
+set(CPACK_DMG_BACKGROUND_IMAGE "${CMAKE_SOURCE_DIR}/os/macosx/splash.png")
+
+# Create a temporary Info.plist.in, where we will fill in the version via
+# CPackProperties.cmake.in. This because at this point in time the version
+# is not yet known.
+configure_file("${CMAKE_SOURCE_DIR}/os/macosx/Info.plist.in" "${CMAKE_CURRENT_BINARY_DIR}/Info.plist.in")
+set(CPACK_BUNDLE_PLIST_SOURCE "${CMAKE_CURRENT_BINARY_DIR}/Info.plist.in")
+
+# Delay fixup_bundle() till the install step; this makes sure all executables
+# exists and it can do its job.
+install(
+ CODE
+ "
+ include(BundleUtilities)
+ fixup_bundle(\"\${CMAKE_INSTALL_PREFIX}/openttd\" \"\" \"\")
+ "
+ DESTINATION .
+ COMPONENT Runtime)
diff --git a/cmake/PackageDeb.cmake b/cmake/PackageDeb.cmake
new file mode 100644
index 000000000..0d635ebcb
--- /dev/null
+++ b/cmake/PackageDeb.cmake
@@ -0,0 +1,4 @@
+set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${ARCHITECTURE}")
+set(CPACK_DEBIAN_PACKAGE_SECTION "games")
+# TODO -- Fix depends
+set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.15)")
diff --git a/cmake/PackageNSIS.cmake b/cmake/PackageNSIS.cmake
new file mode 100644
index 000000000..1af38271f
--- /dev/null
+++ b/cmake/PackageNSIS.cmake
@@ -0,0 +1,39 @@
+set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL ON)
+set(CPACK_NSIS_HELP_LINK "${CPACK_PACKAGE_HOMEPAGE_URL}")
+set(CPACK_NSIS_URL_INFO_ABOUT "${CPACK_PACKAGE_HOMEPAGE_URL}")
+set(CPACK_NSIS_CONTACT "${CPACK_PACKAGE_CONTACT}")
+
+# NSIS uses this for the icon in the top left of the installer
+set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/os/windows\\\\nsis-top.bmp")
+
+# Set other icons and bitmaps for NSIS
+set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/os/windows\\\\openttd.ico")
+set(CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}/os/windows\\\\openttd.ico")
+set(CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP "${CMAKE_SOURCE_DIR}/os/windows\\\\nsis-welcome.bmp")
+set(CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP "${CMAKE_SOURCE_DIR}/os/windows\\\\nsis-welcome.bmp")
+
+# Use the icon of the application
+set(CPACK_NSIS_INSTALLED_ICON_NAME "openttd.exe")
+# Tell NSIS the binary will be in the root
+set(CPACK_NSIS_EXECUTABLES_DIRECTORY ".")
+
+# Add detail information on the NSIS installer executable. CPack doesn't
+# support this out of the box, so we use CPACK_NSIS_DEFINES for this.
+
+# \\\ are needed, because this value is generated in another CPack file,
+# which is used. So one \ is to escape here, the second to escape in the
+# CPack file, which we have to escape here (hence: 3 \).
+set(CPACK_NSIS_DEFINES "
+; Version Info
+Var AddWinPrePopulate
+VIProductVersion \\\"0.0.0.0\\\"
+VIAddVersionKey \\\"ProductName\\\" \\\"OpenTTD Installer for Windows\\\"
+VIAddVersionKey \\\"Comments\\\" \\\"Installs OpenTTD \\\${VERSION}\\\"
+VIAddVersionKey \\\"CompanyName\\\" \\\"OpenTTD Developers\\\"
+VIAddVersionKey \\\"FileDescription\\\" \\\"Installs OpenTTD \\\${VERSION}\\\"
+VIAddVersionKey \\\"ProductVersion\\\" \\\"\\\${VERSION}\\\"
+VIAddVersionKey \\\"InternalName\\\" \\\"InstOpenTTD\\\"
+VIAddVersionKey \\\"FileVersion\\\" \\\"0.0.0.0\\\"
+VIAddVersionKey \\\"LegalCopyright\\\" \\\" \\\"
+"
+)