Skip to content

Commit

Permalink
CMakeLists.txt: Unix install target (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorio committed Jun 23, 2023
1 parent ae730c8 commit e7c1ece
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
root = true

[*.{c,cpp,h,hpp,txt}]
charset = utf-8
indent_style = tab
indent_size = 4
2 changes: 1 addition & 1 deletion .github/workflows/release-appimage-aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-appimage-x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
24 changes: 18 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,28 @@ 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()
set(CMAKE_C_STANDARD 17)
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -246,11 +251,11 @@ endif()
if(APPLE)
set(GAME_DATA_TARGET_LOCATION "$<TARGET_FILE_DIR:${GAME_TARGET}>/../Resources")
else()
set(GAME_DATA_TARGET_LOCATION "$<TARGET_FILE_DIR:${GAME_TARGET}>/CandyCrisisResources")
set(GAME_DATA_TARGET_LOCATION "$<TARGET_FILE_DIR:${GAME_TARGET}>/${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)
Expand All @@ -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()
7 changes: 4 additions & 3 deletions packaging/candycrisis.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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;
File renamed without changes
5 changes: 3 additions & 2 deletions packaging/prepare_appimage_appdir.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
33 changes: 32 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/version.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e7c1ece

Please sign in to comment.