From defd422ec33689a33df18b897f41d1a792557d58 Mon Sep 17 00:00:00 2001 From: Joel Anderson Date: Sat, 30 Sep 2023 21:22:27 -0400 Subject: [PATCH] build examples with single file as well --- .github/workflows/linux.yml | 42 +++++++++++++++++++++++++++++++++++ CMakeLists.txt | 12 +++++----- tools/cmake/example.cmake | 30 +++++++++++++++++++++++++ tools/cmake/single_file.cmake | 12 ++++++++-- 4 files changed, 89 insertions(+), 7 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index f8bb50208..13197c2f2 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -198,6 +198,48 @@ jobs: run: | gcc docs/examples/basic/basic_example.c -lstumpless -o basic_example ./basic_example + linux-release-single-file: + name: "linux, release, single-file library" + runs-on: "ubuntu-latest" + steps: + - uses: actions/checkout@v3 + - name: Configure + run: | + cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_SINGLE_FILE=ON . + - name: Build + run: | + make all + - name: Test + run: | + make check + if grep "DEPRECATED" Testing/Temporary/LastTest.log; then exit 1; fi + - name: Privileged Tests + run: | + sudo ./function-test-tcp4 + sudo ./function-test-tcp4_leak + sudo ./function-test-tcp6 + sudo ./function-test-tcp6_leak + sudo ./function-test-udp4 + sudo ./function-test-udp4_leak + sudo ./function-test-udp6 + sudo ./function-test-udp6_leak + - name: Thread Safety Tests + run: | + make check-thread-safety + sudo ./thread-safety-test-network + - name: Run Examples + run: | + make examples + - name: Run Benchmarks + run: | + make bench + - name: Install + run: | + sudo make install + - name: Test Install + run: | + gcc docs/examples/basic/basic_example.c -lstumpless -o basic_example + ./basic_example linux-release-ansi: name: "linux, release, ansi" runs-on: "ubuntu-latest" diff --git a/CMakeLists.txt b/CMakeLists.txt index 55659c767..292aeeb80 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ string(CONCAT enable_cpp_help_string ) option(ENABLE_CPP ${enable_cpp_help_string} OFF) +set(SINGLE_SOURCE_FILE "${PROJECT_BINARY_DIR}/stumpless.c") option(BUILD_SINGLE_FILE "create a single file version of library" OFF) option(BUILD_PYTHON "include the python libary" OFF) @@ -683,11 +684,6 @@ if(PKG_CONFIG_FOUND) endif() -# single source build -if(BUILD_SINGLE_FILE) - include(tools/cmake/single_file.cmake) -endif() - # installation of examples if enabled if(INSTALL_EXAMPLES) install(DIRECTORY @@ -1069,6 +1065,12 @@ if(FUZZ) endif() +# single source build +if(BUILD_SINGLE_FILE) + include(tools/cmake/single_file.cmake) +endif() + + # c++ support if(ENABLE_CPP) if(HAVE_WRAPTURE) diff --git a/tools/cmake/example.cmake b/tools/cmake/example.cmake index bf48ba5ed..68e3e303b 100644 --- a/tools/cmake/example.cmake +++ b/tools/cmake/example.cmake @@ -27,6 +27,26 @@ function(add_no_run_example name) ) endfunction(add_no_run_example) +function(add_no_run_single_file_example name) + add_executable(example-single-file-${name} + EXCLUDE_FROM_ALL + ${SINGLE_SOURCE_FILE} + ${ARGN} + ) + + set_target_properties(example-single-file-${name} + PROPERTIES + BUILD_RPATH "${CMAKE_CURRENT_BINARY_DIR}" + COMPILE_FLAGS "${example_compile_flags}" + ) + + target_include_directories(example-single-file-${name} + PRIVATE + ${PROJECT_SOURCE_DIR}/include + ${CMAKE_BINARY_DIR}/include + ) +endfunction(add_no_run_single_file_example) + macro(add_example name) add_no_run_example(${name} ${ARGN}) @@ -35,4 +55,14 @@ macro(add_example name) COMMAND "example-${name}" DEPENDS example-${name} ) + + if(BUILD_SINGLE_FILE) + add_no_run_single_file_example(${name} ${ARGN}) + list(APPEND STUMPLESS_SINGLE_FILE_TARGETS example-single-file-${name}) + list(APPEND STUMPLESS_EXAMPLE_RUNNERS run-example-single-file-${name}) + add_custom_target(run-example-single-file-${name} + COMMAND "example-single-file-${name}" + DEPENDS example-single-file-${name} + ) + endif() endmacro(add_example) diff --git a/tools/cmake/single_file.cmake b/tools/cmake/single_file.cmake index 03ab86d4e..bb606c3ec 100644 --- a/tools/cmake/single_file.cmake +++ b/tools/cmake/single_file.cmake @@ -1,5 +1,4 @@ -set(SINGLE_SOURCE_FILE "${PROJECT_BINARY_DIR}/stumpless.c") -message("creating single source library ${SINGLE_SOURCE_FILE}") +message("creating single file library ${SINGLE_SOURCE_FILE}") function(include_file source_filename include_filenames already_included) foreach(include_filename ${include_filenames}) @@ -53,3 +52,12 @@ foreach(source_file ${STUMPLESS_SOURCES}) ) endif() endforeach() + +# this needs to happen after the stumpless library is set up +get_target_property(STUMPLESS_LINK_LIBRARIES stumpless LINK_LIBRARIES) +message("single file targets: ${STUMPLESS_SINGLE_FILE_TARGETS}") +message("linked libraries: ${STUMPLESS_LINK_LIBRARIES}") +foreach(example_target ${STUMPLESS_SINGLE_FILE_TARGETS}) + message(" adding to target: ${example_target}") + target_link_libraries(${example_target} ${STUMPLESS_LINK_LIBRARIES}) +endforeach()