From e7c1ece8a7b2c7b7a37c3654861cef1da9876e6f Mon Sep 17 00:00:00 2001 From: Iliyas Jorio Date: Fri, 23 Jun 2023 22:01:15 +0200 Subject: [PATCH] CMakeLists.txt: Unix install target (#1) --- .editorconfig | 6 ++++ .../workflows/release-appimage-aarch64.yml | 2 +- .github/workflows/release-appimage-x86_64.yml | 2 +- CMakeLists.txt | 24 +++++++++---- packaging/candycrisis.desktop | 7 ++-- ...crisis-desktopicon.png => candycrisis.png} | Bin packaging/prepare_appimage_appdir.sh | 5 +-- src/main.c | 33 +++++++++++++++++- src/version.h | 4 +-- 9 files changed, 67 insertions(+), 16 deletions(-) create mode 100644 .editorconfig rename packaging/{candycrisis-desktopicon.png => candycrisis.png} (100%) diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..af11464 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +root = true + +[*.{c,cpp,h,hpp,txt}] +charset = utf-8 +indent_style = tab +indent_size = 4 diff --git a/.github/workflows/release-appimage-aarch64.yml b/.github/workflows/release-appimage-aarch64.yml index 4b5a185..b8ebb31 100644 --- a/.github/workflows/release-appimage-aarch64.yml +++ b/.github/workflows/release-appimage-aarch64.yml @@ -5,7 +5,7 @@ on: [workflow_dispatch, workflow_call] env: SDL2_VERSION: "2.26.3" APPIMAGETOOL_VERSION: "13" - GAME_SHORTNAME: "CandyCrisis" + GAME_SHORTNAME: "candycrisis" GAME_LONGNAME: "Candy Crisis" jobs: diff --git a/.github/workflows/release-appimage-x86_64.yml b/.github/workflows/release-appimage-x86_64.yml index d0f510e..330c940 100644 --- a/.github/workflows/release-appimage-x86_64.yml +++ b/.github/workflows/release-appimage-x86_64.yml @@ -5,7 +5,7 @@ on: [workflow_dispatch, workflow_call] env: SDL2_VERSION: "2.26.3" APPIMAGETOOL_VERSION: "13" - GAME_SHORTNAME: "CandyCrisis" + GAME_SHORTNAME: "candycrisis" GAME_LONGNAME: "Candy Crisis" jobs: diff --git a/CMakeLists.txt b/CMakeLists.txt index bb77465..1910add 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,16 +6,20 @@ else() cmake_minimum_required(VERSION 3.16) endif() -set(GAME_TARGET "CandyCrisis") +if(APPLE OR WIN32) + set(GAME_TARGET "CandyCrisis") +else() + set(GAME_TARGET "candycrisis") +endif() set(GAME_FRIENDLY_NAME "Candy Crisis") set(GAME_BUNDLE_ID "io.jor.candycrisis") +set(GAME_DATA_DIR "CandyCrisisResources") set(GAME_MAC_COPYRIGHT "https://github.com/jorio/CandyCrisis") # Apply macOS deployment target and architectures to all subprojects set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "Minimum macOS deployment version") set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64" CACHE STRING "Target macOS architectures") -set(CMAKE_CXX_STANDARD 20) if (${CMAKE_VERSION} VERSION_LESS "3.21") set(CMAKE_C_STANDARD 11) else() @@ -23,7 +27,7 @@ else() endif() project(${GAME_TARGET} LANGUAGES C - VERSION 3.0.0) + VERSION 3.0.1) # Create an option to switch between a system sdl library and a vendored sdl library option(BUILD_SDL_FROM_SOURCE "Build SDL from source" OFF) @@ -97,7 +101,7 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/packaging/version.txt.in ${CMAKE_CURR # EXECUTABLE TARGET #------------------------------------------------------------------------------ -file(GLOB_RECURSE GAME_SOURCES CONFIGURE_DEPENDS ${GAME_SOURCE_DIR}/*.cpp ${GAME_SOURCE_DIR}/*.c ${GAME_SOURCE_DIR}/*.h) +file(GLOB_RECURSE GAME_SOURCES CONFIGURE_DEPENDS ${GAME_SOURCE_DIR}/*.c ${GAME_SOURCE_DIR}/*.h) if(WIN32) list(APPEND GAME_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/packaging/app.exe.rc) @@ -206,6 +210,7 @@ else() target_compile_options(${GAME_TARGET} PRIVATE /W4 /wd5105 # see https://developercommunity.visualstudio.com/t/1249671 + /we4013 # treat warning as error: undefined function (assuming extern returning int) /MP # multiprocessor build /Zi # output info to PDB ) @@ -246,11 +251,11 @@ endif() if(APPLE) set(GAME_DATA_TARGET_LOCATION "$/../Resources") else() - set(GAME_DATA_TARGET_LOCATION "$/CandyCrisisResources") + set(GAME_DATA_TARGET_LOCATION "$/${GAME_DATA_DIR}") endif() add_custom_command(TARGET ${GAME_TARGET} POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/CandyCrisisResources" "${GAME_DATA_TARGET_LOCATION}") + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_SOURCE_DIR}/${GAME_DATA_DIR}" "${GAME_DATA_TARGET_LOCATION}") # Copy SDL2 DLL for convenience (WARNING: TARGET_RUNTIME_DLLS requires CMake 3.21, so this copy command was separated from the command above.) if(WIN32) @@ -265,4 +270,11 @@ endif() # Install Windows-specific libraries (cmake --install): copy Visual Studio redistributable DLLs to install location if(WIN32) include(InstallRequiredSystemLibraries) +elseif(APPLE) + # no-op +else() + install(TARGETS ${GAME_TARGET} DESTINATION bin) + install(FILES ${CMAKE_SOURCE_DIR}/packaging/${GAME_TARGET}.desktop DESTINATION share/applications/) + install(FILES ${CMAKE_SOURCE_DIR}/packaging/${GAME_TARGET}.png DESTINATION share/icons/hicolor/128x128/apps/) + install(DIRECTORY ${CMAKE_SOURCE_DIR}/${GAME_DATA_DIR}/ DESTINATION share/${GAME_TARGET}/) endif() diff --git a/packaging/candycrisis.desktop b/packaging/candycrisis.desktop index 0544287..66f79f0 100644 --- a/packaging/candycrisis.desktop +++ b/packaging/candycrisis.desktop @@ -2,8 +2,9 @@ Type=Application Version=1.0 Name=Candy Crisis -Comment=Candy Crisis -Icon=candycrisis-desktopicon -Exec=CandyCrisis +Comment=An exciting combination of pure action and puzzle gaming! +Comment[fr]=Une combinaison palpitante d’action et de réflexion ! +Icon=candycrisis +Exec=candycrisis Terminal=false Categories=Game; diff --git a/packaging/candycrisis-desktopicon.png b/packaging/candycrisis.png similarity index 100% rename from packaging/candycrisis-desktopicon.png rename to packaging/candycrisis.png diff --git a/packaging/prepare_appimage_appdir.sh b/packaging/prepare_appimage_appdir.sh index b62a710..de0d76a 100644 --- a/packaging/prepare_appimage_appdir.sh +++ b/packaging/prepare_appimage_appdir.sh @@ -11,14 +11,15 @@ APP_NAME_LOWERCASE="$(echo "$APP_NAME" | awk '{print tolower($0)}')" APP_DIR="build/${APP_NAME}.AppDir" mkdir -p "${APP_DIR}/usr/bin" +mkdir -p "${APP_DIR}/usr/share" # Copy executable and assets cp "${EXE_PATH}" "${APP_DIR}/usr/bin" -cp -r CandyCrisisResources "${APP_DIR}/CandyCrisisResources" +cp -r CandyCrisisResources "${APP_DIR}/usr/share/candycrisis" # Copy XDG stuff cp "packaging/${APP_NAME_LOWERCASE}.desktop" "${APP_DIR}" -cp "packaging/${APP_NAME_LOWERCASE}-desktopicon.png" "${APP_DIR}" +cp "packaging/${APP_NAME_LOWERCASE}.png" "${APP_DIR}" # Copy AppImage kicker script cp "packaging/AppRun" "${APP_DIR}" diff --git a/src/main.c b/src/main.c index 084b0f5..b0cc0bf 100644 --- a/src/main.c +++ b/src/main.c @@ -614,6 +614,12 @@ const char* QuickResourceName( const char* prefix, int id, const char* extension return name; } +static MBoolean CheckDataPath(void) +{ + const char* path = QuickResourceName("snd", 128, ".wav"); + return FileExists(path); +} + void Initialize(void) { #if _WIN32 @@ -641,7 +647,32 @@ void Initialize(void) snprintf(candyCrisisResources, sizeof(candyCrisisResources), "%s/Resources/", pathbuf); #else - snprintf(candyCrisisResources, sizeof(candyCrisisResources), "CandyCrisisResources/"); + char* basePath = SDL_GetBasePath(); + + SDL_snprintf(candyCrisisResources, sizeof(candyCrisisResources), "CandyCrisisResources/"); + if (CheckDataPath()) + { + goto dataPathFound; + } + + SDL_snprintf(candyCrisisResources, sizeof(candyCrisisResources), "%s../share/candycrisis/", basePath); + if (CheckDataPath()) + { + goto dataPathFound; + } + + SDL_snprintf(candyCrisisResources, sizeof(candyCrisisResources), "%s../share/CandyCrisis/", basePath); + if (CheckDataPath()) + { + goto dataPathFound; + } + + SDL_free(basePath); + Error("Couldn't find the CandyCrisisResources or share/candycrisis folder."); + return; + +dataPathFound: + SDL_free(basePath); #endif if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0) diff --git a/src/version.h b/src/version.h index 7708953..493f189 100644 --- a/src/version.h +++ b/src/version.h @@ -1,7 +1,7 @@ #pragma once -#define PROJECT_VERSION "3.0.0" +#define PROJECT_VERSION "3.0.1" #define PROJECT_VERSION_MAJOR 3 #define PROJECT_VERSION_MINOR 0 -#define PROJECT_VERSION_PATCH 0 +#define PROJECT_VERSION_PATCH 1