From db47a4cb835cf1ba4a03d6660788594864db480b Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 25 Oct 2023 08:22:37 +0200 Subject: [PATCH 1/4] Overall improvements to CMake files with respect to properly installation Signed-off-by: Christian Parpart --- CMakeLists.txt | 9 +++- libtermbench/CMakeLists.txt | 66 ++++++++++++++++++++++---- libtermbench/termbench-config.cmake.in | 8 ++++ termbenchpro/CMakeLists.txt | 14 +++++- 4 files changed, 86 insertions(+), 11 deletions(-) create mode 100644 libtermbench/termbench-config.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 8eeb7a5..42492a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -project(termbench-pro VERSION "${CONTOUR_VERSION}" LANGUAGES CXX) +project(termbench-pro VERSION "0.2.0" LANGUAGES CXX) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS ON) @@ -14,6 +14,11 @@ if(NOT WIN32 AND NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release MinSizeRel RelWithDebInfo) endif() +set(MASTER_PROJECT OFF) +if(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_SOURCE_DIR}) + set(MASTER_PROJECT ON) +endif() + include(EnableCcache) include(ClangTidy) include(PedanticCompiler) diff --git a/libtermbench/CMakeLists.txt b/libtermbench/CMakeLists.txt index 4aa1010..64caf4b 100644 --- a/libtermbench/CMakeLists.txt +++ b/libtermbench/CMakeLists.txt @@ -1,12 +1,62 @@ -add_library(termbench - termbench.cpp termbench.h -) +include(GNUInstallDirs) + +set(_TERMBENCH_LIB_BUILD_MODE) +if(MASTER_PROJECT) + set(_TERMBENCH_LIB_BUILD_MODE "SHARED") +else() + set(_TERMBENCH_LIB_BUILD_MODE "STATIC") +endif() +set(TERMBENCH_LIB_BUILD_MODE ${_TERMBENCH_LIB_BUILD_MODE} CACHE STRING "Choose the build mode." FORCE) +set_property(CACHE TERMBENCH_LIB_BUILD_MODE PROPERTY STRINGS "STATIC" "SHARED") +message(STATUS "termbench library build mode: ${TERMBENCH_LIB_BUILD_MODE}") + +set(_PUBLIC_HEADERS termbench.h) +add_library(termbench ${TERMBENCH_LIB_BUILD_MODE} termbench.cpp) +add_library(termbench::termbench ALIAS termbench) +target_compile_features(termbench PUBLIC cxx_std_20) +set_target_properties(termbench PROPERTIES + PUBLIC_HEADER "${_PUBLIC_HEADERS}" +) +set_target_properties(termbench PROPERTIES + VERSION "${PROJECT_VERSION}" + SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}" +) target_link_libraries(termbench PUBLIC fmt::fmt-header-only) -target_compile_features(termbench PUBLIC cxx_std_17) -target_include_directories(termbench PUBLIC - ${CMAKE_SOURCE_DIR} - $ - $ +target_include_directories(termbench PUBLIC $ + $) + +install(TARGETS termbench + EXPORT termbench-targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/termbench" + PRIVATE_HEADER DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/termbench" + FRAMEWORK DESTINATION "." + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +# {{{ Generate the version, config and target files +include(CMakePackageConfigHelpers) + +write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/termbench-config-version.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY SameMajorVersion +) + +configure_package_config_file(termbench-config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/termbench-config.cmake + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/termbench +) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/termbench-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/termbench-config-version.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/termbench +) + +install(EXPORT termbench-targets + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/termbench + NAMESPACE termbench:: ) +# }}} diff --git a/libtermbench/termbench-config.cmake.in b/libtermbench/termbench-config.cmake.in new file mode 100644 index 0000000..c08f1a8 --- /dev/null +++ b/libtermbench/termbench-config.cmake.in @@ -0,0 +1,8 @@ +@PACKAGE_INIT@ + +# prevent repeatedly including the targets +if(NOT TARGET termbench::termbench) + include(${CMAKE_CURRENT_LIST_DIR}/termbench-targets.cmake) +endif() + +message(STATUS "Found @PROJECT_NAME@, version: ${@PROJECT_NAME@_VERSION}") diff --git a/termbenchpro/CMakeLists.txt b/termbenchpro/CMakeLists.txt index 82f8c0d..4e537c0 100644 --- a/termbenchpro/CMakeLists.txt +++ b/termbenchpro/CMakeLists.txt @@ -1,2 +1,14 @@ +include(GNUInstallDirs) + add_executable(tbp main.cpp) -target_link_libraries(tbp PRIVATE termbench fmt::fmt-header-only) +target_link_libraries(tbp PRIVATE termbench::termbench fmt::fmt-header-only) + +# Set the RPATH so that the executable can find the shared libraries +# when installed in a non-standard location +set_target_properties(tbp PROPERTIES + INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" + INSTALL_RPATH_USE_LINK_PATH TRUE +) + +install(TARGETS tbp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) + From 3b6896cf3d932747b4021300b4f6bb6a90dee11c Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 25 Oct 2023 08:23:58 +0200 Subject: [PATCH 2/4] rename `tbp` executable to `tb` Signed-off-by: Christian Parpart --- {termbenchpro => tb}/CMakeLists.txt | 8 ++++---- {termbenchpro => tb}/main.cpp | 0 2 files changed, 4 insertions(+), 4 deletions(-) rename {termbenchpro => tb}/CMakeLists.txt (54%) rename {termbenchpro => tb}/main.cpp (100%) diff --git a/termbenchpro/CMakeLists.txt b/tb/CMakeLists.txt similarity index 54% rename from termbenchpro/CMakeLists.txt rename to tb/CMakeLists.txt index 4e537c0..b5c47b5 100644 --- a/termbenchpro/CMakeLists.txt +++ b/tb/CMakeLists.txt @@ -1,14 +1,14 @@ include(GNUInstallDirs) -add_executable(tbp main.cpp) -target_link_libraries(tbp PRIVATE termbench::termbench fmt::fmt-header-only) +add_executable(tb main.cpp) +target_link_libraries(tb PRIVATE termbench::termbench fmt::fmt-header-only) # Set the RPATH so that the executable can find the shared libraries # when installed in a non-standard location -set_target_properties(tbp PROPERTIES +set_target_properties(tb PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" INSTALL_RPATH_USE_LINK_PATH TRUE ) -install(TARGETS tbp RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(TARGETS tb RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/termbenchpro/main.cpp b/tb/main.cpp similarity index 100% rename from termbenchpro/main.cpp rename to tb/main.cpp From ee4144e5996a1a690c53c4530da02d30171e9ba6 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 25 Oct 2023 08:26:28 +0200 Subject: [PATCH 3/4] Initiate renaming the project from termbench-pro to termbench Signed-off-by: Christian Parpart --- CMakeLists.txt | 4 ++-- README.md | 7 +++---- libtermbench/termbench.cpp | 2 +- libtermbench/termbench.h | 2 +- tb/main.cpp | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42492a5..1b40f21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -project(termbench-pro VERSION "0.2.0" LANGUAGES CXX) +project(termbench VERSION "0.2.0" LANGUAGES CXX) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -33,4 +33,4 @@ if(NOT TARGET fmt) endif() add_subdirectory(libtermbench) -add_subdirectory(termbenchpro) +add_subdirectory(tb) diff --git a/README.md b/README.md index 06566c5..eeecce1 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,8 @@ -# termbench-pro +# termbench -Termbench Pro is the interim name for a project to benchmark -the terminal emulators backend bandwidth throughput. +Termbench is a project to benchmark the terminal emulators backend bandwidth throughput. -Therefore not just a CLI executable will be provided but also a library +Therefore not just a CLI executable (`tb`) will be provided but also a library that one can link against to test against your own terminal emulator backend without being affected by your rendering pipeline. diff --git a/libtermbench/termbench.cpp b/libtermbench/termbench.cpp index 0a4b0aa..5455f45 100644 --- a/libtermbench/termbench.cpp +++ b/libtermbench/termbench.cpp @@ -1,5 +1,5 @@ /** - * This file is part of the "termbench-pro" project + * This file is part of the "termbench" project * Copyright (c) 2021 Christian Parpart * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/libtermbench/termbench.h b/libtermbench/termbench.h index 366e8ad..ec0f64c 100644 --- a/libtermbench/termbench.h +++ b/libtermbench/termbench.h @@ -1,5 +1,5 @@ /** - * This file is part of the "termbench-pro" project + * This file is part of the "termbench" project * Copyright (c) 2021 Christian Parpart * * Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tb/main.cpp b/tb/main.cpp index 822cb27..d576993 100644 --- a/tb/main.cpp +++ b/tb/main.cpp @@ -1,5 +1,5 @@ /** - * This file is part of the "termbench-pro" project + * This file is part of the "termbench" project * Copyright (c) 2021 Christian Parpart * * Licensed under the Apache License, Version 2.0 (the "License"); From f1209019ceff225c7d914281f79a2b6d8a688475 Mon Sep 17 00:00:00 2001 From: Christian Parpart Date: Wed, 25 Oct 2023 08:32:59 +0200 Subject: [PATCH 4/4] Fix CI pipeline Signed-off-by: Christian Parpart --- .github/workflows/build.yml | 87 +++++++------------------------------ scripts/install-deps.sh | 3 +- tb/CMakeLists.txt | 2 +- vcpkg.json | 7 +++ 4 files changed, 26 insertions(+), 73 deletions(-) create mode 100644 vcpkg.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 308499c..428b1b7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -11,59 +11,28 @@ on: - '*.sh' branches: - master - - feature/** - - fix/** - - improvement/** pull_request: branches: - master +concurrency: + group: ${{ github.ref }} + cancel-in-progress: true + env: CTEST_OUTPUT_ON_FAILURE: 1 - CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules jobs: - ubuntu_2004: - name: "Ubuntu Linux 20.04" - runs-on: ubuntu-20.04 + ubuntu_linux: + name: "Ubuntu Linux 22.04" + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: "**/cpm_modules" - key: ${{github.workflow}}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} - - name: set environment variables - id: set_vars - run: ./scripts/ci-set-vars.sh - env: - REPOSITORY: ${{ github.event.repository.name }} - - name: "install dependencies" - run: | - set -ex - sudo apt -q update - sudo ./scripts/install-deps.sh - - name: "create build directory" - run: mkdir build - - name: "cmake" - run: | - BUILD_DIR="build" \ - CMAKE_BUILD_TYPE="RelWithDebInfo" \ - CXX="g++-9" \ - EXTRA_CMAKE_FLAGS="" \ - ./scripts/ci-prepare-contour.sh - - name: "build" - run: cmake --build build/ -- -j3 - - ubuntu1804: - name: "Ubuntu Linux 18.04" - runs-on: ubuntu-18.04 - steps: - - name: Checkout code - uses: actions/checkout@v2 - - uses: actions/cache@v2 + - name: ccache + uses: hendrikmuhs/ccache-action@v1 with: - path: "**/cpm_modules" - key: ${{github.workflow}}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} + key: "ccache-ubuntu_2204" + max-size: 256M - name: set environment variables id: set_vars run: ./scripts/ci-set-vars.sh @@ -74,17 +43,8 @@ jobs: set -ex sudo apt -q update sudo ./scripts/install-deps.sh - - name: "Get specific version CMake, v3.18.3" - uses: lukka/get-cmake@v3.18.3 - - name: "create build directory" - run: mkdir build - name: "cmake" - run: | - BUILD_DIR="build" \ - CMAKE_BUILD_TYPE="Release" \ - CXX="g++-8" \ - EXTRA_CMAKE_FLAGS="-DCONTOUR_BLUR_PLATFORM_KWIN=ON -DUSE_BOOST_FILESYSTEM=ON" \ - ./scripts/ci-prepare-contour.sh + run: cmake -S . -B build -DCMAKE_BUILD_TYPE="RelWithDebInfo" - name: "build" run: cmake --build build/ -- -j3 @@ -110,14 +70,7 @@ jobs: - name: "Create build directory" run: mkdir build - name: "Generate build files" - run: | - cmake . \ - -DCMAKE_BUILD_TYPE=Release \ - -DYAML_BUILD_SHARED_LIBS=OFF -DYAML_CPP_BUILD_CONTRIB=OFF \ - -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF \ - -DYAML_CPP_INSTALL=OFF \ - -DQt5_DIR="$(brew --prefix qt5)/lib/cmake/Qt5" \ - -B build/ + run: cmake -S . -B build -DCMAKE_BUILD_TYPE="RelWithDebInfo" - name: "Build" run: cmake --build build/ @@ -126,26 +79,18 @@ jobs: runs-on: windows-latest steps: - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: "**/cpm_modules" - key: ${{github.workflow}}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }} - name: setup environment shell: powershell id: set_vars run: .\scripts\ci-set-vars.ps1 env: REPOSITORY: ${{ github.event.repository.name }} - - name: Install Qt - uses: jurplel/install-qt-action@v2 - name: "vcpkg: Install dependencies" - uses: lukka/run-vcpkg@v5 + uses: lukka/run-vcpkg@v11.1 id: runvcpkg with: - vcpkgArguments: freetype fontconfig harfbuzz vcpkgDirectory: ${{ runner.workspace }}/vcpkg/ - vcpkgGitCommitId: b063d0cee7389514a0841cf1e2e055d6466fe4b8 - vcpkgTriplet: x64-windows + vcpkgGitCommitId: 3e93bb69a1cadeb36fe9eca3b6f3912d84f618d5 - name: "create build directory" shell: powershell run: | @@ -154,6 +99,6 @@ jobs: New-Item -ItemType Directory -Force -Path build } - name: "Generate build files" - run: cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${{ runner.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows -DYAML_BUILD_SHARED_LIBS=OFF -DCONTOUR_EXAMPLES=OFF -DLIBTERMINAL_TESTING=ON -DLIBUNICODE_TESTING=ON -DYAML_CPP_BUILD_CONTRIB=OFF -DYAML_CPP_BUILD_TESTS=OFF -DYAML_CPP_BUILD_TOOLS=OFF -DYAML_CPP_INSTALL=OFF -B build . + run: cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE="${{ runner.workspace }}/vcpkg/scripts/buildsystems/vcpkg.cmake" -DVCPKG_TARGET_TRIPLET=x64-windows -B build . - name: "Build" run: cmake --build build/ --config Release diff --git a/scripts/install-deps.sh b/scripts/install-deps.sh index 3f8d824..3fcb4c6 100755 --- a/scripts/install-deps.sh +++ b/scripts/install-deps.sh @@ -11,6 +11,7 @@ install_deps_ubuntu() cmake g++ make + libfmt-dev ) if [[ "${RELEASE}" < "19.04" ]]; then @@ -37,7 +38,7 @@ main_linux() main_darwin() { # brew install cmake clang? - return + brew install fmt } main() diff --git a/tb/CMakeLists.txt b/tb/CMakeLists.txt index b5c47b5..08f91d4 100644 --- a/tb/CMakeLists.txt +++ b/tb/CMakeLists.txt @@ -1,7 +1,7 @@ include(GNUInstallDirs) add_executable(tb main.cpp) -target_link_libraries(tb PRIVATE termbench::termbench fmt::fmt-header-only) +target_link_libraries(tb PRIVATE termbench fmt::fmt-header-only) # Set the RPATH so that the executable can find the shared libraries # when installed in a non-standard location diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..a1c6752 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,7 @@ +{ + "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json", + "dependencies": [ + "catch2", + "fmt" + ] +}