Refactor macOS CMakeLists for .app bundle as default

This commit is contained in:
adam-bloom 2021-03-21 16:38:31 -06:00
parent 2b37f4586a
commit 753ac907f8

View file

@ -61,8 +61,9 @@ option(DOWNLOAD_TITLE_SEQUENCES "Download title sequences during installation."
option(DOWNLOAD_OBJECTS "Download objects during installation." ON) option(DOWNLOAD_OBJECTS "Download objects during installation." ON)
CMAKE_DEPENDENT_OPTION(DOWNLOAD_REPLAYS "Download replays during installation." ON CMAKE_DEPENDENT_OPTION(DOWNLOAD_REPLAYS "Download replays during installation." ON
"WITH_TESTS" OFF) "WITH_TESTS" OFF)
option(MACOS_USE_DEPENDENCIES "Use OpenRCT2 dependencies instead of system libraries" ON) CMAKE_DEPENDENT_OPTION(MACOS_USE_DEPENDENCIES "Use OpenRCT2 dependencies instead of system libraries" ON
CMAKE_DEPENDENT_OPTION(MACOS_BUNDLE "Build macOS application bundle (OpenRCT2.app)" OFF "APPLE" OFF)
CMAKE_DEPENDENT_OPTION(MACOS_BUNDLE "Build macOS application bundle (OpenRCT2.app)" ON
"MACOS_USE_DEPENDENCIES; NOT DISABLE_GUI" OFF) "MACOS_USE_DEPENDENCIES; NOT DISABLE_GUI" OFF)
# Options # Options
@ -104,9 +105,8 @@ if (APPIMAGE)
set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib") set(CMAKE_INSTALL_RPATH "$ORIGIN/../lib")
endif () endif ()
if (APPLE AND MACOS_USE_DEPENDENCIES) if (MACOS_USE_DEPENDENCIES)
# if we're building on macOS, then we need the dependencies # if we're building on macOS, then we need the dependencies
# update dylibs
include(cmake/download.cmake) include(cmake/download.cmake)
set(MACOS_DYLIBS_VERSION "28") set(MACOS_DYLIBS_VERSION "28")
@ -125,17 +125,21 @@ if (APPLE AND MACOS_USE_DEPENDENCIES)
set(CMAKE_MACOSX_RPATH 1) set(CMAKE_MACOSX_RPATH 1)
list(APPEND CMAKE_PREFIX_PATH "${MACOS_DYLIBS_DIR}") list(APPEND CMAKE_PREFIX_PATH "${MACOS_DYLIBS_DIR}")
# the RPATH to be used when installing, but only if it's not a system directory # if we're making the OpenRCT2.app bundle, rpath will be handled by fixup_bundle
list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir) # if we're building the CLI executable, we need to do it ourselves
if("${isSystemDir}" STREQUAL "-1") if (NOT MACOS_BUNDLE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") # the RPATH to be used when installing, but only if it's not a system directory
endif("${isSystemDir}" STREQUAL "-1") list(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
if("${isSystemDir}" STREQUAL "-1")
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
endif("${isSystemDir}" STREQUAL "-1")
# if the DESTDIR env var is defined, use it in the install RPATH # if the DESTDIR env var is defined, use it in the install RPATH
if(DEFINED ENV{DESTDIR}) if(DEFINED ENV{DESTDIR})
get_filename_component(destdirRealPath "$ENV{DESTDIR}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") get_filename_component(destdirRealPath "$ENV{DESTDIR}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
set(CMAKE_INSTALL_RPATH "${destdirRealPath}${CMAKE_INSTALL_PREFIX}/lib") set(CMAKE_INSTALL_RPATH "${destdirRealPath}${CMAKE_INSTALL_PREFIX}/lib")
endif() endif()
endif ()
endif () endif ()
# LIST of supported flags, use SET_CHECK_CXX_FLAGS() to apply to target. # LIST of supported flags, use SET_CHECK_CXX_FLAGS() to apply to target.
@ -203,7 +207,7 @@ if (NOT DISABLE_DISCORD_RPC)
add_definitions(-D__ENABLE_DISCORD__) add_definitions(-D__ENABLE_DISCORD__)
include_directories(DISCORDRPC_PROCESS_INCLUDES) include_directories(DISCORDRPC_PROCESS_INCLUDES)
endif() endif()
elseif (APPLE AND MACOS_USE_DEPENDENCIES) elseif (MACOS_USE_DEPENDENCIES)
find_package(discordrpc CONFIG REQUIRED) find_package(discordrpc CONFIG REQUIRED)
if(${DISCORDRPC_FOUND}) if(${DISCORDRPC_FOUND})
add_definitions(-D__ENABLE_DISCORD__) add_definitions(-D__ENABLE_DISCORD__)
@ -380,80 +384,88 @@ if (WITH_TESTS)
include("${ROOT_DIR}/test/tests/CMakeLists.txt" NO_POLICY_SCOPE) include("${ROOT_DIR}/test/tests/CMakeLists.txt" NO_POLICY_SCOPE)
endif () endif ()
# Install # macOS bundle "install" is handled in src/openrct2-ui/CMakeLists.txt
# Don't recurse, grab all *.txt and *.md files # This is because the openrct2 target is modified (and that is where that target is defined)
file(GLOB DOC_FILES "${ROOT_DIR}/distribution/*.txt") if (NOT MACOS_BUNDLE OR (MACOS_BUNDLE AND WITH_TESTS))
list(APPEND DOC_FILES "${ROOT_DIR}/contributors.md" # Install
"${ROOT_DIR}/licence.txt" # Don't recurse, grab all *.txt and *.md files
"${ROOT_DIR}/distribution/scripting.md" file(GLOB DOC_FILES "${ROOT_DIR}/distribution/*.txt")
"${ROOT_DIR}/distribution/openrct2.d.ts") list(APPEND DOC_FILES "${ROOT_DIR}/contributors.md"
"${ROOT_DIR}/licence.txt"
"${ROOT_DIR}/distribution/scripting.md"
"${ROOT_DIR}/distribution/openrct2.d.ts")
# CMake does not allow specifying a dependency chain which includes built-in # CMake does not allow specifying a dependency chain which includes built-in
# targets, like `install`, so we have to trick it and execute dependency ourselves. # targets, like `install`, so we have to trick it and execute dependency ourselves.
install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" --build \"${CMAKE_CURRENT_BINARY_DIR}\" --target g2)") install(CODE "execute_process(COMMAND \"${CMAKE_COMMAND}\" --build \"${CMAKE_CURRENT_BINARY_DIR}\" --target g2)")
if (DOWNLOAD_TITLE_SEQUENCES) if (DOWNLOAD_TITLE_SEQUENCES)
# If openrct2.parkseq or data/sequence/ exists, assume all the title sequences are already present # If openrct2.parkseq or data/sequence/ exists, assume all the title sequences are already present
install(CODE install(CODE
"if (EXISTS \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/sequence/openrct2.parkseq\" OR EXISTS ${CMAKE_SOURCE_DIR}/data/sequence/)\n\ "if (EXISTS \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/sequence/openrct2.parkseq\" OR EXISTS ${CMAKE_SOURCE_DIR}/data/sequence/)\n\
message(\"Using cached title sequences\")\n\ message(\"Using cached title sequences\")\n\
else () \n\ else () \n\
file(DOWNLOAD ${TITLE_SEQUENCE_URL} \$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/sequence/title-sequences.zip EXPECTED_HASH SHA1=${TITLE_SEQUENCE_SHA1} SHOW_PROGRESS)\n\ file(DOWNLOAD ${TITLE_SEQUENCE_URL} \$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/sequence/title-sequences.zip EXPECTED_HASH SHA1=${TITLE_SEQUENCE_SHA1} SHOW_PROGRESS)\n\
execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/sequence/ \"${CMAKE_COMMAND}\" -E tar xf title-sequences.zip)\n\ execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/sequence/ \"${CMAKE_COMMAND}\" -E tar xf title-sequences.zip)\n\
file(REMOVE \$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/sequence/title-sequences.zip)\n\ file(REMOVE \$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/sequence/title-sequences.zip)\n\
endif ()") endif ()")
endif () endif ()
if (DOWNLOAD_OBJECTS) if (DOWNLOAD_OBJECTS)
# If rct2.wtrcyan.json or data/object/ exists, assume all the objects are already present # If rct2.wtrcyan.json or data/object/ exists, assume all the objects are already present
install(CODE install(CODE
"if (EXISTS \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/object/rct2/water/rct2.wtrcyan.json\" OR EXISTS ${CMAKE_SOURCE_DIR}/data/object/)\n\ "if (EXISTS \"\$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/object/rct2/water/rct2.wtrcyan.json\" OR EXISTS ${CMAKE_SOURCE_DIR}/data/object/)\n\
message(\"Using cached objects\")\n\ message(\"Using cached objects\")\n\
else () \n\ else () \n\
file(DOWNLOAD ${OBJECTS_URL} \$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/object/objects.zip EXPECTED_HASH SHA1=${OBJECTS_SHA1} SHOW_PROGRESS)\n\ file(DOWNLOAD ${OBJECTS_URL} \$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/object/objects.zip EXPECTED_HASH SHA1=${OBJECTS_SHA1} SHOW_PROGRESS)\n\
execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/object/ \"${CMAKE_COMMAND}\" -E tar xf objects.zip)\n\ execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/object/ \"${CMAKE_COMMAND}\" -E tar xf objects.zip)\n\
file(REMOVE \$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/object/objects.zip)\n\ file(REMOVE \$ENV{DESTDIR}${CMAKE_INSTALL_FULL_DATADIR}/${PROJECT_NAME}/object/objects.zip)\n\
endif ()") endif ()")
endif () endif ()
if (DOWNLOAD_REPLAYS) if (DOWNLOAD_REPLAYS)
install(CODE install(CODE
"if (EXISTS \${CMAKE_CURRENT_BINARY_DIR}/testdata/replays/)\n\ "if (EXISTS \${CMAKE_CURRENT_BINARY_DIR}/testdata/replays/)\n\
message(\"Using cached replays\")\n\ message(\"Using cached replays\")\n\
else () \n\ else () \n\
file(DOWNLOAD ${REPLAYS_URL} \${CMAKE_CURRENT_BINARY_DIR}/testdata/replays/replays.zip EXPECTED_HASH SHA1=${REPLAYS_SHA1} SHOW_PROGRESS)\n\ file(DOWNLOAD ${REPLAYS_URL} \${CMAKE_CURRENT_BINARY_DIR}/testdata/replays/replays.zip EXPECTED_HASH SHA1=${REPLAYS_SHA1} SHOW_PROGRESS)\n\
execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \${CMAKE_CURRENT_BINARY_DIR}/testdata/replays/ \"${CMAKE_COMMAND}\" -E tar xf replays.zip)\n\ execute_process(COMMAND \"${CMAKE_COMMAND}\" -E chdir \${CMAKE_CURRENT_BINARY_DIR}/testdata/replays/ \"${CMAKE_COMMAND}\" -E tar xf replays.zip)\n\
file(REMOVE \${CMAKE_CURRENT_BINARY_DIR}/testdata/replays/replays.zip)\n\ file(REMOVE \${CMAKE_CURRENT_BINARY_DIR}/testdata/replays/replays.zip)\n\
endif ()") endif ()")
endif () endif ()
install(TARGETS "libopenrct2" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" install(FILES "${CMAKE_CURRENT_BINARY_DIR}/g2.dat" DESTINATION "${CMAKE_INSTALL_DATADIR}/openrct2")
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") install(DIRECTORY "data/" DESTINATION "${CMAKE_INSTALL_DATADIR}/openrct2")
if(NOT DISABLE_GUI AND NOT MACOS_BUNDLE)
install(TARGETS "openrct2" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()
install(TARGETS "openrct2-cli" OPTIONAL RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/g2.dat" DESTINATION "${CMAKE_INSTALL_DATADIR}/openrct2")
install(DIRECTORY "data/" DESTINATION "${CMAKE_INSTALL_DATADIR}/openrct2")
install(FILES ${DOC_FILES} DESTINATION "${CMAKE_INSTALL_DOCDIR}")
install(FILES "distribution/linux/openrct2.appdata.xml" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo")
if (NOT DISABLE_GUI)
install(FILES "resources/logo/icon_x16.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/16x16/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x24.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/24x24/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x32.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/32x32/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x48.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x64.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/64x64/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x96.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/96x96/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x128.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x256.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/256x256/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_flag.svg" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps" RENAME "openrct2.svg")
install(FILES "distribution/linux/openrct2.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
install(FILES "distribution/linux/openrct2-savegame.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
install(FILES "distribution/linux/openrct2-scenario.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
install(FILES "distribution/linux/openrct2-uri.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
endif()
install(FILES "distribution/linux/openrct2-mimeinfo.xml" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/mime/packages/" RENAME "openrct2.xml")
install(DIRECTORY "distribution/man/" DESTINATION "${CMAKE_INSTALL_MANDIR}/man6" FILES_MATCHING PATTERN "*.6")
if (APPLE AND MACOS_USE_DEPENDENCIES) # even when building WITH_TESTS, none of the below install steps are required for OpenRCT2.app
# Note: dependencies may have the same names as system installed libraries if (NOT MACOS_BUNDLE)
# (via homebrew). A local CMAKE_INSTALL_PREFIX is recommended to avoid issues install(TARGETS "libopenrct2" LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
file(GLOB DYLIB_FILES "${MACOS_DYLIBS_DIR}/lib/*.dylib") ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}")
install(FILES ${DYLIB_FILES} DESTINATION "${CMAKE_INSTALL_LIBDIR}") if(NOT DISABLE_GUI)
install(TARGETS "openrct2" RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()
install(TARGETS "openrct2-cli" OPTIONAL RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
install(FILES ${DOC_FILES} DESTINATION "${CMAKE_INSTALL_DOCDIR}")
install(FILES "distribution/linux/openrct2.appdata.xml" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/metainfo")
if (NOT DISABLE_GUI)
install(FILES "resources/logo/icon_x16.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/16x16/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x24.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/24x24/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x32.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/32x32/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x48.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x64.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/64x64/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x96.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/96x96/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x128.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_x256.png" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/256x256/apps" RENAME "openrct2.png")
install(FILES "resources/logo/icon_flag.svg" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/scalable/apps" RENAME "openrct2.svg")
install(FILES "distribution/linux/openrct2.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
install(FILES "distribution/linux/openrct2-savegame.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
install(FILES "distribution/linux/openrct2-scenario.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
install(FILES "distribution/linux/openrct2-uri.desktop" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
endif()
install(FILES "distribution/linux/openrct2-mimeinfo.xml" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/mime/packages/" RENAME "openrct2.xml")
install(DIRECTORY "distribution/man/" DESTINATION "${CMAKE_INSTALL_MANDIR}/man6" FILES_MATCHING PATTERN "*.6")
if (MACOS_USE_DEPENDENCIES)
# Note: dependencies may have the same names as system installed libraries
# (via homebrew). A local CMAKE_INSTALL_PREFIX is recommended to avoid issues
file(GLOB DYLIB_FILES "${MACOS_DYLIBS_DIR}/lib/*.dylib")
install(FILES ${DYLIB_FILES} DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endif()
endif()
endif() endif()