Skip to content

Commit

Permalink
Merge pull request #70 from KIT-MRT/packaging_with_cpack
Browse files Browse the repository at this point in the history
Setup packaging with cpack
  • Loading branch information
orzechow authored Nov 13, 2024
2 parents 545c422 + c0eb7ba commit adc3414
Show file tree
Hide file tree
Showing 63 changed files with 580 additions and 75 deletions.
42 changes: 30 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ project(arbitration_graphs
LANGUAGES CXX
)

# In order to properly support the GUI, we have to decide on an install path upfront (instead of letting CPack decide)
set(CMAKE_INSTALL_PREFIX "/usr")

# Select project features
set(BUILD_GUI "TRUE" CACHE STRING "Compile the project with the WebApp GUI")
set(BUILD_TESTS "FALSE" CACHE STRING "Compile the project with all unit tests")
Expand Down Expand Up @@ -75,7 +78,6 @@ target_link_libraries(${PROJECT_NAME} INTERFACE
util_caching
${YAML_CPP_LIBRARIES}
)
set(INSTALL_TARGETS ${PROJECT_NAME})


###################
Expand Down Expand Up @@ -122,16 +124,32 @@ endif()
## Install ##
#############

install(TARGETS ${INSTALL_TARGETS}
EXPORT ${PROJECT_NAME}Targets
LIBRARY DESTINATION lib COMPONENT Runtime
ARCHIVE DESTINATION lib COMPONENT Development
RUNTIME DESTINATION bin COMPONENT Runtime
PUBLIC_HEADER DESTINATION include COMPONENT Development
BUNDLE DESTINATION bin COMPONENT Runtime
)
install(EXPORT ${PROJECT_NAME}Targets DESTINATION lib/cmake/${PROJECT_NAME})
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}Targets
COMPONENT core
LIBRARY DESTINATION lib COMPONENT Runtime
ARCHIVE DESTINATION lib COMPONENT Development
RUNTIME DESTINATION bin COMPONENT Runtime
PUBLIC_HEADER DESTINATION include COMPONENT Development
BUNDLE DESTINATION bin COMPONENT Runtime)
install(EXPORT ${PROJECT_NAME}Targets
DESTINATION lib/cmake/${PROJECT_NAME}
COMPONENT core)
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION lib/cmake/${PROJECT_NAME})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/ DESTINATION include)
DESTINATION lib/cmake/${PROJECT_NAME}
COMPONENT core)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION include
COMPONENT core
PATTERN "gui" EXCLUDE)


###############
## Packaging ##
###############

include(cpack_config)
include(CPack)

message(STATUS "Components to pack: ${CPACK_COMPONENTS_ALL}")
35 changes: 16 additions & 19 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ RUN apt-get update && \
apt-get install -y \
build-essential \
cmake \
git \
libgoogle-glog-dev \
libgtest-dev \
libyaml-cpp-dev && \
Expand All @@ -17,25 +16,21 @@ RUN apt-get update && \
RUN apt-get update && \
apt-get install -y \
libasio-dev \
unzip \
wget &&\
zlib1g-dev &&\
apt-get clean

