Skip to content

Commit

Permalink
Merge pull request #154 from TcT2k/cmake_package
Browse files Browse the repository at this point in the history
Add CPack support to provide Win32 binaries and github releases
  • Loading branch information
JayFoxRox authored Nov 6, 2018
2 parents 5d880e1 + 5b7622c commit fc13ad3
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 11 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# This is the EditorConfig (http://editorconfig.org/) coding style file for
# openswe1r

root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
39 changes: 39 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,40 @@ add_executable(openswe1r
com/dplay.c
)

# Determine version information
if(CMAKE_SIZEOF_VOID_P LESS 8)
set(APP_BUILD_CONFIG x86)
else()
set(APP_BUILD_CONFIG x64)
endif()
if(WIN32)
string(APPEND APP_BUILD_CONFIG "-Windows")
if(MSVC)
string(APPEND APP_BUILD_CONFIG "-MSVC")
elseif(MSYS)
string(APPEND APP_BUILD_CONFIG "-MSYS")
endif()
elseif(APPLE)
string(APPEND APP_BUILD_CONFIG "-macOS")
else()
string(APPEND APP_BUILD_CONFIG "-Linux")
endif()

add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/app_version.h
PRE_BUILD
COMMAND
${CMAKE_COMMAND}
-D APP_VERSION_DIR=${CMAKE_BINARY_DIR}
-D APP_BUILD_CONFIG=${APP_BUILD_CONFIG}
-P cmake/create_app_version.cmake
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
)
target_sources(openswe1r PUBLIC ${CMAKE_BINARY_DIR}/app_version.h)
target_include_directories(openswe1r PRIVATE ${CMAKE_BINARY_DIR})

include(package.cmake)

