Skip to content

Commit

Permalink
build examples with single file as well
Browse files Browse the repository at this point in the history
  • Loading branch information
goatshriek committed Oct 1, 2023
1 parent ffb25bc commit defd422
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 7 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
12 changes: 7 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
30 changes: 30 additions & 0 deletions tools/cmake/example.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})

Expand All @@ -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)
12 changes: 10 additions & 2 deletions tools/cmake/single_file.cmake
Original file line number Diff line number Diff line change
@@ -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})
Expand Down Expand Up @@ -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()

0 comments on commit defd422

Please sign in to comment.