Skip to content

Commit

Permalink
Adding top-level CPACK option (#700)
Browse files Browse the repository at this point in the history
* Adding top-level CPACK option
* Setting CMAKE_BUILD_TYPE should always be Cache variables

This initializes CMAKE_CXX_FLAGS_RELEASE during project() correctly. With out
this, changes to CMakeLists.txt may result in a complete rebuild because
CMAKE_BUILD_TYPE wasn't in the cache before, and wasn't respected by project(),
but now it is.

https://cmake.org/pipermail/cmake/2008-September/023808.html

* Always build deb and rpm packages where possible
* Searching for .ttf instead of hard-coding it's full path
  • Loading branch information
kai4785 committed May 2, 2020
1 parent 6e449b9 commit 791aa60
Show file tree
Hide file tree
Showing 9 changed files with 124 additions and 30 deletions.
9 changes: 6 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ jobs:
- checkout
- run: echo deb http://deb.debian.org/debian stretch-backports-sloppy main >> /etc/apt/sources.list.d/debian-backports.list
- run: apt-get update -y
- run: apt-get install -y g++ libsdl2-dev libsdl2-mixer-dev libsdl2-ttf-dev git
- run: apt-get install -y g++ libsdl2-dev libsdl2-mixer-dev libsdl2-ttf-dev git rpm
- run: apt-get install -y -t 'stretch-backports*' cmake libsodium-dev
- run: cmake -S. -Bbuild .. -DNIGHTLY_BUILD=ON
- run: cmake --build build -j $(nproc)
- run: cmake --build build --target package
- store_artifacts: {path: ./build/devilutionx, destination: devilutionx_linux_x86_64}
linux_x86_64_test:
docker:
Expand All @@ -33,10 +34,11 @@ jobs:
- checkout
- run: echo deb http://deb.debian.org/debian stretch-backports-sloppy main >> /etc/apt/sources.list.d/debian-backports.list
- run: apt-get update -y
- run: apt-get install -y g++ libsdl-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev git
- run: apt-get install -y g++ libsdl-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev git rpm
- run: apt-get install -y -t 'stretch-backports*' cmake libsodium-dev
- run: cmake -S. -Bbuild .. -DNIGHTLY_BUILD=ON -DUSE_SDL1=ON
- run: cmake --build build -j $(nproc)
- run: cmake --build build --target package
- store_artifacts: {path: ./build/devilutionx, destination: devilutionx_linux_x86_64_sdl1}
linux_x86:
docker:
Expand All @@ -47,10 +49,11 @@ jobs:
- run: echo deb http://deb.debian.org/debian stretch-backports-sloppy main >> /etc/apt/sources.list.d/debian-backports.list
- run: dpkg --add-architecture i386
- run: apt-get update -y
- run: apt-get install -y g++-multilib libsdl2-dev:i386 libsdl2-mixer-dev:i386 libsdl2-ttf-dev:i386 libsodium-dev git
- run: apt-get install -y g++-multilib libsdl2-dev:i386 libsdl2-mixer-dev:i386 libsdl2-ttf-dev:i386 libsodium-dev git rpm
- run: apt-get install -y -t 'stretch-backports*' cmake libsodium-dev:i386
- run: cmake -S. -Bbuild -DNIGHTLY_BUILD=ON -DCMAKE_TOOLCHAIN_FILE=../CMake/32bit.cmake
- run: cmake --build build -j $(nproc)
- run: cmake --build build --target package
- store_artifacts: {path: ./build/devilutionx, destination: devilutionx_linux_x86}
windows_x86:
docker:
Expand Down
2 changes: 1 addition & 1 deletion CMake/amiga_defs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set(UBSAN OFF)
set(NONET ON)
set(USE_SDL1 ON)
set(SDL1_VIDEO_MODE_BPP 8)
set(TTF_FONT_PATH \"LiberationSerif-Bold.ttf\")
set(TTF_FONT_NAME \"LiberationSerif-Bold.ttf\")
# Enable exception suport as they are used in dvlnet code
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
find_package(Freetype REQUIRED)
Expand Down
100 changes: 82 additions & 18 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,21 @@ option(NIGHTLY_BUILD "Enable options for nightly build" OFF)
option(USE_SDL1 "Use SDL1.2 instead of SDL2" OFF)
option(NONET "Disable network" OFF)
option(RUN_TESTS "Build and run tests" OFF)
RELEASE_OPTION(CPACK "Configure CPack")


if(BINARY_RELEASE OR CMAKE_BUILD_TYPE STREQUAL "Release")
set(BINARY_RELEASE ON)
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "")
set(DIST ON)
set(CPACK ON)
endif()

if(NIGHTLY_BUILD OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
set(NIGHTLY_BUILD ON)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "")
set(DIST ON)
set(CPACK ON)
endif()

if(NOT VERSION_NUM)
Expand All @@ -37,6 +41,11 @@ if(NOT VERSION_NUM)
endif()
endif()

find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()

if(VERSION_NUM MATCHES untagged)
project(DevilutionX
LANGUAGES C CXX)
Expand Down Expand Up @@ -324,6 +333,9 @@ endif()

add_executable(${BIN_TARGET} WIN32 MACOSX_BUNDLE ${devilutionx_SRCS})

# Copy the font to the build directory to it works from the build directory
file(COPY "Packaging/resources/CharisSILB.ttf" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")

# Use file GENERATE instead of configure_file because configure_file
# does not support generator expressions.
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
Expand Down Expand Up @@ -391,7 +403,8 @@ foreach(
def_name
SDL1_VIDEO_MODE_WIDTH
SDL1_VIDEO_MODE_HEIGHT
TTF_FONT_PATH
TTF_FONT_DIR
TTF_FONT_NAME
SDL1_VIDEO_MODE_BPP
SDL1_VIDEO_MODE_FLAGS
HAS_KBCTRL
Expand Down Expand Up @@ -567,12 +580,7 @@ if(APPLE)
endif()

set(MACOSX_BUNDLE_LONG_VERSION_STRING "Version ${PROJECT_VERSION}")
set(CPACK_PACKAGE_FILE_NAME "devilutionx")
set(CPACK_DMG_DISABLE_APPLICATIONS_SYMLINK "ON")
set(CPACK_STRIP_FILES TRUE)
set(CPACK_GENERATOR "DragNDrop")

include(CPack)
set(CPACK On)
endif()

if(SWITCH)
Expand All @@ -584,15 +592,71 @@ if(SWITCH)
build_switch_binaries(${BIN_TARGET})
endif()

if(${CMAKE_SYSTEM_NAME} STREQUAL Linux)
set(CPACK_PACKAGE_NAME "devilutionx")
string(TOLOWER "${CPACK_PACKAGE_NAME}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" CPACK_PACKAGE_FILE_NAME)
set(CPACK_STRIP_FILES TRUE)
set(CPACK_GENERATOR "7Z")
if(CPACK)
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
string(TOLOWER ${PROJECT_NAME} project_name)
set(CPACK_PACKAGE_NAME ${project_name})
set(CPACK_GENERATOR "7Z")
# Common *nix files
set(CPACK_STRIP_FILES TRUE)
install(TARGETS ${BIN_TARGET} DESTINATION bin)
set(desktop_file "${PROJECT_SOURCE_DIR}/Packaging/nix/${project_name}.desktop")

find_program(DFI desktop-file-install)
if(DFI)
execute_process(COMMAND ${DFI} --dir=${CMAKE_BINARY_DIR} ${desktop_file})
set(desktop_file "${CMAKE_BINARY_DIR}/${project_name}.desktop")
endif()

install (TARGETS ${BIN_TARGET} DESTINATION ./)
install (FILES "${PROJECT_SOURCE_DIR}/Packaging/resources/CharisSILB.ttf" DESTINATION ./)
install (FILES "${PROJECT_SOURCE_DIR}/Packaging/resources/LICENSE.CharisSILB.txt" DESTINATION ./)
install (FILES "${PROJECT_SOURCE_DIR}/Packaging/nix/README.txt" DESTINATION ./)
install(FILES "${desktop_file}"
DESTINATION "share/applications"
)
install(FILES
"${PROJECT_SOURCE_DIR}/Packaging/nix/README.txt"
DESTINATION "share/diasurgical/${project_name}"
)
install(FILES "${PROJECT_SOURCE_DIR}/Packaging/resources/16.png"
DESTINATION "share/icons/hicolor/16x16/apps"
RENAME "${project_name}.png"
)
install(FILES "${PROJECT_SOURCE_DIR}/Packaging/resources/Diablo_32.png"
DESTINATION "share/icons/hicolor/32x32/apps"
RENAME "${project_name}.png"
)
install(FILES "${PROJECT_SOURCE_DIR}/Packaging/resources/Diablo_48.png"
DESTINATION "share/icons/hicolor/48x48/apps"
RENAME "${project_name}.png"
)
install(FILES "${PROJECT_SOURCE_DIR}/Packaging/resources/CharisSILB.ttf"
DESTINATION "share/fonts/truetype"
)

# -G DEB
set(CPACK_PACKAGE_CONTACT "kai@gnukai.com")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)

# -G RPM
set(CPACK_RPM_FILE_NAME RPM-DEFAULT)

find_program(RPMBUILD rpmbuild)
if(RPMBUILD)
list(APPEND CPACK_GENERATOR "RPM")
endif()
find_program(DPKG dpkg)
if(DPKG)
list(APPEND CPACK_GENERATOR "DEB")
endif()

elseif(APPLE)
set(CPACK_PACKAGE_FILE_NAME "devilutionx")
set(CPACK_DMG_DISABLE_APPLICATIONS_SYMLINK "ON")
set(CPACK_STRIP_FILES TRUE)
set(CPACK_GENERATOR "DragNDrop")
endif()

set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
include(CPack)
endif()
1 change: 0 additions & 1 deletion Packaging/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export COMPILE_FLAGS="-O0"
export DEB_BUILD_MAINT_OPTIONS = hardening=-all
export DEB_CFLAGS_MAINT_APPEND = -Wno-error
export DEB_LDFLAGS_MAINT_APPEND = -Wno-error
export CXXFLAGS="-DTTF_FONT_PATH=\"/usr/share/fonts/truetype/CharisSILB.ttf\""
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
Expand Down
6 changes: 3 additions & 3 deletions Packaging/fedora/devilutionx.desktop
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[Desktop Entry]
Name=devilutionX
Name=devilutionx
GenericName=DevilutionX
Comment=Play Diablo I on Linux
Comment[da]=Spil Diablo I på Linux
Comment[hr]=Igrajte Diablo I na Linuxu
Exec=devilutionx
Icon=devilutionx.png
Icon=devilutionx
Terminal=false
Type=Application
X-DCOP-ServiceType=Multi
X-KDE-StartupNotify=true
Categories=Qt;Game;RolePlaying;
Categories=Game;RolePlaying;
1 change: 0 additions & 1 deletion Packaging/fedora/devilutionx.spec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ Note: Devilution requires an original copy of diabdat.mpq. None of the Diablo 1
mkdir -p build
rm -rf build/*
cd build
export CXXFLAGS="-DTTF_FONT_PATH=\"/usr/share/fonts/truetype/CharisSILB.ttf\""
cmake ..
cmake --build .
cd ..
Expand Down
13 changes: 13 additions & 0 deletions Packaging/nix/devilutionx.desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Desktop Entry]
Name=devilutionx
GenericName=DevilutionX
Comment=Play Diablo I on Linux
Comment[da]=Spil Diablo I på Linux
Comment[hr]=Igrajte Diablo I na Linuxu
Exec=devilutionx
Icon=devilutionx
Terminal=false
Type=Application
X-DCOP-ServiceType=Multi
X-KDE-StartupNotify=true
Categories=Game;RolePlaying;
14 changes: 13 additions & 1 deletion SourceX/DiabloUI/fonts.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "DiabloUI/fonts.h"
#include "file_util.h"

namespace dvl {

Expand Down Expand Up @@ -60,7 +61,18 @@ void LoadTtfFont() {
was_fonts_init = true;
}

font = TTF_OpenFont(TTF_FONT_PATH, 17);
const char* ttf_font_path = TTF_FONT_NAME;
if (!FileExists(ttf_font_path))
{
ttf_font_path = TTF_FONT_DIR TTF_FONT_NAME;
}
#ifdef __linux__
if (!FileExists(ttf_font_path))
{
ttf_font_path = "/usr/share/fonts/truetype/" TTF_FONT_NAME;
}
#endif
font = TTF_OpenFont(ttf_font_path, 17);
if (font == NULL) {
SDL_Log("TTF_OpenFont: %s", TTF_GetError());
return;
Expand Down
8 changes: 6 additions & 2 deletions SourceX/DiabloUI/fonts.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@

#include "DiabloUI/art.h"

#ifndef TTF_FONT_PATH
#define TTF_FONT_PATH "CharisSILB.ttf"
#ifndef TTF_FONT_DIR
#define TTF_FONT_DIR ""
#endif

#ifndef TTF_FONT_NAME
#define TTF_FONT_NAME "CharisSILB.ttf"
#endif

namespace dvl {
Expand Down

0 comments on commit 791aa60

Please sign in to comment.