Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,55 @@ jobs:
--legend coverage_without_system_and_test_files
lcov --list coverage_without_system_and_test_files
shell: alpine.sh {0}
- uses: actions/upload-artifact@v4
with:
name: coverage_${{ matrix.cpp_version }}
path: coverage
retention-days: 3

ctest:
name: "ctest"
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v4
with:
name: build_alpine-v3.20_g++_cpp17
path: build
- name: Fix artifact permissions
run: chmod +x build/test/tests

- uses: jirutka/setup-alpine@v1
with:
branch: v3.20
packages: >
cmake
ninja-build
g++
boost-dev
boost-filesystem
boost-python3
lua5.2-dev
python3-dev
fmt-dev
gtest-dev
- name: Fixup environment
run: |
ln -s /usr/lib/ninja-build/bin/ninja /usr/bin/ninja
ln -s liblua-5.2.so.0 /usr/lib/liblua-5.2.so
shell: alpine.sh --root {0}

- name: Run cmake tests
run: |
cd build
ctest -R cmake_ --output-on-failure
env:
CMAKE_GENERATOR: Ninja
shell: alpine.sh {0}
- uses: actions/upload-artifact@v4
if: success() || failure()
with:
name: cmake_tests_results
path: build/Testing/Temporary
retention-days: 2
2 changes: 1 addition & 1 deletion .github/workflows/cmake-format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
run: find . \( -path '*/.*' -prune \) -o
\( -type f -a -name 'CMakeLists.txt' \)
-exec echo "Format checking '{}'..." \;
-exec cmake-format --check -- {} +
-exec cmake-format --check --line-width=80 -- {} +
10 changes: 6 additions & 4 deletions .github/workflows/cmake-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ jobs:
python-version: '3.13'
cache-dependency-path: '.github/workflows/cmake-lint.yml'
cache: 'pip'
- name: Install dependencies
run: pip install cmakelint
- name: Install CMake linting tool
run: pip install cmakelang

