diff --git a/CMakeLists.txt b/CMakeLists.txt index 72f8bda3a..81b1e47a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,7 @@ add_subdirectory(plugins) # must precede webgui add_subdirectory(webgui) add_subdirectory(webgui-new) add_subdirectory(webserver) +add_subdirectory(packaging) # Install java libraries install(DIRECTORY diff --git a/Config.cmake b/Config.cmake index 1032ce379..33ead3def 100644 --- a/Config.cmake +++ b/Config.cmake @@ -57,6 +57,9 @@ set(INSTALL_BIN_DIR "bin") set(DATABASE sqlite CACHE STRING "Database type") string(TOUPPER ${DATABASE} DATABASE_U) +# Installation directory for dependencies +set(INSTALL_DEPS_DIR_NAME "deps") + # Set up the dynamic libraries' runtime path to the install folder set(CMAKE_SKIP_BUILD_RPATH FALSE) set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE) diff --git a/doc/deps.md b/doc/deps.md index 221e795fb..796b9d29f 100644 --- a/doc/deps.md +++ b/doc/deps.md @@ -297,3 +297,4 @@ relevant during compilation. | `CODECOMPASS_LINKER` | The path of the linker, if the system's default linker is to be overridden. | | `WITH_PLUGIN`/`WITHOUT_PLUGIN` | The names of the plugins to be built/skipped at build. Possible values are **cpp**, **cpp_reparse**, **dummy**, **git**, **metrics**, **search**. The `metrics` and `search` plugins are fundamental, they will be compiled even if not included. `WITH_PLUGIN` **cannot** be used together with `WITHOUT_PLUGIN`. Example: `-DWITH_PLUGIN="cpp;git"` This will compile the cpp, git, metrics and search plugins. | | `WITH_AUTH` | The names of the authentication plugins to be compiled. Possible values are **plain** and **ldap**. `plain` **cannot** be skipped. Example: `-DWITH_AUTH="plain;ldap"`| +| `INSTALL_RUNTIME_DEPENDENCIES` | If enabled, the required shared objects will be copied to `${CMAKE_INSTALL_PREFIX}/lib/deps/`. Optional, disabled by default. | diff --git a/doc/packaging.md b/doc/packaging.md new file mode 100644 index 000000000..a5666510f --- /dev/null +++ b/doc/packaging.md @@ -0,0 +1,79 @@ +# Packaging +Before running or installing any package verify its checksum: +``` +sha256sum +``` + +# AppImage + +## Running CodeCompass AppImage +Set execution permissions: +``` +chmod +x ./CodeCompass.AppImage +``` + +Run AppImage: +``` +./CodeCompass.AppImage +``` + +AppImage Usage: +``` +./CodeCompass.AppImage parser +``` +``` +./CodeCompass.AppImage webserver +``` +``` +./CodeCompass.AppImage logger +``` + +## Building CodeCompass AppImage + +### appimagetool +To build AppImages, we need to use `appimagetool`. +1. Download `appimagetool-x86_64.AppImage` from https://github.com/AppImage/AppImageKit/releases +2. Place `appimagetool-x86_64.AppImage` into a directory which is added to the `PATH` environmental variable. +3. Set execution permissions: ```chmod +x ./appimagetool-x86_64.AppImage``` +4. Verify `appimagetool-x86_64.AppImage` is runnable from any directory: `which appimagetool-x86_64.AppImage` + +### Building AppImage +First, we need to build CodeCompass. + +Create a build folder: +``` +mkdir build +cd build +``` + +To enable packaging, run CMake with `-DENABLE_PACKAGING=1`: +``` +cmake .. \ + -DCMAKE_INSTALL_PREFIX= \ + -DDATABASE= \ + -DCMAKE_BUILD_TYPE= \ + -DLLVM_DIR=/usr/lib/llvm-11/cmake \ + -DClang_DIR=/usr/lib/cmake/clang-11 \ + -DENABLE_PACKAGING=1 +``` + +Build and install CodeCompass: +``` +make -j $(nproc) +make install -j $(nproc) +``` + +Build AppImage: +``` +make appimage +``` + +The built package will be located in `build/packaging/`. + +## Build options +The built package can be customized by using CMake variables. + +| Variable | Meaning | +| -------------------- | ---------------------------------------- | +| `PACKAGE_VERSION` | Version of the package for the manifest file. If not specified, version `1.0` will be used. | + diff --git a/packaging/CMakeLists.txt b/packaging/CMakeLists.txt new file mode 100644 index 000000000..946728520 --- /dev/null +++ b/packaging/CMakeLists.txt @@ -0,0 +1,43 @@ +# Install shared objects to $CMAKE_INSTALL_PREFIX/lib/deps/ +if(INSTALL_RUNTIME_DEPENDENCIES OR ENABLE_PACKAGING) + install(TARGETS CodeCompass_parser CodeCompass_webserver util gitservice cppparser RUNTIME_DEPENDENCIES LIBRARY DESTINATION "${INSTALL_LIB_DIR}/${INSTALL_DEPS_DIR_NAME}") +endif() + +if(NOT ENABLE_PACKAGING) + return() +endif() + +if(NOT PACKAGE_VERSION) + set(PACKAGE_VERSION "1.0") +endif() + +set(PACKAGE_DIR "codecompass") + +add_custom_target( + appimage + + COMMAND mkdir -p ${PACKAGE_DIR}/usr/ + + COMMAND echo "Adding CodeCompass installation: ${CMAKE_INSTALL_PREFIX}" + COMMAND cp -r ${CMAKE_INSTALL_PREFIX}/* ${PACKAGE_DIR}/usr/ + + COMMAND echo "Removing webgui-new sources ..." + COMMAND rm -rf ${PACKAGE_DIR}/usr/share/codecompass/webgui-new/app/ + + COMMAND cp -r ${CMAKE_SOURCE_DIR}/packaging/appimage/* ${PACKAGE_DIR} + COMMAND chmod +x ${PACKAGE_DIR}/AppRun + + COMMAND echo "---------- AppRun file ----------" + COMMAND cat ${PACKAGE_DIR}/AppRun + COMMAND echo "---------------------------------" + + COMMAND sed -i "s/\%PACKAGE_VERSION\%/${PACKAGE_VERSION}/" ${PACKAGE_DIR}/codecompass.desktop + + COMMAND echo "---------- Desktop file ----------" + COMMAND cat ${PACKAGE_DIR}/codecompass.desktop + COMMAND echo "----------------------------------" + + COMMAND echo "Building CodeCompass AppImage ..." + COMMAND appimagetool-x86_64.AppImage ${PACKAGE_DIR} + COMMAND echo "Done!" +) diff --git a/packaging/appimage/AppRun b/packaging/appimage/AppRun new file mode 100755 index 000000000..7335e6a26 --- /dev/null +++ b/packaging/appimage/AppRun @@ -0,0 +1,27 @@ +#!/usr/bin/env bash + +usage() +{ + echo "CodeCompass AppImage" + echo "Usage:" + echo "./CodeCompass.AppImage parser " + echo "./CodeCompass.AppImage webserver " + echo "./CodeCompass.AppImage logger " +} + +export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$APPDIR/usr/lib/deps/" + +if [ -z "$1" ]; then + usage +elif [ "$1" == "parser" ]; then + shift + exec $APPDIR/usr/bin/CodeCompass_parser "$@" +elif [ "$1" == "webserver" ]; then + shift + exec $APPDIR/usr/bin/CodeCompass_webserver "$@" +elif [ "$1" == "logger" ]; then + shift + exec $APPDIR/usr/bin/CodeCompass_logger "$@" +else + usage +fi diff --git a/packaging/appimage/codecompass.desktop b/packaging/appimage/codecompass.desktop new file mode 100644 index 000000000..fe7828b80 --- /dev/null +++ b/packaging/appimage/codecompass.desktop @@ -0,0 +1,9 @@ +[Desktop Entry] + +Type=Application +Version=%PACKAGE_VERSION% +Name=CodeCompass +Comment=CodeCompass is a pluginable code comprehension tool. +Icon=logo +Terminal=true +Categories=Development; diff --git a/packaging/appimage/logo.png b/packaging/appimage/logo.png new file mode 100644 index 000000000..6e7fef2ba Binary files /dev/null and b/packaging/appimage/logo.png differ