[sample] add samples showing how to build ryml and apps

This commit is contained in:
Joao Paulo Magalhaes
2021-07-06 15:16:38 +01:00
parent 0cfbdd39ae
commit 5ea549b098
7 changed files with 73 additions and 8 deletions

View File

@@ -1,5 +0,0 @@
cmake_minimum_required(VERSION 3.12)
project(ryml-samples LANGUAGES CXX)
add_subdirectory(add_subdirectory)
add_subdirectory(fetch_content)

15
samples/add_subdirectory/run.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash -x
BUILD_TYPE=Release
if [ "$#" -ge 1 ] ; then
BUILD_TYPE=$1
fi
THIS_DIR=$(pwd)
BUILD_DIR=$THIS_DIR/build/$BUILD_TYPE
mkdir -p $BUILD_DIR
# configure the sample
cmake -S "$THIS_DIR" -B "$BUILD_DIR"
# build and run the sample
cmake --build "$BUILD_DIR" --config $BUILD_TYPE --target run

View File

@@ -5,7 +5,7 @@ include(FetchContent)
FetchContent_Declare(ryml
GIT_REPOSITORY https://github.com/biojppm/rapidyaml.git
GIT_TAG samples
GIT_SHALLOW FALSE
GIT_SHALLOW FALSE # ensure submodules are checked out
)
FetchContent_MakeAvailable(ryml)

15
samples/fetch_content/run.sh Executable file
View File

@@ -0,0 +1,15 @@
#!/bin/bash -x
BUILD_TYPE=Release
if [ "$#" -ge 1 ] ; then
BUILD_TYPE=$1
fi
THIS_DIR=$(pwd)
BUILD_DIR=$THIS_DIR/build/$BUILD_TYPE
mkdir -p $BUILD_DIR
# configure the sample
cmake -S "$THIS_DIR" -B "$BUILD_DIR"
# build and run the sample
cmake --build "$BUILD_DIR" --config $BUILD_TYPE --target run

View File

@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.12)
project(ryml-quickstart LANGUAGES CXX)
find_package(ryml REQUIRED)
add_executable(ryml-quickstart ../quickstart.cpp)
target_link_libraries(ryml-quickstart ryml::ryml) # note the namespace!
add_custom_target(run ryml-quickstart
COMMAND $<TARGET_FILE:ryml-quickstart>
DEPENDS ryml-quickstart
COMMENT "running: $<TARGET_FILE:ryml-quickstart>")

29
samples/find_package/run.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/bin/bash -x
BUILD_TYPE=Release
if [ "$#" -ge 1 ] ; then
BUILD_TYPE=$1
fi
RYML_DIR=$(cd ../.. ; pwd)
THIS_DIR=$(pwd)
BUILD_DIR=$THIS_DIR/build/$BUILD_TYPE
mkdir -p $BUILD_DIR
RYML_BUILD_DIR=$BUILD_DIR/ryml-build
RYML_INSTALL_DIR=$BUILD_DIR/ryml-install
# configure ryml
cmake -S "$RYML_DIR" -B "$RYML_BUILD_DIR" "-DCMAKE_INSTALL_PREFIX=$RYML_INSTALL_DIR"
# build ryml
cmake --build "$RYML_BUILD_DIR" --parallel --config $BUILD_TYPE
# install ryml
cmake --build "$RYML_BUILD_DIR" --target install
# configure the sample
cmake -S "$THIS_DIR" -B "$BUILD_DIR" "-DCMAKE_PREFIX_PATH=$RYML_INSTALL_DIR"
# build and run the sample
cmake --build "$BUILD_DIR" --config $BUILD_TYPE --target run

View File

@@ -70,8 +70,7 @@ void sample_docs(); ///< deal with YAML docs
void sample_error_handler(); ///< set a custom error handler
void sample_global_allocator(); ///< set a global allocator for ryml
void sample_per_tree_allocator(); ///< set per-tree allocators
int report_checks();
int report_checks();
int main()
{