From 5395a8dc841fd2bc7eae9cfbc65c7be15296e7b5 Mon Sep 17 00:00:00 2001 From: Lukas Werling Date: Sun, 23 Sep 2018 23:14:51 +0200 Subject: [PATCH] Add WITH_APPDIR_INSTALLATION configuration option With this option enabled, `make install` will install the files in an AppDir-compatible directory structure suitable for creating an AppImage. --- CMakeLists.txt | 18 ++++++++++++------ config.h.cmake | 10 +++++++++- src/config/C4Config.cpp | 4 ++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7cb677dfa..2a03394b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ CMAKE_DEPENDENT_OPTION(USE_COCOA "Use Apple Cocoa widgets." ON "APPLE" O CMAKE_DEPENDENT_OPTION(USE_WIN32_WINDOWS "Use Microsoft Desktop App User Interface widgets." ON "WIN32" OFF) CMAKE_DEPENDENT_OPTION(USE_SDL_MAINLOOP "Use SDL to create windows etc. Qt editor." ON "NOT USE_COCOA AND NOT USE_WIN32_WINDOWS AND NOT HEADLESS_ONLY" OFF) option(WITH_AUTOMATIC_UPDATE "Automatic updates are downloaded from the project website." OFF) +CMAKE_DEPENDENT_OPTION(WITH_APPDIR_INSTALLATION "Install into an AppDir" OFF "UNIX AND NOT APPLE AND WITH_AUTOMATIC_UPDATE" ON) option(HEADLESS_ONLY "Only build headless parts. Somewhat reduces dependencies. (still needs libpng because that one's small and hard to remove.) Only tested with make/gcc/linux." OFF) option(C4GROUP_TOOL_ONLY "Only build c4group binary." OFF) @@ -170,10 +171,6 @@ if(WIN32 AND MINGW) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--nxcompat -Wl,--dynamicbase") endif() -if(UNIX) - add_definitions("-DOC_SYSTEM_DATA_DIR=\"${CMAKE_INSTALL_PREFIX}/share/games/openclonk\"") -endif() - if(APPLE) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc -headerpad_max_install_names") endif() @@ -1463,7 +1460,11 @@ endif() # Don't allow installation for WITH_AUTOMATIC_UPDATE because otherwise # the installed binary wouldn't find its game data in the system data path. IF(WITH_AUTOMATIC_UPDATE) - INSTALL(CODE "MESSAGE(SEND_ERROR \"Installation is only supported for WITH_AUTOMATIC_UPDATE disabled\")") + if(WITH_APPDIR_INSTALLATION) + INSTALL(CODE "MESSAGE(\"WITH_APPDIR_INSTALLATION is enabled, installation will create an AppDir\")") + else() + INSTALL(CODE "MESSAGE(SEND_ERROR \"Installation is only supported for WITH_AUTOMATIC_UPDATE disabled\")") + endif() ENDIF() if(NOT C4GROUP_TOOL_ONLY) @@ -1606,7 +1607,12 @@ if(NOT HEADLESS_ONLY AND NOT C4GROUP_TOOL_ONLY) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/openclonk.appdata.xml DESTINATION share/appdata) # Install binaries - install(TARGETS openclonk DESTINATION games) + if(WITH_APPDIR_INSTALLATION) + # AppDir expects binaries in /usr/bin + install(TARGETS openclonk DESTINATION bin) + else() + install(TARGETS openclonk DESTINATION games) + endif() else() install(TARGETS openclonk BUNDLE DESTINATION . diff --git a/config.h.cmake b/config.h.cmake index 02af2cb26..7bd3460ef 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -105,12 +105,13 @@ /* Enable automatic update system */ #cmakedefine WITH_AUTOMATIC_UPDATE 1 +#cmakedefine WITH_APPDIR_INSTALLATION 1 /* Select an audio provider */ #define AUDIO_TK AUDIO_TK_${Audio_TK_UPPER} #else #define AUDIO_TK AUDIO_TK_NONE -#endif +#endif // USE_CONSOLE #define AUDIO_TK_NONE 0 #define AUDIO_TK_OPENAL 1 @@ -119,5 +120,12 @@ /* Include OpenAL extensions (alext.h) for sound modifiers */ #cmakedefine HAVE_ALEXT 1 +/* Path to data directory */ +#ifdef WITH_APPDIR_INSTALLATION +#define OC_SYSTEM_DATA_DIR "../share/games/openclonk" +#else +#define OC_SYSTEM_DATA_DIR "${CMAKE_INSTALL_PREFIX}/share/games/openclonk" +#endif + /* Path to /proc/self/exe (Linux) or equivalent */ #cmakedefine PROC_SELF_EXE "${PROC_SELF_EXE}" diff --git a/src/config/C4Config.cpp b/src/config/C4Config.cpp index bc6e0a20c..1d29c46fe 100644 --- a/src/config/C4Config.cpp +++ b/src/config/C4Config.cpp @@ -477,6 +477,10 @@ void C4ConfigGeneral::DeterminePaths() SCopy(ExePath.getMData(),SystemDataPath); #elif defined(__APPLE__) SCopy(::Application.GetGameDataPath().c_str(),SystemDataPath); +#elif defined(WITH_APPDIR_INSTALLATION) + // AppDir: layout like normal unix installation, but relative to executable. + auto str = FormatString("%s%s", ExePath.getMData(), OC_SYSTEM_DATA_DIR); + SCopy(str.getMData(), SystemDataPath); #elif defined(WITH_AUTOMATIC_UPDATE) // WITH_AUTOMATIC_UPDATE builds are our tarball releases and // development snapshots, i.e. where the game data is at the