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 0e1f205
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 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
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +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_MAC_COPYRIGHT "https://github.com/jorio/CandyCrisis")

if(NOT APPLE AND NOT WIN32)
set(GAME_INSTALL_BIN_DIR "bin" CACHE STRING "Install executable to this directory")
set(GAME_INSTALL_DATA_DIR "share/${GAME_TARGET}" CACHE STRING "Install game assets to this directory")
endif()

# 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")
Expand All @@ -23,7 +32,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)
Expand Down Expand Up @@ -265,4 +274,9 @@ 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 ${GAME_INSTALL_BIN_DIR})
install(DIRECTORY ${CMAKE_SOURCE_DIR}/CandyCrisisResources/ DESTINATION ${GAME_INSTALL_DATA_DIR})
endif()
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 0e1f205

Please sign in to comment.