Skip to content

Commit

Permalink
Build release archives with CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
sturnclaw committed Sep 9, 2023
1 parent 8bea203 commit cad5570
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 30 deletions.
30 changes: 19 additions & 11 deletions .github/workflows/build-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,29 +97,36 @@ jobs:
sudo apt-fast update
sudo apt-fast install -y ${{ env.packages }}
- name: Setup CMake
run: |
cp scripts/CMakeBuildPresetsCI.json CMakeUserPresets.json
cmake --preset linux-x64-release
- name: Build GCC
run: ./bootstrap cmake && make -C build
run: cmake --build ./build --target all

- name: Build Pioneer Data
run: make -C build build-data
run: cmake --build ./build --target build-data

- name: Run Tests
run: ./build/unittest

- name: Build Release
run: ./scripts/build-release.sh
run: |
cmake --build ./build --target install
./scripts/package-release.sh
- name: Upload Artifact
uses: actions/upload-artifact@v3
with:
name: Linux-Artifacts
path: release/zip/*.tar.gz
path: release/pioneer-linux-x64-release-*.tar.gz

- name: Upload Release Files
uses: softprops/action-gh-release@v1
if: ${{ github.event_name == 'release' }}
with:
files: release/zip/pioneer-*.tar.gz
files: release/pioneer-linux-x64-release-*.tar.gz
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand All @@ -137,16 +144,17 @@ jobs:
sudo apt-fast update
sudo apt-fast install -y clang-8 ${{ env.packages }}
- name: Build Clang
- name: Setup CMake
run: |
cp scripts/CMakeBuildPresetsCI.json CMakeUserPresets.json
export CC=clang CXX=clang++
./bootstrap cmake && make -C build
cmake --preset linux-x64-release
- name: Build Clang
run: cmake --build ./build --target all

- name: Build Pioneer Data
run: make -C build build-data
run: cmake --build ./build --target build-data

- name: Run Tests
run: ./build/unittest

- name: Build Release
run: ./scripts/build-release.sh
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ codedoc/
nd/Data/
doxygen/html
doxygen/latex
/release
/out

.deps
*.swp
Expand Down Expand Up @@ -80,12 +82,12 @@ pioneer-*.tar.*
# meta-build tooling products etc. shouldn't be tracked
Makefile
Makefile.in
/release
Debug/
PreRelease/
Profile/
Release/
cmake-*
CMakeUserPresets.json
compile

# IDEs make their local configurations shouldn't be tracked
Expand Down
35 changes: 18 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ if(POLICY CMP0072)
endif()

include(GNUInstallDirs)
include(cmake/InstallPioneer.cmake)

if (MINGW)
# Fix build errors on AppVeyor with MinGW due to a broken GLEW config script
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_SOURCE_DIR}/cmake/Modules)
endif (MINGW)

# We don't want a 'bin' folder on Windows
if (WIN32)
set(CMAKE_INSTALL_BINDIR ${CMAKE_INSTALL_PREFIX})
endif (WIN32)

# Put the output into the root dir so it can be run from Visual Studio
if (MSVC)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR})
Expand Down Expand Up @@ -107,13 +103,6 @@ endif()

string(TIMESTAMP PROJECT_VERSION "%Y%m%d")

if (NOT PIONEER_DATA_DIR)
set(PIONEER_DATA_DIR ${CMAKE_INSTALL_FULL_DATADIR}/pioneer/data CACHE PATH
"Path where game data will be installed" FORCE)
endif (NOT PIONEER_DATA_DIR)

file(TO_NATIVE_PATH ${PIONEER_DATA_DIR} _PIONEER_DATA_DIR)

if (MINGW)
# Enable PRIxYY macros on MinGW
add_definitions(-D__STDC_FORMAT_MACROS)
Expand Down Expand Up @@ -415,20 +404,32 @@ else (MODELCOMPILER)
endif(MODELCOMPILER)

install(TARGETS ${PROJECT_NAME} editor modelcompiler savegamedump
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
RUNTIME DESTINATION ${PIONEER_INSTALL_BINDIR}
)
install(DIRECTORY data/
DESTINATION ${PIONEER_DATA_DIR}
DESTINATION ${PIONEER_INSTALL_DATADIR}/data
REGEX "/models" EXCLUDE
PATTERN ".gitignore" EXCLUDE
PATTERN "listdata.*" EXCLUDE
PATTERN "Makefile.am" EXCLUDE
)
install(DIRECTORY data/models/
DESTINATION ${PIONEER_DATA_DIR}/models
DESTINATION ${PIONEER_INSTALL_DATADIR}/data/models
FILES_MATCHING PATTERN "*.sgm" PATTERN "*.dds" PATTERN "*.png"
)

list(APPEND install_txt
"AUTHORS.txt"
"Changelog.txt"
"Modelviewer.txt"
"Quickstart.txt"
"README.md")

install(FILES ${install_txt} DESTINATION ${PIONEER_INSTALL_DATADIR})

install(DIRECTORY ${CMAKE_SOURCE_DIR}/licenses
DESTINATION ${PIONEER_INSTALL_DATADIR})

if (WIN32)
configure_file(pioneer.iss.cmakein pioneer.iss @ONLY)
file(GLOB win_libs ../pioneer-thirdparty/win32/bin/${MSVC_ARCH}/vs2019/*.dll)
Expand All @@ -439,7 +440,7 @@ if (WIN32)
add_custom_target(win-installer COMMAND ${ISCC} /Q pioneer.iss)
endif (WIN32)

if (UNIX)
if (UNIX AND NOT PIONEER_INSTALL_INPLACE)
set(PIONEER_DESKTOP_FILE ${CMAKE_BINARY_DIR}/metadata/net.pioneerspacesim.Pioneer.desktop)
configure_file(metadata/net.pioneerspacesim.Pioneer.desktop.cmakein ${PIONEER_DESKTOP_FILE} @ONLY)
install(FILES ${PIONEER_DESKTOP_FILE}
Expand All @@ -455,4 +456,4 @@ if (UNIX)
RENAME net.pioneerspacesim.Pioneer.png
)
endforeach()
endif (UNIX)
endif (UNIX AND NOT PIONEER_INSTALL_INPLACE)
2 changes: 1 addition & 1 deletion buildopts.h.cmakein
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#define PIONEER_EXTRAVERSION "@PROJECT_VERSION_GIT@"
#define PIONEER_VERSION "@PROJECT_VERSION@"
#define PIONEER_DATA_DIR "@_PIONEER_DATA_DIR@"
#define PIONEER_DATA_DIR "@PIONEER_DATA_RUNTIME_DIR@"
#define REMOTE_LUA_REPL_PORT @REMOTE_LUA_REPL_PORT@

#cmakedefine01 WITH_OBJECTVIEWER
Expand Down
34 changes: 34 additions & 0 deletions cmake/InstallPioneer.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Setup script for Pioneer installation paths

option(PIONEER_INSTALL_INPLACE "Should an in-place install be generated" OFF)

if (NOT PIONEER_INSTALL_DATADIR)
set(PIONEER_INSTALL_DATADIR ${CMAKE_INSTALL_DATADIR}/pioneer CACHE PATH
"Path where pioneer's data/ folder will be installed" FORCE)
endif (NOT PIONEER_INSTALL_DATADIR)

if (NOT PIONEER_INSTALL_BINDIR)
set(PIONEER_INSTALL_BINDIR ${CMAKE_INSTALL_BINDIR} CACHE PATH
"Path where Pioneer's executables will be installed" FORCE)
endif (NOT PIONEER_INSTALL_BINDIR)

# We don't want a 'bin' folder on Windows
if (WIN32)
set(CMAKE_INSTALL_BINDIR ${CMAKE_INSTALL_PREFIX})
endif (WIN32)

# If doing an in-place installation, everything is installed in the root of the prefix
if (PIONEER_INSTALL_INPLACE)
set(PIONEER_INSTALL_BINDIR ${CMAKE_INSTALL_PREFIX})
set(PIONEER_INSTALL_DATADIR ${CMAKE_INSTALL_PREFIX})
# don't load data from system-wide install
set(PIONEER_DATA_DIR "data")
endif (PIONEER_INSTALL_INPLACE)

# Expected location of game data
if (NOT PIONEER_DATA_DIR)
set(PIONEER_DATA_DIR ${CMAKE_INSTALL_FULL_DATADIR}/pioneer/data CACHE PATH
"Runtime path to load game data from" FORCE)
endif (NOT PIONEER_DATA_DIR)

file(TO_NATIVE_PATH ${PIONEER_DATA_DIR} PIONEER_DATA_RUNTIME_DIR)
42 changes: 42 additions & 0 deletions scripts/CMakeBuildPresetsCI.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"version": 2,
"configurePresets": [
{
"name": "linux-x64-release",
"displayName": "Linux x64 Release",
"description": "in-place installation target; Opt=yes; Profiler=no",
"binaryDir": "${sourceDir}/build/",
"generator": "Unix Makefiles",
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"PIONEER_INSTALL_INPLACE": "1",
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [
"Linux"
]
}
}
},
{
"name": "linux-x64-release-global",
"displayName": "Linux x64 Release",
"description": "global installation target; Opt=yes; Profiler=no",
"binaryDir": "${sourceDir}/build/",
"generator": "Unix Makefiles",
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_BUILD_TYPE": "RelWithDebInfo"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [
"Linux"
]
}
}
}
]
}
24 changes: 24 additions & 0 deletions scripts/package-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

# Package a build and prepare it for upload to Github.

TAG_NAME=$(git describe HEAD)
if [ -z "$TAG_NAME" ]; then
TAG_NAME=$(date +%Y%m%d)
fi

mkdir release

mv out/install/linux-x64-release "release/pioneer-linux-x64-$TAG_NAME"
cd release

tar -czf "pioneer-linux-x64-$TAG_NAME.tar.gz" "pioneer-linux-x64-$TAG_NAME"

if [ $? -ne 0 ]; then
echo "Release failed!"
exit 1
fi

echo "Release finished successfully!"

exit 0

0 comments on commit cad5570

Please sign in to comment.