diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a051666c..d083a86d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -529,6 +529,8 @@ jobs: - {name: show info, run: source .github/setenv.sh && c4_show_info } # - {name: singleheader, run: cd samples/singleheader && ./run.sh $BT } + - {name: singleheaderlib-static, run: cd samples/singleheaderlib && ./run_static.sh $BT } + - {name: singleheaderlib-shared, run: cd samples/singleheaderlib && ./run_shared.sh $BT } - {name: add_subdirectory, run: cd samples/add_subdirectory && ./run.sh $BT } - {name: find_package, run: cd samples/find_package && ./run.sh $BT } - {name: custom_c4core, run: cd samples/custom_c4core && ./run.sh $BT } diff --git a/samples/quickstart.cpp b/samples/quickstart.cpp index 6490c315..2e5cf17b 100644 --- a/samples/quickstart.cpp +++ b/samples/quickstart.cpp @@ -24,9 +24,11 @@ //----------------------------------------------------------------------------- // ryml can be used as a single header, or as a simple library: -#ifdef RYML_SINGLE_HEADER +#if defined(RYML_SINGLE_HEADER) // using the single header directly in the executable #define RYML_SINGLE_HDR_DEFINE_NOW #include +#elif defined(RYML_SINGLE_HEADER_LIB) // using the single header from a library + #include #else // is only needed if interop with std types is // desired; ryml itself does not use any STL container. diff --git a/samples/singleheader/CMakeLists.txt b/samples/singleheader/CMakeLists.txt index b91fab3b..e4b54e31 100644 --- a/samples/singleheader/CMakeLists.txt +++ b/samples/singleheader/CMakeLists.txt @@ -7,6 +7,7 @@ amalgamate_ryml(SINGLE_HEADER_DIR SINGLE_HEADER) # now simply define the executable: add_executable(ryml-quickstart ../quickstart.cpp ${SINGLE_HEADER}) +target_compile_features(ryml-quickstart PUBLIC cxx_std_11) target_compile_definitions(ryml-quickstart PUBLIC -DRYML_SINGLE_HEADER) target_include_directories(ryml-quickstart PUBLIC "${SINGLE_HEADER_DIR}") diff --git a/samples/singleheaderlib/CMakeLists.txt b/samples/singleheaderlib/CMakeLists.txt new file mode 100644 index 00000000..78a88484 --- /dev/null +++ b/samples/singleheaderlib/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.15 FATAL_ERROR) +project(ryml-quickstart LANGUAGES CXX) + +# create a target to amalgamate ryml into a single header: +include(../singleheader/amalgamate.cmake) +amalgamate_ryml(SINGLE_HEADER_DIR SINGLE_HEADER) + +# add a library using the amalgamated header +add_library(ryml lib.cpp ${SINGLE_HEADER}) +target_compile_features(ryml PUBLIC cxx_std_11) +target_include_directories(ryml PUBLIC "${SINGLE_HEADER_DIR}") + +# now simply define the executable: +add_executable(ryml-quickstart ../quickstart.cpp ) +target_link_libraries(ryml-quickstart PRIVATE ryml) +target_compile_definitions(ryml-quickstart PUBLIC -DRYML_SINGLE_HEADER_LIB) + +add_custom_target(run ryml-quickstart + COMMAND $ + DEPENDS ryml-quickstart) diff --git a/samples/singleheaderlib/lib.cpp b/samples/singleheaderlib/lib.cpp new file mode 100644 index 00000000..aa33e6e1 --- /dev/null +++ b/samples/singleheaderlib/lib.cpp @@ -0,0 +1,2 @@ +#define RYML_SINGLE_HDR_DEFINE_NOW +#include diff --git a/samples/singleheaderlib/run_shared.sh b/samples/singleheaderlib/run_shared.sh new file mode 100755 index 00000000..372a3677 --- /dev/null +++ b/samples/singleheaderlib/run_shared.sh @@ -0,0 +1,10 @@ +#!/bin/bash -x + +# take the build type from the command line, or default to release +cfg=${1:-Release} +# make sure to run from where this file is +cd $(dirname $0) +# configure the sample +cmake -S . -B ./build/$cfg-shared -DCMAKE_BUILD_TYPE=$cfg -DBUILD_SHARED_LIBS=ON +# build and run the sample +cmake --build ./build/$cfg-shared --config $cfg --target run diff --git a/samples/singleheaderlib/run_static.sh b/samples/singleheaderlib/run_static.sh new file mode 100755 index 00000000..d0e57021 --- /dev/null +++ b/samples/singleheaderlib/run_static.sh @@ -0,0 +1,10 @@ +#!/bin/bash -x + +# take the build type from the command line, or default to release +cfg=${1:-Release} +# make sure to run from where this file is +cd $(dirname $0) +# configure the sample +cmake -S . -B ./build/$cfg-static -DCMAKE_BUILD_TYPE=$cfg -DBUILD_SHARED_LIBS=OFF +# build and run the sample +cmake --build ./build/$cfg-static --config $cfg --target run