2020-06-18 16:34:19 +00:00
include ( GNUInstallDirs )
2019-04-07 10:00:36 +00:00
# If requested, use FHS layout; otherwise fall back to a flat layout.
2020-09-25 11:55:25 +00:00
if ( OPTION_INSTALL_FHS )
2020-06-18 16:34:19 +00:00
set ( BINARY_DESTINATION_DIR "${CMAKE_INSTALL_BINDIR}" )
2020-06-11 19:57:14 +00:00
set ( DATA_DESTINATION_DIR "${CMAKE_INSTALL_DATADIR}/${BINARY_NAME}" )
2020-06-18 16:34:19 +00:00
set ( DOCS_DESTINATION_DIR "${CMAKE_INSTALL_DOCDIR}" )
set ( MAN_DESTINATION_DIR "${CMAKE_INSTALL_MANDIR}" )
2020-09-25 11:55:25 +00:00
else ( )
2020-12-12 15:29:09 +00:00
if ( APPLE )
set ( BINARY_DESTINATION_DIR "../MacOS" )
else ( )
set ( BINARY_DESTINATION_DIR "." )
endif ( )
2019-04-07 10:00:36 +00:00
set ( DATA_DESTINATION_DIR "." )
set ( DOCS_DESTINATION_DIR "." )
set ( MAN_DESTINATION_DIR "." )
2020-09-25 11:55:25 +00:00
endif ( )
2019-04-07 10:00:36 +00:00
install ( TARGETS openttd
R U N T I M E
D E S T I N A T I O N $ { B I N A R Y _ D E S T I N A T I O N _ D I R }
C O M P O N E N T R u n t i m e
)
install ( DIRECTORY
$ { C M A K E _ B I N A R Y _ D I R } / l a n g
$ { C M A K E _ B I N A R Y _ D I R } / b a s e s e t
2021-04-02 08:15:45 +00:00
$ { C M A K E _ B I N A R Y _ D I R } / a i
$ { C M A K E _ B I N A R Y _ D I R } / g a m e
2019-04-07 10:00:36 +00:00
$ { C M A K E _ S O U R C E _ D I R } / b i n / s c r i p t s
D E S T I N A T I O N $ { D A T A _ D E S T I N A T I O N _ D I R }
2021-04-20 16:46:15 +00:00
C O M P O N E N T l a n g u a g e _ f i l e s
R E G E X " a i / [ ^ \ . ] + $ " E X C L U D E # Ignore subdirs in ai dir
)
2019-04-07 10:00:36 +00:00
install ( FILES
$ { C M A K E _ S O U R C E _ D I R } / C O P Y I N G . m d
$ { C M A K E _ S O U R C E _ D I R } / R E A D M E . m d
2021-04-03 10:01:29 +00:00
$ { C M A K E _ S O U R C E _ D I R } / C R E D I T S . m d
$ { C M A K E _ S O U R C E _ D I R } / C O N T R I B U T I N G . m d
2019-04-07 10:00:36 +00:00
$ { C M A K E _ S O U R C E _ D I R } / c h a n g e l o g . t x t
$ { C M A K E _ S O U R C E _ D I R } / k n o w n - b u g s . t x t
D E S T I N A T I O N $ { D O C S _ D E S T I N A T I O N _ D I R }
C O M P O N E N T d o c s )
2021-04-03 10:01:29 +00:00
install ( FILES
$ { C M A K E _ S O U R C E _ D I R } / d o c s / a d m i n _ n e t w o r k . m d
$ { C M A K E _ S O U R C E _ D I R } / d o c s / d e b u g g i n g _ d e s y n c s . m d
$ { C M A K E _ S O U R C E _ D I R } / d o c s / d e s y n c . m d
$ { C M A K E _ S O U R C E _ D I R } / d o c s / d i r e c t o r y _ s t r u c t u r e . m d
2023-06-18 15:10:08 +00:00
$ { C M A K E _ S O U R C E _ D I R } / d o c s / e i n t s . m d
2021-04-03 10:01:29 +00:00
$ { C M A K E _ S O U R C E _ D I R } / d o c s / g a m e _ c o o r d i n a t o r . m d
$ { C M A K E _ S O U R C E _ D I R } / d o c s / l i n k g r a p h . m d
$ { C M A K E _ S O U R C E _ D I R } / d o c s / l o g g i n g _ a n d _ p e r f o r m a n c e _ m e t r i c s . m d
$ { C M A K E _ S O U R C E _ D I R } / d o c s / m u l t i p l a y e r . m d
$ { C M A K E _ S O U R C E _ D I R } / d o c s / s a v e g a m e _ f o r m a t . m d
2023-06-18 15:10:08 +00:00
$ { C M A K E _ S O U R C E _ D I R } / d o c s / s y m b o l _ s e r v e r . m d
2021-04-03 10:01:29 +00:00
$ { C M A K E _ S O U R C E _ D I R } / d o c s / o b g _ f o r m a t . t x t
$ { C M A K E _ S O U R C E _ D I R } / d o c s / o b m _ f o r m a t . t x t
$ { C M A K E _ S O U R C E _ D I R } / d o c s / o b s _ f o r m a t . t x t
D E S T I N A T I O N $ { D O C S _ D E S T I N A T I O N _ D I R } / d o c s
C O M P O N E N T d o c s )
2019-04-07 10:00:36 +00:00
# A Linux manual only makes sense when using FHS. Otherwise it is a very odd
# file with little context to what it is.
2020-09-25 11:55:25 +00:00
if ( OPTION_INSTALL_FHS )
2020-06-11 19:57:14 +00:00
set ( MAN_SOURCE_FILE ${ CMAKE_SOURCE_DIR } /docs/openttd.6 )
2020-06-11 19:57:14 +00:00
set ( MAN_BINARY_FILE ${ CMAKE_BINARY_DIR } /docs/ ${ BINARY_NAME } .6 )
2020-06-11 19:57:14 +00:00
install ( CODE
"
execute_process ( COMMAND ${ CMAKE_COMMAND } -E copy ${ MAN_SOURCE_FILE } ${ MAN_BINARY_FILE } )
2020-10-14 19:24:48 +00:00
execute_process ( COMMAND gzip -9 -n -f ${ MAN_BINARY_FILE } )
2020-06-11 19:57:14 +00:00
"
C O M P O N E N T m a n u a l )
2019-04-07 10:00:36 +00:00
install ( FILES
2020-06-11 19:57:14 +00:00
$ { M A N _ B I N A R Y _ F I L E } . g z
2020-06-18 16:34:19 +00:00
D E S T I N A T I O N $ { M A N _ D E S T I N A T I O N _ D I R } / m a n 6
2019-04-07 10:00:36 +00:00
C O M P O N E N T m a n u a l )
2020-09-25 11:55:25 +00:00
endif ( )
2019-04-07 10:00:36 +00:00
2021-03-09 17:00:37 +00:00
if ( UNIX AND NOT APPLE )
install ( DIRECTORY
$ { C M A K E _ B I N A R Y _ D I R } / m e d i a / i c o n s
$ { C M A K E _ B I N A R Y _ D I R } / m e d i a / p i x m a p s
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ D A T A R O O T D I R }
C O M P O N E N T m e d i a )
install ( FILES
$ { C M A K E _ B I N A R Y _ D I R } / m e d i a / $ { B I N A R Y _ N A M E } . d e s k t o p
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ D A T A R O O T D I R } / a p p l i c a t i o n s
C O M P O N E N T m e n u )
endif ( )
2019-04-07 10:00:36 +00:00
2020-09-25 11:55:25 +00:00
if ( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" )
2019-04-07 10:00:36 +00:00
set ( ARCHITECTURE "amd64" )
2020-09-25 11:55:25 +00:00
else ( )
2019-04-07 10:00:36 +00:00
string ( TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" ARCHITECTURE )
2020-09-25 11:55:25 +00:00
endif ( )
2019-04-07 10:00:36 +00:00
# Windows is a bit more annoying to detect; using the size of void pointer
# seems to be the most robust.
2020-09-25 11:55:25 +00:00
if ( WIN32 )
2021-01-16 21:31:20 +00:00
# Check if the MSVC platform has been defined
if ( "$ENV{Platform}" STREQUAL "arm64" )
set ( ARCHITECTURE "arm64" )
2020-09-25 11:55:25 +00:00
else ( )
2021-01-16 21:31:20 +00:00
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
set ( ARCHITECTURE "win64" )
else ( )
set ( ARCHITECTURE "win32" )
endif ( )
2020-09-25 11:55:25 +00:00
endif ( )
endif ( )
2020-12-12 15:29:32 +00:00
if ( APPLE AND CMAKE_OSX_ARCHITECTURES )
string ( TOLOWER "${CMAKE_OSX_ARCHITECTURES}" ARCHITECTURE )
endif ( )
2019-04-07 10:00:36 +00:00
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" )
2021-01-30 09:36:20 +00:00
if ( ( APPLE OR WIN32 ) AND EXISTS ${ PANDOC_EXECUTABLE } )
execute_process ( COMMAND ${ PANDOC_EXECUTABLE } "${CMAKE_SOURCE_DIR}/COPYING.md" -s -o "${CMAKE_BINARY_DIR}/COPYING.rtf" )
set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_BINARY_DIR}/COPYING.rtf" )
else ( )
set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/COPYING.md" )
endif ( )
2019-04-07 10:00:36 +00:00
set ( CPACK_RESOURCE_FILE_README "${CMAKE_SOURCE_DIR}/README.md" )
set ( CPACK_MONOLITHIC_INSTALL YES )
set ( CPACK_PACKAGE_EXECUTABLES "openttd;OpenTTD" )
2022-10-10 12:42:54 +00:00
set ( CPACK_STRIP_FILES YES )
2019-04-07 10:00:36 +00:00
set ( CPACK_OUTPUT_FILE_PREFIX "bundles" )
2020-09-25 11:55:25 +00:00
if ( APPLE )
2022-10-10 12:42:54 +00:00
# Stripping would produce unreadable stacktraces.
set ( CPACK_STRIP_FILES NO )
2020-06-08 23:20:43 +00:00
set ( CPACK_GENERATOR "Bundle" )
2019-04-07 10:00:36 +00:00
include ( PackageBundle )
2021-01-17 16:45:23 +00:00
if ( APPLE_UNIVERSAL_PACKAGE )
set ( CPACK_PACKAGE_FILE_NAME "openttd-#CPACK_PACKAGE_VERSION#-macos-universal" )
else ( )
set ( CPACK_PACKAGE_FILE_NAME "openttd-#CPACK_PACKAGE_VERSION#-macos-${CPACK_SYSTEM_NAME}" )
2022-04-19 00:11:42 +00:00
endif ( )
2020-09-25 11:55:25 +00:00
elseif ( WIN32 )
2020-06-07 02:34:50 +00:00
set ( CPACK_GENERATOR "ZIP" )
2020-09-25 11:55:25 +00:00
if ( OPTION_USE_NSIS )
2020-06-07 02:34:50 +00:00
list ( APPEND CPACK_GENERATOR "NSIS" )
include ( PackageNSIS )
2020-09-25 11:55:25 +00:00
endif ( )
2019-04-07 10:00:36 +00:00
set ( CPACK_PACKAGE_FILE_NAME "openttd-#CPACK_PACKAGE_VERSION#-windows-${CPACK_SYSTEM_NAME}" )
2021-05-24 22:03:04 +00:00
if ( WINDOWS_CERTIFICATE_COMMON_NAME )
add_custom_command ( TARGET openttd
P O S T _ B U I L D
C O M M A N D " $ { C M A K E _ S O U R C E _ D I R } / o s / w i n d o w s / s i g n . b a t " " $ < T A R G E T _ F I L E : o p e n t t d > " " $ { W I N D O W S _ C E R T I F I C A T E _ C O M M O N _ N A M E } "
)
endif ( )
2020-09-25 11:55:25 +00:00
elseif ( UNIX )
2019-04-07 10:00:36 +00:00
# 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.
2021-02-05 11:31:27 +00:00
if ( OPTION_PACKAGE_DEPENDENCIES )
2019-04-07 10:00:36 +00:00
set ( CPACK_GENERATOR "TXZ" )
2021-02-05 11:31:27 +00:00
set ( PLATFORM "generic" )
elseif ( NOT OPTION_INSTALL_FHS )
set ( CPACK_GENERATOR "TXZ" )
set ( PLATFORM "unknown" )
2020-12-21 20:32:29 +00:00
else ( )
find_program ( LSB_RELEASE_EXEC lsb_release )
execute_process ( COMMAND ${ LSB_RELEASE_EXEC } -is
O U T P U T _ V A R I A B L E L S B _ R E L E A S E _ I D
2020-12-12 15:30:02 +00:00
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
2021-01-02 17:45:42 +00:00
if ( LSB_RELEASE_ID )
if ( LSB_RELEASE_ID STREQUAL "Ubuntu" OR LSB_RELEASE_ID STREQUAL "Debian" )
execute_process ( COMMAND ${ LSB_RELEASE_EXEC } -cs
O U T P U T _ V A R I A B L E L S B _ R E L E A S E _ C O D E N A M E
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
string ( TOLOWER "${LSB_RELEASE_ID}-${LSB_RELEASE_CODENAME}" PLATFORM )
set ( CPACK_GENERATOR "DEB" )
include ( PackageDeb )
2023-02-01 07:41:41 +00:00
elseif ( LSB_RELEASE_ID STREQUAL "Fedora" )
set ( PLATFORM "fedora" )
set ( CPACK_GENERATOR "RPM" )
include ( PackageRPM )
2021-01-02 17:45:42 +00:00
else ( )
set ( UNSUPPORTED_PLATFORM_NAME "LSB-based Linux distribution '${LSB_RELEASE_ID}'" )
endif ( )
elseif ( EXISTS "/etc/os-release" )
file ( STRINGS "/etc/os-release" OS_RELEASE_CONTENTS REGEX "^ID=" )
string ( REGEX MATCH "ID=(.*)" _ ${ OS_RELEASE_CONTENTS } )
set ( DISTRO_ID ${ CMAKE_MATCH_1 } )
if ( DISTRO_ID STREQUAL "arch" )
2021-02-05 11:31:27 +00:00
set ( PLATFORM "arch" )
2021-01-02 17:45:42 +00:00
set ( CPACK_GENERATOR "TXZ" )
2022-04-19 00:11:42 +00:00
elseif ( DISTRO_ID STREQUAL "fedora" OR DISTRO_ID STREQUAL "rhel" )
set ( PLATFORM "fedora" )
set ( CPACK_GENERATOR "RPM" )
include ( PackageRPM )
2021-01-02 17:45:42 +00:00
else ( )
set ( UNSUPPORTED_PLATFORM_NAME "Linux distribution '${DISTRO_ID}' from /etc/os-release" )
endif ( )
2020-12-21 20:32:29 +00:00
else ( )
2021-01-02 17:45:42 +00:00
set ( UNSUPPORTED_PLATFORM_NAME "Linux distribution" )
endif ( )
2020-12-21 20:32:29 +00:00
2021-01-02 17:45:42 +00:00
if ( NOT PLATFORM )
set ( PLATFORM "generic" )
set ( CPACK_GENERATOR "TXZ" )
message ( WARNING "Unknown ${UNSUPPORTED_PLATFORM_NAME} found for packaging; can only pack to a txz. Please consider creating a Pull Request to add support for this distribution." )
2020-12-21 20:32:29 +00:00
endif ( )
2020-12-12 15:30:02 +00:00
endif ( )
2021-02-05 11:31:27 +00:00
set ( CPACK_PACKAGE_FILE_NAME "openttd-#CPACK_PACKAGE_VERSION#-linux-${PLATFORM}-${CPACK_SYSTEM_NAME}" )
2020-09-25 11:55:25 +00:00
else ( )
2019-04-07 10:00:36 +00:00
message ( FATAL_ERROR "Unknown OS found for packaging; please consider creating a Pull Request to add support for this OS." )
2020-09-25 11:55:25 +00:00
endif ( )
2019-04-07 10:00:36 +00:00
include ( CPack )
2021-02-05 11:31:27 +00:00
if ( OPTION_PACKAGE_DEPENDENCIES )
# Install all dependencies we can resolve, with the exception of ones that
# every Linux machine should have. This should make this build as generic
# as possible, where it runs on any machine with the same or newer libc
# than the one this is compiled with.
# We copy these libraries into lib/ folder, so they can be found on game
# startup. See comment in root CMakeLists.txt for how this works exactly.
install ( CODE [[
file ( GET_RUNTIME_DEPENDENCIES
R E S O L V E D _ D E P E N D E N C I E S _ V A R D E P E N D E N C I E S
U N R E S O L V E D _ D E P E N D E N C I E S _ V A R U N R E S O L V E D _ D E P E N D E N C I E S
E X E C U T A B L E S o p e n t t d
P O S T _ E X C L U D E _ R E G E X E S " l d - l i n u x | l i b c . s o | l i b d l . s o | l i b m . s o | l i b g c c _ s . s o | l i b p t h r e a d . s o | l i b r t . s o | l i b s t d c . . . s o " )
file ( INSTALL
D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ P R E F I X } / l i b "
F I L E S $ { D E P E N D E N C I E S }
F O L L O W _ S Y M L I N K _ C H A I N )
# This should not be possible, but error out when a dependency cannot
# be resolved.
list ( LENGTH UNRESOLVED_DEPENDENCIES UNRESOLVED_LENGTH )
if ( ${ UNRESOLVED_LENGTH } GREATER 0 )
message ( FATAL_ERROR "Unresolved dependencies: ${UNRESOLVED_DEPENDENCIES}" )
endif ( )
] ] )
endif ( )