- name: Execute cmakelint
# Check all cmake files; ignore files in hidden directories;
# use increased line width since formatting is checked by other workflow
- name: Execute cmake-lint
run: find . \( \( -path './build' -o -path '*/.*' \) -prune \) -o
\( -type f -a -iname 'CMakeLists.txt' \)
-exec echo "Linting '{}'..." \;
-exec cmakelint --spaces=1 {} +
-exec cmake-lint --line-width=90 -- {} +
5 changes: 2 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ option(PPPLUGIN_ENABLE_UNDEFINED_SANITIZE
option(PPPLUGIN_ENABLE_UNREACHABLE_SANITIZE
"Enable compilation with unreachable sanitize flags" OFF)

find_package(Boost 1.61.0 REQUIRED COMPONENTS headers filesystem)
find_package(Boost 1.70.0 REQUIRED CONFIG COMPONENTS headers filesystem)
find_package(Python 3.0 REQUIRED COMPONENTS Development)
find_package(Lua 5.2 REQUIRED)

Expand Down Expand Up @@ -60,8 +60,6 @@ set(DEBUG_FLAGS "-g3")
if(${PPPLUGIN_ENABLE_CPP17_COMPATIBILITY})
find_package(fmt 8.1.0 REQUIRED)
set(CMAKE_CXX_STANDARD 17)
# TODO: generate C++17 compatible header files instead
add_definitions("-DPPPLUGIN_CPP17_COMPATIBILITY")
else()
set(CMAKE_CXX_STANDARD 20)
endif()
Expand Down Expand Up @@ -129,5 +127,6 @@ if(${PPPLUGIN_ENABLE_EXAMPLES})
add_subdirectory(examples)
endif()
if(${PPPLUGIN_ENABLE_TESTS})
enable_testing()
add_subdirectory(test)
endif()
4 changes: 4 additions & 0 deletions cmake/ppplugin-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ find_dependency(Boost @Boost_VERSION_MAJOR@ COMPONENTS headers filesystem
find_dependency(Python @Python_VERSION_MAJOR@ COMPONENTS Development)
find_dependency(Lua @LUA_VERSION_MAJOR@)

if(${PPPLUGIN_ENABLE_CPP17_COMPATIBILITY})
find_dependency(fmt @fmt_VERSION_MAJOR@)
endif()

check_required_components("@PROJECT_NAME@")

set(PPPLUGIN_INCLUDE_DIR ${PACKAGE_PREFIX_DIR}/include)
Expand Down
3 changes: 2 additions & 1 deletion examples/lua_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/plugin.lua
$<TARGET_FILE_DIR:lua_plugin_manager>/plugin_1.lua
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/plugin.lua
$<TARGET_FILE_DIR:lua_plugin_manager>/plugin_2.lua)
$<TARGET_FILE_DIR:lua_plugin_manager>/plugin_2.lua
COMMENT "Copying Lua plugins to output directory...")
8 changes: 3 additions & 5 deletions examples/multi_language_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ add_custom_command(
POST_BUILD
COMMAND
${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/plugins/lua_plugin.lua
$<TARGET_FILE_DIR:multi_language_plugin_manager>)
add_custom_command(
TARGET multi_language_plugin_manager
POST_BUILD
$<TARGET_FILE_DIR:multi_language_plugin_manager>
COMMAND
${CMAKE_COMMAND} -E copy
${CMAKE_CURRENT_SOURCE_DIR}/plugins/python_plugin.py
$<TARGET_FILE_DIR:multi_language_plugin_manager>)
$<TARGET_FILE_DIR:multi_language_plugin_manager>
COMMENT "Copying plugins to output directory...")
3 changes: 2 additions & 1 deletion examples/multi_return_lua_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ add_custom_command(
TARGET multi_return_lua_plugin_manager
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/plugin.lua
$<TARGET_FILE_DIR:multi_return_lua_plugin_manager>)
$<TARGET_FILE_DIR:multi_return_lua_plugin_manager>
COMMENT "Copying Lua plugin to output directory...")
3 changes: 2 additions & 1 deletion examples/python_plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ add_custom_command(
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/plugin.py
$<TARGET_FILE_DIR:python_plugin_manager>/plugin_1.py
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/plugin.py
$<TARGET_FILE_DIR:python_plugin_manager>/plugin_2.py)
$<TARGET_FILE_DIR:python_plugin_manager>/plugin_2.py
COMMENT "Copying Python plugins to output directory...")
1 change: 0 additions & 1 deletion include/ppplugin/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include "ppplugin/detail/compatibility_utils.h"
#include "ppplugin/expected.h"

#include <memory>
#ifndef PPPLUGIN_CPP17_COMPATIBILITY
#include <source_location>
#endif // PPPLUGIN_CPP17_COMPATIBILITY
Expand Down
2 changes: 1 addition & 1 deletion include/ppplugin/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <cassert>
#include <optional>
#include <variant>
#if __cplusplus >= 202101L
#if __cplusplus >= 202101L // if C++23 is available
#include <expected>
#endif // __cplusplus

Expand Down
1 change: 1 addition & 0 deletions include/ppplugin/lua/lua_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ppplugin/errors.h"

#include <functional>
#include <memory>
#include <optional>

struct lua_State;
Expand Down
12 changes: 8 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@ set(LIBRARY_SOURCES
add_library(${LIBRARY_TARGET} ${LIBRARY_SOURCES})
target_link_libraries(
${LIBRARY_TARGET}
PUBLIC Boost::filesystem
PUBLIC Python::Python
PRIVATE ${LUA_LIBRARIES}
PUBLIC $<$<BOOL:${PPPLUGIN_ENABLE_CPP17_COMPATIBILITY}>:fmt::fmt>)
PUBLIC Boost::filesystem Python::Python
$<$<BOOL:${PPPLUGIN_ENABLE_CPP17_COMPATIBILITY}>:fmt::fmt>)
target_include_directories(
${LIBRARY_TARGET}
PRIVATE ${LUA_INCLUDE_DIR}
PUBLIC $<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>
PUBLIC $<INSTALL_INTERFACE:include/${PROJECT_NAME}>)
$<INSTALL_INTERFACE:include/${PROJECT_NAME}>)
target_compile_definitions(
${LIBRARY_TARGET}
PUBLIC
$<$<BOOL:${PPPLUGIN_ENABLE_CPP17_COMPATIBILITY}>:"PPPLUGIN_CPP17_COMPATIBILITY">
)

