Skip to content

Commit

Permalink
feature: enabled full installation using cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart-Steensma committed Feb 20, 2024
1 parent efe7243 commit 5288440
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 46 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@ jobs:
./scripts/configure -- -DBUILD_TESTING=OFF
cmake --build ./build --target package
- name: Run test
run: |
ctest --test-dir ./build --verbose
- name: Publish
uses: "marvinpinto/action-automatic-releases@latest"
with:
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ jobs:
run: |
./scripts/configure -- -DBUILD_TESTING=ON
cmake --build ./build --target package
sudo cmake --install ./build
- name: Run test
- name: Run ctest
run: |
ctest --test-dir ./build --verbose
- name: Run installed tests
run: |
/opt/snapshot/snapshot_tests
- name: Run test tarball
run: |
tar -xvf ./build/snapshot-*.tar.gz -C /tmp
Expand Down
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
include(${CMAKE_SOURCE_DIR}/cmake/Version.cmake)
include(${CMAKE_SOURCE_DIR}/cmake/Install.cmake)

cmake_minimum_required(VERSION 3.5)
project(snapshot LANGUAGES CXX)
Expand All @@ -19,10 +20,11 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

set(INSTALL_SCRIPTS
${CMAKE_SOURCE_DIR}/scripts/install
CACHE PATH "Install scripts")
set(CMAKE_INSTALL_PREFIX /opt/${PROJECT_NAME})
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION_FULL})
set(CPACK_GENERATOR "TGZ")
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")

configure_file(${CMAKE_SOURCE_DIR}/include/version.h.in
${CMAKE_SOURCE_DIR}/include/version.h @ONLY)
Expand All @@ -35,4 +37,7 @@ if(BUILD_TESTING)
add_subdirectory(tests)
endif()

set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION_FULL})
set(CPACK_GENERATOR "TGZ")
include(CPack)
53 changes: 32 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,40 @@ online installer of Qt which is included in this project. Do the following:
- Install the project:

```bash
cmake --install ./build
sudo cmake --install ./build
```

- TODO: test installing the project for both static and shared qt builds.
- TODO: explain why `/opt` is used instead of `/usr/local`:
- `/opt` is for self contained packages. This way, libs and bins are not
migled with those in local.
- Can be easily uninstalled by removing the `/opt/snapshot` directory +
symlink.
- This way, I can keep the tarball and the `cmake --install` identical to
each other.
- TODO: make a symlonk from `/opt/snapshot/run_snapshot` to
`/usr/local/bin/snapshot`
This will install the project in the `/opt/snapshot` directory. The `/opt`
directory is chosen as `snapshot` is a self-contained application. The
installed files tree is as follows:

```bash
/opt/snapshot
├── runtime/
│ └── libs, bins, and qt plugins
└── snapshot
```

Where `snapshot` is the entry point of the application. If you want to
add the `snapshot` executable to your `PATH`, you can create a symlink to
`/usr/local/bin`:

```bash
sudo ln -s /opt/snapshot/snapshot /usr/local/bin/snapshot
```

Or you can add the `/opt/snapshot` directory to your `PATH`.

If you have no root access, you can install the project in you home directory
by using the `--prefix` option. For example, if you want to install the
project in the `$HOME/opt/snapshot` directory, you can run the following:

```bash
cmake --install ./build --prefix $HOME/opt/snapshot
```

This will install the project in the `$HOME/opt/snapshot` directory, instead
of the `/opt/snapshot` directory.

#### Building

Expand Down Expand Up @@ -654,16 +675,6 @@ more information.

# TODO:

