Skip to content

Commit

Permalink
build: generate git commit hash for non-snap build, do correct instal…
Browse files Browse the repository at this point in the history
…l for all envs
  • Loading branch information
stivius committed Jan 6, 2021
1 parent a6a4bb9 commit 202d818
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 18 deletions.
19 changes: 12 additions & 7 deletions player/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0>=3.22.0)
pkg_check_modules(GLIBMM REQUIRED glibmm-2.4>=2.56.0)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/)
set(CMAKE_TESTS_DIRECTORY ${CMAKE_BINARY_DIR}/bin/tests/)

set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
add_compile_options(
-pthread -Wall -Wno-parentheses -Wno-cast-function-type -W -Wunused-variable -Wunused-parameter -Wunused-function -Wunused -Wno-system-headers -Wno-deprecated -Woverloaded-virtual -Wwrite-strings
Expand Down Expand Up @@ -45,6 +42,11 @@ if(GTK_UI)
add_compile_definitions(USE_GTK)
endif(GTK_UI)

if (NOT SNAP_BUILD AND NOT APPIMAGE_BUILD)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
endif()
set(CMAKE_TESTS_DIRECTORY ${CMAKE_BINARY_DIR}/tests)

add_executable(${PROJECT_NAME}
main.cpp
MainLoop.cpp
Expand All @@ -65,18 +67,21 @@ target_link_libraries(${PROJECT_NAME}
backtrace
)

install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
if(SNAP_BUILD)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
install(FILES resources/ui.glade resources/splash.jpg DESTINATION share/xibo-player)
install(
FILES snap_run.sh
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION bin
)
endif()
install(FILES resources/ui.glade resources/splash.jpg DESTINATION share/xibo-player)
if(APPIMAGE_BUILD)
elseif(APPIMAGE_BUILD)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
install(FILES resources/ui.glade resources/splash.jpg DESTINATION share/xibo-player)
install(FILES resources/xibo-player.desktop DESTINATION share/applications)
install(FILES resources/xibo-player.png DESTINATION share/icons/hicolor/512x512/apps)
else()
install(FILES resources/ui.glade resources/splash.jpg DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif()

enable_testing()
Expand Down
2 changes: 1 addition & 1 deletion player/XiboApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ GeneralInfo XiboApp::collectGeneralInfo()
info.cmsAddress = cmsSettings_.address();
info.resourcesPath = cmsSettings_.resourcesPath();
info.codeVersion = AppConfig::codeVersion();
info.projectVersion = AppConfig::version();
info.projectVersion = AppConfig::releaseVersion();
info.screenShotInterval = playerSettings_.screenshotInterval();
info.displayName = playerSettings_.displayName();
info.windowWidth = mainWindow_->width();
Expand Down
2 changes: 1 addition & 1 deletion player/cms/CollectionInterval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void CollectionInterval::collectNow()
Log::debug("[CollectionInterval] Started");

auto registerDisplayResult =
xmdsSender_.registerDisplay(AppConfig::codeVersion(), AppConfig::version(), "Display").get();
xmdsSender_.registerDisplay(AppConfig::codeVersion(), AppConfig::releaseVersion(), "Display").get();
onDisplayRegistered(registerDisplayResult);
});
}
Expand Down
17 changes: 12 additions & 5 deletions player/config/AppConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@
#include "common/fs/FileSystem.hpp"
#include "common/logger/Logging.hpp"

#if !defined(SNAP_ENABLED)
#include "GitHash.hpp"
#endif

#include <filesystem>
#include <linux/limits.h>
#include <unistd.h>

FilePath AppConfig::resourceDirectory_;

std::string AppConfig::version()
{
return releaseVersion() + "-" + codeVersion();
}

std::string AppConfig::releaseVersion()
{
#if defined(SNAP_ENABLED)
return getenv("SNAP_VERSION");
#elif defined(APPIMAGE_ENABLED)
return std::string{"1.8-R6"};
return "1.8-R6";
#else
return std::string{"dev-version"};
return "dev";
#endif
}

std::string AppConfig::codeVersion()
{
#if defined(SNAP_ENABLED)
return getenv("SNAP_REVISION");
#elif defined(APPIMAGE_ENABLED)
return std::string{"appimage-revision"};
#else
return std::string{"dev-revision"};
return GIT_HASH;
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion player/config/AppConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
class AppConfig
{
public:
static std::string version(); // TODO: strong type
static std::string version();
static std::string releaseVersion(); // TODO: strong type
static std::string codeVersion(); // TODO: strong type

static FilePath resourceDirectory();
Expand Down
20 changes: 20 additions & 0 deletions player/config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
project(config)

if (NOT SNAP_BUILD)
find_package(Git REQUIRED)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
RESULT_VARIABLE SHORT_HASH_RESULT
OUTPUT_VARIABLE SHORT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(RESULT)
message(FATAL_ERROR "Failed to get git hash: ${RESULT}")
endif()
message("Retrieved commit SHA ${SHORT_HASH}")
configure_file(GitHash.hpp.in GitHash.hpp @ONLY)
endif()

add_library(${PROJECT_NAME}
PlayerSettings.cpp
PlayerSettings.hpp
Expand All @@ -12,6 +27,7 @@ add_library(${PROJECT_NAME}
SettingsSerializer.hpp
AppConfig.cpp
AppConfig.hpp
GitHash.hpp.in
)

target_link_libraries(${PROJECT_NAME}
Expand All @@ -20,3 +36,7 @@ target_link_libraries(${PROJECT_NAME}
types
common
)

target_include_directories(${PROJECT_NAME}
PRIVATE ${CMAKE_CURRENT_BINARY_DIR}
)
4 changes: 4 additions & 0 deletions player/config/GitHash.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#pragma once

const char* const GIT_HASH = "@SHORT_HASH@";

2 changes: 2 additions & 0 deletions player/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ void signalStacktraceHandler(int signum)

int main(int /*argc*/, char** /*argv*/)
{
std::cout << AppConfig::version() << std::endl;

XInitThreads();
signal(SIGSEGV, &signalStacktraceHandler);
signal(SIGABRT, &signalStacktraceHandler);
Expand Down
4 changes: 3 additions & 1 deletion player/options/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ target_link_libraries(${PROJECT_NAME}
${GTKMM_LINK_LIBRARIES}
)

install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
if (SNAP_BUILD OR APPIMAGE_BUILD)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
endif()

target_include_directories(${PROJECT_NAME} PRIVATE
${GTKMM_INCLUDE_DIRS}
Expand Down
2 changes: 1 addition & 1 deletion player/options/MainWindowController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ std::string MainWindowController::connectToCms(const std::string& cmsAddress,
XmdsRequestSender xmdsRequester{cmsAddress, key, displayId};

auto connectionResult =
xmdsRequester.registerDisplay(AppConfig::codeVersion(), AppConfig::version(), DefaultDisplay)
xmdsRequester.registerDisplay(AppConfig::codeVersion(), AppConfig::releaseVersion(), DefaultDisplay)
.then([](auto future) {
auto [error, result] = future.get();

Expand Down
4 changes: 3 additions & 1 deletion player/watchdog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ add_executable(${PROJECT_NAME}
ProcessWatcher.hpp
)

install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
if (SNAP_BUILD OR APPIMAGE_BUILD)
install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
endif()

target_link_libraries(${PROJECT_NAME}
config
Expand Down

0 comments on commit 202d818

Please sign in to comment.