Skip to content

Commit

Permalink
Merge pull request #3 from h67ma/basic_cpack
Browse files Browse the repository at this point in the history
Basic cpack
  • Loading branch information
h67ma authored Dec 7, 2023
2 parents 5683d1e + 2f959e0 commit 0d21904
Show file tree
Hide file tree
Showing 12 changed files with 290 additions and 32 deletions.
64 changes: 64 additions & 0 deletions .github/workflows/package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: CPack and upload

on:
workflow_dispatch:

jobs:
build:
runs-on: ${{matrix.os}}

strategy:
fail-fast: true

matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++

steps:
- name: Install Linux dependencies
if: ${{ matrix.os == 'ubuntu-latest' }}
run: |
sudo apt update
sudo apt install -y libfreetype-dev libx11-dev libxrandr-dev libudev-dev libgl-dev libflac-dev libvorbis-dev libopenal-dev libxcursor-dev
- name: Install Windows dependencies
if: ${{ matrix.os == 'windows-latest' }}
run: |
iwr -useb get.scoop.sh -outfile 'install.ps1'
.\install.ps1 -RunAsAdmin
scoop update
scoop bucket add extras
scoop install nsis
- name: Checkout
uses: actions/checkout@v4

- name: Configure
run: >
cmake -B ${{github.workspace}}/build
-DCMAKE_CXX_COMPILER=${{matrix.cpp_compiler}}
-DCMAKE_C_COMPILER=${{matrix.c_compiler}}
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}
-S ${{github.workspace}}
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{matrix.build_type}}

- name: Package
run: cpack --config ${{github.workspace}}/build/CPackConfig.cmake

- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: cpacked
path: |
${{github.workspace}}/foerr-*.tar.gz
${{github.workspace}}/foerr-*.exe
if-no-files-found: ignore
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
foerr
.cache/
.vscode/
build/
*.dll
*.gch
*.log
*.o
*.svg
*.tmp
_CPack_Packages/
foerr-*.tar.gz
foerr-*.exe
41 changes: 24 additions & 17 deletions CMakeGitVersion.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
# based on https://github.com/nocnokneo/cmake-git-versioning-example
if(GIT_EXECUTABLE)
get_filename_component(SRC_DIR ${SRC} DIRECTORY)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "v*"
WORKING_DIRECTORY ${SRC_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_DESCRIBE_ERROR_CODE)
set(GIT_VERSION ${GIT_DESCRIBE_VERSION})
function(get_git_version GIT_EXECUTABLE SRC_DIR)
if(GIT_EXECUTABLE)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "v*"
WORKING_DIRECTORY ${SRC_DIR}
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_DESCRIBE_ERROR_CODE)
set(_GIT_VERSION ${GIT_DESCRIBE_VERSION})
endif()
endif()
endif()

if(NOT DEFINED GIT_VERSION)
set(GIT_VERSION v0.0.0-unknown)
message(WARNING "Failed to determine GIT_VERSION. Using default version: \"${GIT_VERSION}\".")
endif()
if(NOT DEFINED _GIT_VERSION)
set(_GIT_VERSION v0.0.0-unknown)
message(WARNING "Failed to determine GIT_VERSION. Using default version: \"${_GIT_VERSION}\".")
endif()

configure_file(${SRC} ${DST} @ONLY)
set(GIT_VERSION ${_GIT_VERSION} PARENT_SCOPE)
endfunction()

if(DEFINED SRC)
get_filename_component(SRC_DIR ${SRC} DIRECTORY)
get_git_version(${GIT_EXECUTABLE} ${SRC_DIR})
configure_file(${SRC} ${DST} @ONLY)
endif()
47 changes: 44 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# SPDX-License-Identifier: GPL-3.0-only
#
# (c) 2022 h67ma <[email protected]>
# (c) 2022-2023 h67ma <[email protected]>

cmake_minimum_required(VERSION 3.15)
set(CMAKE_CXX_STANDARD 17)
set(CXX_STANDARD_REQUIRED ON)
include(CMakeGitVersion.cmake)

project(foerr_game
project(foerr
LANGUAGES CXX
)

Expand All @@ -15,6 +16,46 @@ if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
cmake_policy(SET CMP0135 NEW)
endif()

add_subdirectory(deps/sfml)
# EXCLUDE_FROM_ALL skips SFML's files from being installed.
# we don't need them, also some of them want to install to system paths and require superuser privileges to do so
add_subdirectory(deps/sfml EXCLUDE_FROM_ALL)

add_subdirectory(deps/nlohmann_json)
add_subdirectory(src)

install(DIRECTORY res DESTINATION ".")
install(DIRECTORY fonts DESTINATION ".")
install(FILES LICENSE DESTINATION ".")

if(WIN32)
# seems a bit hacky but I guess it works?
# TODO detect x86/x64 and select dll from proper path
install(FILES "${PROJECT_BINARY_DIR}/_deps/sfml-src/extlibs/bin/x64/openal32.dll" DESTINATION ".")
endif()

set(CPACK_BINARY_STGZ "OFF")
set(CPACK_BINARY_TZ "OFF")

if(WIN32)
set(CPACK_BINARY_NSIS "ON")
set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/res/ico/foerr.ico")
set(CPACK_NSIS_INSTALLED_ICON_NAME "foerr.exe")
set(CPACK_NSIS_PACKAGE_NAME "FoE: Remains of Remains")
set(CPACK_NSIS_EXECUTABLES_DIRECTORY ".")
set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON")
elseif(UNIX)
set(CPACK_BINARY_TGZ "ON")
endif()

set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "foerr")
set(CPACK_MONOLITHIC_INSTALL "ON")