# Install Crow (C++ REST/WebSocket server)
RUN cd /tmp && \
wget https://github.com/CrowCpp/Crow/releases/download/v1.2.0/Crow-1.2.0.zip && \
unzip Crow-*.zip -d /tmp && \
cp -r /tmp/Crow-*/* /usr/local && \
rm -r Crow-*

# Install util_caching
RUN git clone https://github.com/KIT-MRT/util_caching.git /tmp/util_caching && \
mkdir /tmp/util_caching/build && \
cd /tmp/util_caching/build && \
cmake .. && \
cmake --build . && \
cmake --install . && \
rm -rf /tmp/util_caching

# Install Crow (C++ REST/WebSocket server) and util_caching

# `ADD` downloads the Crow and util_caching debian releases and adds them to the docker image
# This "bloats" the image. But otherwise, we'd have to installing wget and ca-certificates
# temporarily to download and install the package in one docker layer…
ADD https://github.com/CrowCpp/Crow/releases/download/v1.2.0/Crow-1.2.0-Linux.deb /tmp/debfiles/
ADD https://github.com/KIT-MRT/util_caching/releases/latest/download/libutil-caching-dev.deb /tmp/debfiles/

# Install Crow and util_caching from release debian package
RUN dpkg -i /tmp/debfiles/*.deb && \
rm -rf /tmp/debfiles



Expand All @@ -52,11 +47,13 @@ FROM base AS install

# Install arbitration_graphs
COPY CMakeLists.txt /tmp/arbitration_graphs/
COPY LICENSE /tmp/arbitration_graphs/
COPY README.md /tmp/arbitration_graphs/
COPY version /tmp/arbitration_graphs/
COPY cmake /tmp/arbitration_graphs/cmake
COPY gui /tmp/arbitration_graphs/gui
COPY include /tmp/arbitration_graphs/include
COPY test /tmp/arbitration_graphs/test
COPY version /tmp/arbitration_graphs/version

RUN mkdir /tmp/arbitration_graphs/build && \
cd /tmp/arbitration_graphs/build && \
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,20 @@ Run all unit tests with CTest:
cmake --build . --target test
```


### Serving the WebApp GUI

The GUI consists of
- a web server with static WebApp files, see [`gui/app`](./gui/app)
- a websocket server providing the arbitration graph state to the WebApp

In order to serve the WebApp files, their location must be known to the executable running the web server.
By default (and without further setup), we support these locations:
- the install path, i.e. `/opt/share/arbitration_graphs`
- the current source path for local builds, i.e. `/home/blinky/arbitration_graphs/gui/app/arbitration_graphs` (only works, if no installation has been found)

If you intend to override these, please use the `APP_DIRECTORY` environment variable to define the WebApp path:

```
APP_DIRECTORY=/my/custom/app/path my_awesome_executable
```
42 changes: 42 additions & 0 deletions cmake/cpack_config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# CPACK_PACKAGE_NAME and CPACK_PACKAGE_DESCRIPTION_SUMMARY are loaded from package variables
set(CPACK_PACKAGE_VENDOR "Karlsruhe Institute of Technology")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/KIT-MRT/arbitration_graphs")

set(CPACK_VERBATIM_VARIABLES YES)

set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_BINARY_DIR}/packages")

set(CPACK_DEBIAN_PACKAGE_MAINTAINER "https://github.com/orzechow")

set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")


set(CPACK_GENERATOR "TGZ;ZIP;DEB")

set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}")
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)

set(CPACK_COMPONENTS_GROUPING ONE_PER_GROUP)
set(CPACK_DEB_COMPONENT_INSTALL YES)
set(CPACK_ARCHIVE_COMPONENT_INSTALL YES)

set(CPACK_DEBIAN_PACKAGE_SECTION "libdevel")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "all")


# Rename packages to kebab case
set(CPACK_DEBIAN_CORE_PACKAGE_NAME "libarbitration-graphs-core-dev")
set(CPACK_DEBIAN_GUI_PACKAGE_NAME "libarbitration-graphs-gui-dev")

# Component-specific dependencies (make sure to use upper-case!)
set(CPACK_DEBIAN_CORE_PACKAGE_DEPENDS "libgoogle-glog-dev, libyaml-cpp-dev, libutil-caching-dev")
set(CPACK_DEBIAN_GUI_PACKAGE_DEPENDS "libarbitration-graphs-core-dev, Crow, zlib1g-dev")

# Use fixed debian file names
set(CPACK_DEBIAN_CORE_FILE_NAME "${CPACK_DEBIAN_CORE_PACKAGE_NAME}.deb")
set(CPACK_DEBIAN_GUI_FILE_NAME "${CPACK_DEBIAN_GUI_PACKAGE_NAME}.deb")

# Use CMAKE_INSTALL_PREFIX for CPack install paths aswell
set(CPACK_SET_DESTDIR true)
59 changes: 50 additions & 9 deletions demo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/modules/")
find_package(arbitration_graphs REQUIRED)
find_package(EnTT_Pacman REQUIRED)
find_package(Glog)
find_package(Glog REQUIRED)
find_package(SDL2 REQUIRED)
find_package(util_caching REQUIRED)
find_package(Yaml-cpp REQUIRED)
Expand All @@ -59,7 +59,7 @@ find_package(Yaml-cpp REQUIRED)
## Build ##
###########

add_library(${PROJECT_NAME} STATIC
add_library(${PROJECT_NAME} SHARED
src/astar.cpp
src/avoid_ghost_behavior.cpp
src/change_dot_cluster_behavior.cpp
Expand All @@ -75,12 +75,15 @@ target_include_directories(${PROJECT_NAME} PRIVATE
include
${SDL2_INCLUDE_DIR}
)
target_link_libraries(${PROJECT_NAME} PRIVATE
target_link_libraries(${PROJECT_NAME} PUBLIC
arbitration_graphs
EnTT_Pacman

glog::glog
util_caching
${SDL2_LIBRARY}
${YAML_CPP_LIBRARIES}

EnTT_Pacman
${SDL2_LIBRARY}
)

add_executable(${PROJECT_NAME}_exe
Expand All @@ -93,10 +96,24 @@ target_include_directories(${PROJECT_NAME}_exe PRIVATE
)
target_link_libraries(${PROJECT_NAME}_exe PRIVATE
${PROJECT_NAME}
EnTT_Pacman
util_caching
${SDL2_LIBRARY}
${YAML_CPP_LIBRARIES}
)


###################
## Cmake Package ##
###################

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
VERSION 0.1
COMPATIBILITY AnyNewerVersion
)
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME}
)


Expand All @@ -110,3 +127,27 @@ if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME OR ARBITRATION_GRAPHS_DEMO_CMAKE_BU
AND BUILD_TESTS)
add_subdirectory(test)
endif()


#############
## Install ##
#############

install(TARGETS ${PROJECT_NAME} ${PROJECT_NAME}_exe
EXPORT ${PROJECT_NAME}Targets
COMPONENT demo
LIBRARY DESTINATION lib COMPONENT Runtime
ARCHIVE DESTINATION lib COMPONENT Development
RUNTIME DESTINATION bin COMPONENT Runtime
PUBLIC_HEADER DESTINATION include COMPONENT Development
BUNDLE DESTINATION bin COMPONENT Runtime)
install(EXPORT ${PROJECT_NAME}Targets
DESTINATION lib/cmake/${PROJECT_NAME}
COMPONENT demo)
install(FILES "${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
DESTINATION lib/cmake/${PROJECT_NAME}
COMPONENT demo)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/
DESTINATION include
COMPONENT demo)
1 change: 1 addition & 0 deletions demo/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
cmake \
git \
libsdl2-dev && \
apt-get clean

Expand Down
4 changes: 4 additions & 0 deletions demo/cmake/arbitration_graphs_pacman_demoConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
2 changes: 1 addition & 1 deletion demo/include/demo/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <utility>
#include <vector>

#include <SDL_scancode.h>
#include <SDL2/SDL_scancode.h>
#include <arbitration_graphs/types.hpp>
#include <entt/entity/registry.hpp>
#include <pacman/comp/dir.hpp>
Expand Down
2 changes: 1 addition & 1 deletion demo/include/utils/pacman_wrapper.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <SDL.h>
#include <SDL2/SDL.h>

#include <pacman/core/game.hpp>
#include <pacman/util/sdl_delete.hpp>
Expand Down
2 changes: 1 addition & 1 deletion demo/src/pacman_wrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "utils/pacman_wrapper.hpp"

#include <SDL_main.h>
#include <SDL2/SDL_main.h>

#include <pacman/core/constants.hpp>
#include <pacman/util/frame_cap.hpp>
Expand Down
Loading

0 comments on commit adc3414

Please sign in to comment.