Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding top-level CPACK option #700

Merged
merged 6 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -566,12 +579,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 @@ -583,15 +591,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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the game doesn't look for the font here, are you sure this will work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On our own branch for Amiga, we have added set(TTF_FONT_PATH \"LiberationSerif-Bold.ttf\")

Shouldn't it be possible to check if target == package change font-path to /usr/share/fonts/truetype etc?

Copy link
Contributor Author

@kai4785 kai4785 Apr 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was emulating what the fedora rpm was doing. Where does the source look for it currently? Seems like a small-ish change for packaging to match the code, but seems like a more expected behavioral change for the code to look for it in a "standard" location.
Also, when does it get used? Because the game seems to work with or with out the font.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh, the fedora spec file has this line:
export CXXFLAGS="-DTTF_FONT_PATH=\"/usr/share/fonts/truetype/CharisSILB.ttf\""
I missed that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed a small patch that splits TTF_FONT_PATH into TTF_FONT_NAME and TTF_FONT_DIR so I could search for TTF_FONT_NAME in 3 places:

  1. Current directory
  2. TTF_FONT_DIR
  3. #ifdef __linux__ "/usr/share/fonts/truetype"
    It should preserve the current behavior while allowing the default build on Linux to search for the TTF_FONT_NAME in a known good location.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The font is used in the credits and any error message.

Your patch looks like a decent solution.

)

# -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