- [ ] currently, all plugins are installed, the regexes are not working.
- [ ] Configure `cmake --install` for both static and shared qt builds. This is
needed after building the project from source.
- [ ] Ensure that the tarball can also be made using the --shared option.
- How to load plugins using a shared Qt build is explained [here](https://doc.qt.io/qt-6/linux-deployment.html)
Follow the conventions they use. See the tmp commit.
- It would be good to run the unittest on the tarball aswel, to ensure that
all the so files are included. Best idea is to create the same tarball as
the release, but with the tests included (with gtest). Then run the tests
like you run the snapshot executable, through a bash script.
- [ ] Cross compile for raspberry pi
- [ ] Release a 64bit and a 32bit version of the app
- [ ] Add to docs:
Expand Down
2 changes: 1 addition & 1 deletion app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ add_executable(snapshot_bin main.cpp
${CMAKE_SOURCE_DIR}/resources/resources.qrc)
target_link_libraries(snapshot_bin PRIVATE snapshot)

install(PROGRAMS ${CMAKE_SOURCE_DIR}/scripts/run_snapshot DESTINATION .)
install(PROGRAMS ${INSTALL_SCRIPTS}/snapshot DESTINATION .)
install_with_runtime_dependencies(snapshot_bin)

if(QT6_LIB_TYPE STREQUAL "SHARED_LIBRARY")
Expand Down
2 changes: 1 addition & 1 deletion cmake/Find.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ endfunction()
# https://github.com/shiguredo/sora-cpp-sdk/blob/develop/cmake/FindLibdrm.cmake
# The script not modified.
function(find_libdrm)
find_package(Libdrm REQUIRED)
find_package(Libdrm QUIET)
find_package(PkgConfig)

pkg_check_modules(Libdrm libdrm)
Expand Down
16 changes: 8 additions & 8 deletions cmake/Install.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function(install_with_runtime_dependencies binary)

install(
TARGETS ${binary}
DESTINATION .
DESTINATION runtime
RUNTIME_DEPENDENCIES DIRECTORIES ${FFMPEG_LIBRARY_DIRS}
POST_EXCLUDE_REGEXES ${exclude_c_libs_regex})
endfunction()
Expand All @@ -29,7 +29,7 @@ macro(install_qt_shared_plugins)
${_plugin_dir}/platforms/libqwayland-egl.so
${_plugin_dir}/platforms/libqwayland-generic.so
${_plugin_dir}/platforms/libqxcb.so
DESTINATION platforms)
DESTINATION runtime/platforms)

# Support all the wayland graphics integrations, except emulation.
install(
Expand All @@ -38,26 +38,26 @@ macro(install_qt_shared_plugins)
${_plugin_dir}/wayland-graphics-integration-client/libdrm-egl-server.so
${_plugin_dir}/wayland-graphics-integration-client/libqt-plugin-wayland-egl.so
${_plugin_dir}/wayland-graphics-integration-client/libvulkan-server.so
DESTINATION wayland-graphics-integration-client)
DESTINATION runtime/wayland-graphics-integration-client)

# X11 support for eglfs can be used by Raspberry Pi.
install(
FILES ${_plugin_dir}/egldeviceintegrations/libqeglfs-x11-integration.so
DESTINATION egldeviceintegrations)
DESTINATION runtime/egldeviceintegrations)

# Jpeg is needded for image support.
install(FILES ${_plugin_dir}/imageformats/libqjpeg.so
DESTINATION imageformats)
DESTINATION runtime/imageformats)

# Only ffmpeg is supported.
install(FILES ${_plugin_dir}/multimedia/libffmpegmediaplugin.so
DESTINATION multimedia)
DESTINATION runtime/multimedia)

# Support both egl and glx.
install(DIRECTORY ${_plugin_dir}/xcbglintegrations/
DESTINATION xcbglintegrations)
DESTINATION runtime/xcbglintegrations)

# Support all shells
install(DIRECTORY ${_plugin_dir}/wayland-shell-integration/
DESTINATION wayland-shell-integration)
DESTINATION runtime/wayland-shell-integration)
endmacro()
2 changes: 1 addition & 1 deletion scripts/run_snapshot → scripts/install/snapshot
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ this_dir=$(cd -P "$(dirname "$source")" >/dev/null 2>&1 && pwd)

LD_LIBRARY_PATH="$this_dir"
export LD_LIBRARY_PATH
"$this_dir/snapshot_bin" "$@"
"$this_dir/runtime/snapshot_bin" "$@"
7 changes: 3 additions & 4 deletions scripts/run_tests → scripts/install/snapshot_tests
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ while [ -L "$source" ]; do
done
this_dir=$(cd -P "$(dirname "$source")" >/dev/null 2>&1 && pwd)

LD_LIBRARY_PATH="$this_dir"
export LD_LIBRARY_PATH
export LD_LIBRARY_PATH="$this_dir"
export QT_QPA_PLATFORM=offscreen
ldd "$this_dir/tests_bin" | grep "not found" && exit 1
"$this_dir/tests_bin" "$@"

ldd "$this_dir/runtime/tests_bin" | grep "not found" && exit 1
"$this_dir/runtime/tests_bin" "$@"
4 changes: 2 additions & 2 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ add_test(NAME tests_bin COMMAND tests_bin)
set_tests_properties(tests_bin PROPERTIES ENVIRONMENT
"QT_QPA_PLATFORM=offscreen")

install(PROGRAMS ${CMAKE_SOURCE_DIR}/scripts/run_tests DESTINATION .)
install(DIRECTORY static DESTINATION .)
install(PROGRAMS ${INSTALL_SCRIPTS}/snapshot_tests DESTINATION .)
install(DIRECTORY static DESTINATION runtime)
install_with_runtime_dependencies(tests_bin)

0 comments on commit 5288440

Please sign in to comment.