# ':' not allowed in shortcut name as it will be a file name.
# for some reason these shortcuts remain in "Start Menu" after uninstall
set(CPACK_PACKAGE_EXECUTABLES "foerr" "FoE Remains of Remains")

get_git_version(${GIT_EXECUTABLE} ${CMAKE_SOURCE_DIR})
set(CPACK_PACKAGE_VERSION ${GIT_VERSION})

include(CPack)
7 changes: 7 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ run

Installed hook can be skipped with `git commit --no-verify`.

# Resources
All resources (images, audio, json, etc.) must be located in the `res` directory. Note that everything inside `res`
is distributed under a different license than code (see `res/LICENSE.txt`).

In case of files that can be compressed/optimized without sacrificing quality, it is recommended to do so. For example,
for `.svg` files it is recommended to run them through `scour`.

# Commits
Commits should be atomic. Whenever possible, don't mix two new features in one commit.
When renaming/refactoring a large chunk of code, don't do it alongside other changes - rather split it off into
Expand Down
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Features currently **outside** project scope:

# Installing dependencies
## GNU/Linux
### Building
Refer to [SFML documentation](https://www.sfml-dev.org/tutorials/2.6/compile-with-cmake.php#installing-dependencies)
for satisfying SFML dependencies. On most Debian-based systems the following should be enough:
```
Expand All @@ -63,16 +64,24 @@ sudo apt install -y \
```

## Windows
### Running
Download and install latest
[Microsoft Visual C++ Redistributable](https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist).

### Building
1. Download Visual Studio Community installer
2. Select individual components to install (minimal):
* Compilers, build tools, and runtimes -> MSVC [...] C++ x64/86 build tools (latest)
* SDKs, libraries, and frameworks -> Windows [...] SDK (latest one)

### Packaging
Download and install [NSIS](https://nsis.sourceforge.io).

# Build
```
cd $PROJECT_ROOT
cmake -DCMAKE_BUILD_TYPE=$TYPE -B build
cmake --build . -j`nproc` --config $TYPE
cmake --build build --config $TYPE
```
Where `TYPE` can be either `Debug` or `Release`.

Expand All @@ -98,6 +107,18 @@ cmake --build . --target clean

# Install
```
cd build
cmake --install . --config Release --prefix $PATH_TO_INSTALL
cd $PROJECT_ROOT
cmake -DCMAKE_BUILD_TYPE=Release -B build
cmake --build build --config Release
cmake --install build --config Release --prefix $PATH_TO_INSTALL
```
**Warning**: files will be installed **directly** to the specified path, i.e. without creating a subdirectory.

# Package
```
cd $PROJECT_ROOT
cmake -DCMAKE_BUILD_TYPE=Release -B build
cmake --build build --config Release
cpack --config build/CPackConfig.cmake
```
This will generate a tarball on GNU/Linux and NSIS installer on Windows.
2 changes: 0 additions & 2 deletions deps/sfml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ if(WIN32)
target_compile_options(sfml-system PRIVATE /EHsc)
target_compile_options(sfml-window PRIVATE /EHsc)
endif()

# TODO copy openal.dll from sfml-src/extlibs/bin/{x64/x86} to root dir or somehow add it to PATH
Binary file added res/ico/foerr.ico
Binary file not shown.
90 changes: 90 additions & 0 deletions res/ico/foerr.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 14 additions & 5 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# SPDX-License-Identifier: GPL-3.0-only
#
# (c) 2022 h67ma <[email protected]>
# (c) 2022-2023 h67ma <[email protected]>

file(GLOB_RECURSE SOURCES *.cpp)

add_executable(foerr ${SOURCES})
if(WIN32)
# WIN32 flag prevents the console window from showing up alongside graphical window
# see https://www.sfml-dev.org/faq.php#tr-win-console
add_executable(foerr WIN32 ${SOURCES} exe_icon.rc)
else()
add_executable(foerr ${SOURCES})
endif()

if(WIN32)
# set a tolerable warning level
Expand All @@ -16,10 +22,13 @@ else()
endif()

target_link_libraries(foerr PRIVATE sfml-graphics sfml-window sfml-system sfml-audio nlohmann_json)
if(WIN32)
# needed for the WIN32 flag
# see https://www.sfml-dev.org/faq.php#tr-win-console
target_link_libraries(foerr PRIVATE sfml-main)
endif()

install(TARGETS foerr DESTINATION foerr)
install(DIRECTORY "${PROJECT_BINARY_DIR}/../res" DESTINATION foerr)
# TODO? on binbows also copy openal to install dir
install(TARGETS foerr DESTINATION ".")

# add version from git-describe
# based on https://github.com/nocnokneo/cmake-git-versioning-example
Expand Down
1 change: 1 addition & 0 deletions src/exe_icon.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "../res/ico/foerr.ico"
Loading

0 comments on commit 0d21904

Please sign in to comment.