set_target_properties(
${LIBRARY_TARGET}
Expand Down
55 changes: 52 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,55 @@ add_executable(${TESTS_NAME} detail_templates_tests.cpp expected_tests.cpp
scope_guard_tests.cpp)

target_include_directories(${TESTS_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include)
target_link_libraries(
${TESTS_NAME} PRIVATE GTest::GTest GTest::Main gmock Threads::Threads
${LIBRARY_TARGET_STATIC})
target_link_libraries(${TESTS_NAME} PRIVATE GTest::GTest GTest::Main gmock
Threads::Threads ${LIBRARY_TARGET})

gtest_discover_tests(${TESTS_NAME})

add_test(
NAME cmake_shared_cpp17_compatible_installation_test
COMMAND
test.sh ${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/cmake_find_package_test_build
${CMAKE_CURRENT_BINARY_DIR}/test_install_root_shared_cpp17 "SHARED" "Cpp17"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake_tests/find_package_test)
add_test(
NAME cmake_shared_cpp20_compatible_installation_test
COMMAND
test.sh ${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/cmake_find_package_test_build
${CMAKE_CURRENT_BINARY_DIR}/test_install_root_shared_cpp20 "SHARED" "Cpp20"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake_tests/find_package_test)
add_test(
NAME cmake_static_cpp17_compatible_installation_test
COMMAND
test.sh ${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/cmake_find_package_test_build
${CMAKE_CURRENT_BINARY_DIR}/test_install_root_static_cpp17 "STATIC" "Cpp17"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake_tests/find_package_test)
add_test(
NAME cmake_static_cpp20_compatible_installation_test
COMMAND
test.sh ${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/cmake_find_package_test_build
${CMAKE_CURRENT_BINARY_DIR}/test_install_root_static_cpp20 "STATIC" "Cpp20"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake_tests/find_package_test)

add_test(
NAME cmake_no_shared_installation_test
COMMAND
test.sh ${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/cmake_find_package_test_build
${CMAKE_CURRENT_BINARY_DIR}/test_install_root_shared_fail "SHARED_FAIL"
"Cpp20"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake_tests/find_package_test)
set_property(TEST cmake_no_shared_installation_test PROPERTY WILL_FAIL TRUE)
add_test(
NAME cmake_no_static_installation_test
COMMAND
test.sh ${CMAKE_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}/cmake_find_package_test_build
${CMAKE_CURRENT_BINARY_DIR}/test_install_root_static_fail "STATIC_FAIL"
"Cpp20"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/cmake_tests/find_package_test)
set_property(TEST cmake_no_static_installation_test PROPERTY WILL_FAIL TRUE)
19 changes: 19 additions & 0 deletions test/cmake_tests/build_and_install_ppplugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh

set -e
set -x

ROOT_SOURCE_DIR="${1}"
BUILD_DIR="${2}"
INSTALL_ROOT="${3}"
BUILD_SHARED="${4}"
BUILD_CPP17_COMPATIBLE="${5}"

echo "Building ppplugin library (shared: ${BUILD_SHARED})..."

echo "Use sources at '${ROOT_SOURCE_DIR}'..."
cmake "${ROOT_SOURCE_DIR}" -B "${BUILD_DIR}" -DPPPLUGIN_SHARED="${BUILD_SHARED}" -DPPPLUGIN_ENABLE_CPP17_COMPATIBILITY="${BUILD_CPP17_COMPATIBLE}"
echo "Build in '${BUILD_DIR}'..."
cmake --build "${BUILD_DIR}"
echo "Install to '${INSTALL_ROOT}'..."
cmake --install "${BUILD_DIR}" --prefix "${INSTALL_ROOT}/usr/local"
22 changes: 22 additions & 0 deletions test/cmake_tests/find_package_test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)

project(a)

find_package(ppplugin REQUIRED)

message(DEBUG "ppplugin found: ${ppplugin_FOUND}")
message(DEBUG "ppplugin should be shared library: ${PPPLUGIN_SHARED}")
message(DEBUG "ppplugin library dir: ${PPPLUGIN_LIBRARY_DIR}")
message(DEBUG "ppplugin include dir: ${PPPLUGIN_INCLUDE_DIR}")
message(
DEBUG
"ppplugin should be C++17 compatible: ${PPPLUGIN_ENABLE_CPP17_COMPATIBILITY}")

if(${PPPLUGIN_ENABLE_CPP17_COMPATIBILITY})
set(CMAKE_CXX_STANDARD 17)
else()
set(CMAKE_CXX_STANDARD 20)
endif()

add_executable(a a.cpp)
target_link_libraries(a PUBLIC ppplugin::ppplugin)
13 changes: 13 additions & 0 deletions test/cmake_tests/find_package_test/a.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <ppplugin/plugin_manager.h>

#include <iostream>

int main(int argc, char* /*argv*/[])
{
auto plugin = ppplugin::LuaPlugin::load("a.lua");
if (plugin) {
std::cout << plugin->call<int>("Main", argc).value().value() << '\n';
} else {
std::cerr << "Error: " << static_cast<int>(plugin.error().value()) << '\n';
}
}
3 changes: 3 additions & 0 deletions test/cmake_tests/find_package_test/a.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function Main(a)
return a + 10
end
46 changes: 46 additions & 0 deletions test/cmake_tests/find_package_test/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

set -e
set -x

ROOT_SOURCE_DIR="${1}"
BUILD_DIR="${2}"
INSTALL_ROOT="${3}"

if [ "${4}" = "SHARED" ] || [ "${4}" = "STATIC_FAIL" ]; then
TEST_SHARED=ON
elif [ "${4}" = "STATIC" ] || [ "${4}" = "SHARED_FAIL" ]; then
TEST_SHARED=OFF
else
echo "Fourth argument must be 'SHARED', 'STATIC', 'SHARED_FAIL' or 'STATIC_FAIL'"
return
fi

if [ "${5}" = "Cpp17" ]; then
TEST_CPP17_COMPATIBILITY=ON
elif [ "${5}" = "Cpp20" ]; then
TEST_CPP17_COMPATIBILITY=OFF
else
echo "Fifth argument must be 'Cpp17' or 'Cpp20'"
return
fi

TEST_BUILD_DIR="${BUILD_DIR}/shared_${TEST_SHARED}_cpp17_${TEST_CPP17_COMPATIBILITY}"
EXECUTABLE_NAME="${TEST_BUILD_DIR}/a"

"${ROOT_SOURCE_DIR}/test/cmake_tests/build_and_install_ppplugin.sh" "${ROOT_SOURCE_DIR}" "${BUILD_DIR}/ppplugin_build_shared_${TEST_SHARED}_cpp17_${TEST_CPP17_COMPATIBILITY}" "${INSTALL_ROOT}" "${TEST_SHARED}" "${TEST_CPP17_COMPATIBILITY}"

# if it is a test with expected failure, switch dependency to opposite library type to provoke error
if [ "${4}" = "SHARED_FAIL" ]; then
TEST_SHARED=ON
TEST_BUILD_DIR="${TEST_BUILD_DIR}_shared_fail"
elif [ "${4}" = "STATIC_FAIL" ]; then
TEST_SHARED=OFF
TEST_BUILD_DIR="${TEST_BUILD_DIR}_static_fail"
fi

CMAKE_PREFIX_PATH="${INSTALL_ROOT}/usr/local/lib/cmake" \
cmake . --log-level DEBUG -B "${TEST_BUILD_DIR}" -DPPPLUGIN_SHARED="${TEST_SHARED}" -DPPPLUGIN_ENABLE_CPP17_COMPATIBILITY="${TEST_CPP17_COMPATIBILITY}"
cmake --build "${TEST_BUILD_DIR}"

"${EXECUTABLE_NAME}"