if(USE_VM)
target_compile_definitions(openswe1r PUBLIC -DUC_KVM)
target_sources(openswe1r PUBLIC
Expand All @@ -65,3 +99,8 @@ target_link_libraries(openswe1r
${SDL2_LIBRARY}
${OPENAL_LIBRARY}
)

if(MSVC)
# Silence MSVC CRT security warnings
target_compile_definitions(openswe1r PRIVATE _CRT_SECURE_NO_WARNINGS)
endif()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/OpenSWE1R) [![CLA assistant](https://cla-assistant.io/readme/badge/OpenSWE1R/openswe1r)](https://cla-assistant.io/OpenSWE1R/openswe1r) [![Travis build Status](https://travis-ci.org/OpenSWE1R/openswe1r.svg?branch=master)](https://travis-ci.org/OpenSWE1R/openswe1r) [![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/92s5hpto3kvn8sx3/branch/master?svg=true)](https://ci.appveyor.com/project/JayFoxRox82949/openswe1r/branch/master)
[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/OpenSWE1R) [![CLA assistant](https://cla-assistant.io/readme/badge/OpenSWE1R/openswe1r)](https://cla-assistant.io/OpenSWE1R/openswe1r) [![Travis build Status](https://travis-ci.org/OpenSWE1R/openswe1r.svg?branch=master)](https://travis-ci.org/OpenSWE1R/openswe1r) [![AppVeyor Build status](https://ci.appveyor.com/api/projects/status/4fixwemedrccktt3/branch/master?svg=true)](https://ci.appveyor.com/project/OpenSWE1R/openswe1r/branch/master)

---

Expand Down
7 changes: 7 additions & 0 deletions app_version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright 2017 OpenSWE1R Maintainers
// Licensed under GPLv2 or any later version
// Refer to the included LICENSE.txt file.

// THIS FILE IS CREATE AUTOMATICALLY DO NOT EDIT

#define APP_VERSION_STRING "@APP_VERSION@"
61 changes: 52 additions & 9 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# shallow clone
clone_depth: 10

version: '{build}'

cache:
- C:\tools\vcpkg\installed\
- C:\projects\unicorn\mingw-w64-x86_64-unicorn-1.0.1-1-any.pkg.tar.xz

os: Visual Studio 2017 Preview

Expand All @@ -27,20 +30,25 @@ install:
# redirect err to null to prevent warnings from becoming errors
C:\msys64\usr\bin\bash -lc "pacman --noconfirm -S mingw-w64-x86_64-SDL2 mingw-w64-x86_64-glew mingw-w64-x86_64-openal mingw-w64-x86_64-enet 2>&1"
# install unicorn from source
mkdir unicorn
cd unicorn
Start-FileDownload 'https://raw.githubusercontent.com/Alexpux/MINGW-packages/master/mingw-w64-unicorn/PKGBUILD'
C:\msys64\usr\bin\bash -lc "MINGW_INSTALLS=mingw64 makepkg-mingw -sLf -i --noconfirm 2>&1"
cd ..
if (Test-Path C:\projects\unicorn\mingw-w64-x86_64-unicorn-1.0.1-1-any.pkg.tar.xz) {
C:\msys64\usr\bin\bash -lc "pacman --noconfirm -U C:/projects/unicorn/mingw-w64-x86_64-unicorn-1.0.1-1-any.pkg.tar.xz 2>&1"
} else {
pushd C:\projects
mkdir unicorn
cd unicorn
Start-FileDownload 'https://raw.githubusercontent.com/Alexpux/MINGW-packages/master/mingw-w64-unicorn/PKGBUILD'
C:\msys64\usr\bin\bash -lc "MINGW_INSTALLS=mingw64 makepkg-mingw -sLf -i --noconfirm 2>&1"
popd
}
# stick to cmake 3.9.6 since on lower versions it could happen that cmake generates a Makefile that links against gcc_eh
C:\msys64\usr\bin\bash -lc "pacman --noconfirm -U http://repo.msys2.org/mingw/x86_64/mingw-w64-x86_64-cmake-3.9.6-1-any.pkg.tar.xz 2>&1"
} else {
vcpkg install unicorn sdl2 glew openal-soft enet
}
before_build:
- mkdir %BUILD_TYPE%_build
- cd %BUILD_TYPE%_build
- mkdir build
- cd build
- ps: |
if ($env:BUILD_TYPE -eq 'mingw') {
C:\msys64\usr\bin\bash.exe -lc "cmake -G 'MSYS Makefiles' -DCMAKE_BUILD_TYPE=Release .. 2>&1"
Expand All @@ -53,7 +61,42 @@ before_build:
build_script:
- ps: |
if ($env:BUILD_TYPE -eq 'mingw') {
C:\msys64\usr\bin\bash.exe -lc 'mingw32-make -j4 -C mingw_build/ 2>&1'
C:\msys64\usr\bin\bash.exe -lc 'mingw32-make -j4 -C build/ 2>&1'
} else {
msbuild msvc_build/openswe1r.sln /maxcpucount /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
msbuild build/openswe1r.sln /maxcpucount /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll"
}
- cmake --build build --config Release --target package

artifacts:
- path: build/*.zip
name: executable

deploy:
- provider: GitHub
tag: dev-$(appveyor_build_version)
release: Development Release $(appveyor_build_version)
description: >
Automatically created development release $(appveyor_build_version)
Use this release to test cutting edge features and changes not
included in the latest offical release build.
prerelease: true
repository: OpenSWE1R/openswe1r-unstable
auth_token:
secure: dt7LXTsIxqTkmXC0FdK7k7K23ifilaIvb0wFXCVDhrNk6u6myk6I0Zgz/FwQ1nFf
on:
appveyor_repo_tag: false
branch: master
BUILD_TYPE: msvc

- provider: GitHub
tag: $(appveyor_repo_tag_name)
release: Version $(appveyor_repo_tag_name)
description: >
Stable release version $(appveyor_build_version)
auth_token:
secure: dt7LXTsIxqTkmXC0FdK7k7K23ifilaIvb0wFXCVDhrNk6u6myk6I0Zgz/FwQ1nFf
on:
appveyor_repo_tag: true
branch: master
BUILD_TYPE: msvc
25 changes: 25 additions & 0 deletions cmake/create_app_version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# This script will determine the current version based on git revision
# or tag and create information files to be consumed during compile
# and package time

include(${CMAKE_SOURCE_DIR}/cmake/determine_app_version.cmake)

# Write app version to header if changed
set(APP_VERSION_FILE_NEEDS_UPDATE TRUE)
set(APP_VERSION_FILE "${APP_VERSION_DIR}/app_version.h")
if(EXISTS ${APP_VERSION_FILE})
file(READ ${APP_VERSION_FILE} VERSION_H_CONTENTS)
string(REGEX MATCH "APP_VERSION_STRING[ \t]+\"(.+)\""
FILE_VERSION ${VERSION_H_CONTENTS})
string(REGEX MATCH "\"(.+)\""
FILE_VERSION ${FILE_VERSION})
string(REGEX MATCH "[^\"]+"
FILE_VERSION ${FILE_VERSION})
if(FILE_VERSION STREQUAL APP_VERSION)
set(APP_VERSION_FILE_NEEDS_UPDATE FALSE)
endif()
endif()

if(APP_VERSION_FILE_NEEDS_UPDATE)
configure_file("${CMAKE_SOURCE_DIR}/app_version.h.in" ${APP_VERSION_FILE} @ONLY)
endif()
32 changes: 32 additions & 0 deletions cmake/determine_app_version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This script will determine the current version based on git revision or tag

# Determine version number

# When AppVeyor builds a tag use that tags name as version
if("$ENV{APPVEYOR_REPO_TAG}" STREQUAL "true")
set(APP_VERSION $ENV{APPVEYOR_REPO_TAG_NAME})
else()
# Default to git revision
execute_process(
COMMAND git show -s --format=%h
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_REVISION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(APP_VERSION g${GIT_REVISION})
endif()

# Determine if the current version is "dirty"
execute_process(
COMMAND git status --porcelain
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_STATUS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(GIT_STATUS)
string(APPEND APP_VERSION "-dirty")
endif()

if(APP_BUILD_CONFIG)
string(APPEND APP_VERSION "-${APP_BUILD_CONFIG}")
endif()
6 changes: 5 additions & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Refer to the included LICENSE.txt file.

#include "main.h"
#include "app_version.h"

#include <string.h>
#include <stdio.h>
Expand Down Expand Up @@ -3976,6 +3977,7 @@ void RunX86(Exe* exe) {

int main(int argc, char* argv[]) {
printf("-- Initializing\n");
printf("Version: %s\n", APP_VERSION_STRING);
InitializeEmulation();
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS) < 0) {
printf("Failed to initialize SDL2!\n");
Expand All @@ -3998,7 +4000,9 @@ int main(int argc, char* argv[]) {
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

sdlWindow = SDL_CreateWindow("OpenSWE1R", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, style);
char windowTitle[200];
snprintf(windowTitle, 200, "OpenSWE1R (Version: %s)", APP_VERSION_STRING);
sdlWindow = SDL_CreateWindow(windowTitle, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, style);
assert(sdlWindow != NULL);

SDL_GLContext glcontext = SDL_GL_CreateContext(sdlWindow);
Expand Down
46 changes: 46 additions & 0 deletions package.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Configure CPack variables before including CPack

set(CPACK_PACKAGE_VENDOR OpenSWE1R)
set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_SOURCE_DIR}/LICENSE.txt)

if(NOT CPACK_GENERATOR)
# Set default list of supported CPack generators if not specified by the user
if(WIN32 OR APPLE)
set(CPACK_GENERATOR "ZIP")
else()
set(CPACK_GENERATOR "TGZ")
endif()
endif()

include(cmake/determine_app_version.cmake)
set(CPACK_PACKAGE_VERSION ${APP_VERSION})
set(CPACK_PACKAGE_FILE_NAME OpenSWE1R-${APP_VERSION})

include(CPack)

# Install required files
set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ".")

# Install main binaries
install(TARGETS openswe1r
RUNTIME DESTINATION ${CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION}
)

# Install documentation
install(FILES README.md LICENSE.txt DESTINATION ${CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION})

# Install additional binary modules
if(MSVC)
# Install required runtime libraries
include(InstallRequiredSystemLibraries)

# vcpkg will automatically move the required binaries to the build folder
foreach(lib OpenAL32 unicorn SDL2)
install(FILES $<TARGET_FILE_DIR:openswe1r>/${lib}.dll
DESTINATION ${CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION}
)
endforeach()
install(FILES $<TARGET_FILE_DIR:openswe1r>/glew32$<$<CONFIG:Debug>:d>.dll
DESTINATION ${CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION}
)
endif()

0 comments on commit fc13ad3

Please sign in to comment.