From 8a60fd1c24a48bb84cbacf9189ade9c3a2429ec9 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Wed, 12 Jul 2023 16:43:16 +0200 Subject: [PATCH] Move C and C++ examples to examples/ folder --- CMakeLists.txt | 6 ++ crates/rerun_c/run_examples.sh | 7 -- examples/c/README.md | 1 + .../example => examples/c/minimal}/.gitignore | 0 .../example => examples/c/minimal}/Makefile | 2 +- .../example => examples/c/minimal}/README.md | 0 .../example => examples/c/minimal}/main.c | 0 examples/cpp/README.md | 1 + .../cpp/minimal}/CMakeLists.txt | 2 +- examples/cpp/minimal/README.md | 5 ++ .../cpp/minimal}/build_and_run.sh | 5 +- .../example => examples/cpp/minimal}/main.cpp | 0 rerun_cpp/CMakeLists.txt | 71 ++++++++++++++++++- rerun_cpp/README.md | 2 +- rerun_cpp/example/README.md | 5 -- rerun_cpp/src/CMakeLists.txt | 71 ------------------- 16 files changed, 86 insertions(+), 92 deletions(-) create mode 100644 CMakeLists.txt delete mode 100755 crates/rerun_c/run_examples.sh create mode 100644 examples/c/README.md rename {crates/rerun_c/example => examples/c/minimal}/.gitignore (100%) rename {crates/rerun_c/example => examples/c/minimal}/Makefile (93%) rename {crates/rerun_c/example => examples/c/minimal}/README.md (100%) rename {crates/rerun_c/example => examples/c/minimal}/main.c (100%) create mode 100644 examples/cpp/README.md rename {rerun_cpp/example => examples/cpp/minimal}/CMakeLists.txt (88%) create mode 100644 examples/cpp/minimal/README.md rename {rerun_cpp => examples/cpp/minimal}/build_and_run.sh (73%) rename {rerun_cpp/example => examples/cpp/minimal}/main.cpp (100%) delete mode 100644 rerun_cpp/example/README.md delete mode 100644 rerun_cpp/src/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000000..2cf3cd01cdca --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,6 @@ +cmake_minimum_required(VERSION 3.16) + +project(rerun_cpp_proj LANGUAGES CXX) + +add_subdirectory(rerun_cpp) # The Rerun C++ SDK library +add_subdirectory(examples/cpp/minimal) diff --git a/crates/rerun_c/run_examples.sh b/crates/rerun_c/run_examples.sh deleted file mode 100755 index e4a3770cf04c..000000000000 --- a/crates/rerun_c/run_examples.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/usr/bin/env bash - -set -eu -script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) -set -x - -(cd "$script_path/example" && make run) diff --git a/examples/c/README.md b/examples/c/README.md new file mode 100644 index 000000000000..1bacc94d5a08 --- /dev/null +++ b/examples/c/README.md @@ -0,0 +1 @@ +The Rerun C SDK is in its infancy, and not ready for production. diff --git a/crates/rerun_c/example/.gitignore b/examples/c/minimal/.gitignore similarity index 100% rename from crates/rerun_c/example/.gitignore rename to examples/c/minimal/.gitignore diff --git a/crates/rerun_c/example/Makefile b/examples/c/minimal/Makefile similarity index 93% rename from crates/rerun_c/example/Makefile rename to examples/c/minimal/Makefile index 4e00643d109e..4b10ddf20e6b 100644 --- a/crates/rerun_c/example/Makefile +++ b/examples/c/minimal/Makefile @@ -1,7 +1,7 @@ CC = gcc CFLAGS = --std=c99 -O2 -g -DNDEBUG CFLAGS += -Wall -Wextra -Wpedantic -Wcast-align -Wcast-qual -Wformat=2 -Wmissing-include-dirs -Wnull-dereference -Woverloaded-virtual -Wpointer-arith -Wshadow -Wswitch-enum -Wvla -Wno-sign-compare -Wconversion -Wunused -Wold-style-cast -Wno-missing-braces -CFLAGS += -I ../src # Make sure rerun.h is found +CFLAGS += -I ../../../crates/rerun_c/src # Make sure rerun.h is found LDLIBS = OBJECTS = main.o diff --git a/crates/rerun_c/example/README.md b/examples/c/minimal/README.md similarity index 100% rename from crates/rerun_c/example/README.md rename to examples/c/minimal/README.md diff --git a/crates/rerun_c/example/main.c b/examples/c/minimal/main.c similarity index 100% rename from crates/rerun_c/example/main.c rename to examples/c/minimal/main.c diff --git a/examples/cpp/README.md b/examples/cpp/README.md new file mode 100644 index 000000000000..555ca37bda36 --- /dev/null +++ b/examples/cpp/README.md @@ -0,0 +1 @@ +The Rerun C++ SDK is in its infancy, and not ready for production. diff --git a/rerun_cpp/example/CMakeLists.txt b/examples/cpp/minimal/CMakeLists.txt similarity index 88% rename from rerun_cpp/example/CMakeLists.txt rename to examples/cpp/minimal/CMakeLists.txt index af764b822b9c..2dedec771f0f 100644 --- a/rerun_cpp/example/CMakeLists.txt +++ b/examples/cpp/minimal/CMakeLists.txt @@ -21,6 +21,6 @@ else() target_compile_options(rerun_example PRIVATE -Wall -Wextra -Wpedantic -Wcast-align -Wcast-qual -Wformat=2 -Wmissing-include-dirs -Wnull-dereference -Woverloaded-virtual -Wpointer-arith -Wshadow -Wswitch-enum -Wvla -Wno-sign-compare -Wconversion -Wunused -Wold-style-cast -Wno-missing-braces) endif() -include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../src) # For rerun.hpp (Rerun C++ SDK) +include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../../../rerun_cpp/src) # For rerun.hpp (Rerun C++ SDK) target_link_libraries(rerun_example PRIVATE loguru::loguru rerun_sdk) diff --git a/examples/cpp/minimal/README.md b/examples/cpp/minimal/README.md new file mode 100644 index 000000000000..5041110c8676 --- /dev/null +++ b/examples/cpp/minimal/README.md @@ -0,0 +1,5 @@ +# Example of using the Rerun C SDK + +``` +make run +``` diff --git a/rerun_cpp/build_and_run.sh b/examples/cpp/minimal/build_and_run.sh similarity index 73% rename from rerun_cpp/build_and_run.sh rename to examples/cpp/minimal/build_and_run.sh index 4c0091909a54..b19b24164e42 100755 --- a/rerun_cpp/build_and_run.sh +++ b/examples/cpp/minimal/build_and_run.sh @@ -2,7 +2,7 @@ set -eu script_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) -cd "$script_path" +cd "$script_path/../../.." set -x mkdir -p build @@ -11,5 +11,4 @@ pushd build make -j8 # VERBOSE=1 popd -./build/example/rerun_example - +./build/examples/cpp/minimal/rerun_example diff --git a/rerun_cpp/example/main.cpp b/examples/cpp/minimal/main.cpp similarity index 100% rename from rerun_cpp/example/main.cpp rename to examples/cpp/minimal/main.cpp diff --git a/rerun_cpp/CMakeLists.txt b/rerun_cpp/CMakeLists.txt index 13f41954602f..a937d45ba0c4 100644 --- a/rerun_cpp/CMakeLists.txt +++ b/rerun_cpp/CMakeLists.txt @@ -1,6 +1,71 @@ cmake_minimum_required(VERSION 3.16) -project(rerun_cpp_proj LANGUAGES CXX) +# NOTE: CMake docs strongly discourages using GLOB, and instead suggests +# manually listing all the files, like it's 1972. +# However, that won't work for use since we auto-generate the source tree. +# See https://cmake.org/cmake/help/latest/command/file.html#glob +file(GLOB_RECURSE rerun_sdk_SRC CONFIGURE_DEPENDS + "*.hpp" + "*.cpp" +) -add_subdirectory(src) # The Rerun C++ SDK library -add_subdirectory(example) +add_library(rerun_sdk ${rerun_sdk_SRC}) + +# ------------------------------------------------------------------------------ + +# For rerun.h (Rerun C SDK): +include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../crates/rerun_c/src) + +# Make sure the compiler can find include files for rerun +# when other libraries or executables link to rerun: +target_include_directories(rerun_sdk PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) + +# ------------------------------------------------------------------------------ +# Loguru logging library (https://github.com/emilk/loguru): +set(CMAKE_DL_LIBS "dl") # Required by Loguru for backtraces + +# Loguru, see https://github.com/emilk/loguru/blob/master/loguru_cmake_example/CMakeLists.txt +include(FetchContent) +FetchContent_Declare(LoguruGitRepo + GIT_REPOSITORY "https://github.com/emilk/loguru" # can be a filesystem path + GIT_TAG "master" +) + +# set any loguru compile-time flags before calling MakeAvailable() +set(LOGURU_STACKTRACES 1) +FetchContent_MakeAvailable(LoguruGitRepo) # defines target 'loguru::loguru' + +target_link_libraries(rerun_sdk PRIVATE loguru::loguru) + +# ------------------------------------------------------------------------------ +execute_process(COMMAND cargo build -p re_types) # Generates most of the C++ source files +execute_process(COMMAND cargo build -p rerun_c) # We link against this, so must be up-to-date + +# ------------------------------------------------------------------------------ +if(APPLE) + target_link_libraries(rerun_sdk PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../target/debug/librerun_c.a) + target_link_libraries(rerun_sdk PRIVATE "-framework CoreFoundation" "-framework IOKit") +endif() + +if(LINUX) + target_link_libraries(rerun_sdk PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../target/debug/librerun_c.a) + target_link_libraries(rerun_sdk PRIVATE "-lm") +endif() + +# ----------------------------------------------------------------------------- +# Arrow: +option(ARROW_LINK_SHARED "Link to the Arrow shared library" ON) + +find_package(Arrow REQUIRED) + +# Arrow requires a C++17 compliant compiler +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +message(STATUS "Arrow version: ${ARROW_VERSION}") +message(STATUS "Arrow SO version: ${ARROW_FULL_SO_VERSION}") + +if(ARROW_LINK_SHARED) + target_link_libraries(rerun_sdk PRIVATE Arrow::arrow_shared) +else() + target_link_libraries(rerun_sdk PRIVATE Arrow::arrow_static) +endif() diff --git a/rerun_cpp/README.md b/rerun_cpp/README.md index e27e375d5287..a86ff38dd4aa 100644 --- a/rerun_cpp/README.md +++ b/rerun_cpp/README.md @@ -6,7 +6,7 @@ This is not yet ready to be used. Run `scripts/setup.sh`. ## Test it -rerun_cpp/example/build_and_run.sh +`examples/cpp/minimal/build_and_run.sh`` # To do: * CI diff --git a/rerun_cpp/example/README.md b/rerun_cpp/example/README.md deleted file mode 100644 index adb11aefbb05..000000000000 --- a/rerun_cpp/example/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# Example of using the Rerun C++ SDK - -``` -make run -``` diff --git a/rerun_cpp/src/CMakeLists.txt b/rerun_cpp/src/CMakeLists.txt deleted file mode 100644 index d91df4649d8f..000000000000 --- a/rerun_cpp/src/CMakeLists.txt +++ /dev/null @@ -1,71 +0,0 @@ -cmake_minimum_required(VERSION 3.16) - -# NOTE: CMake docs strongly discourages using GLOB, and instead suggests -# manually listing all the files, like it's 1972. -# However, that won't work for use since we auto-generate the source tree. -# See https://cmake.org/cmake/help/latest/command/file.html#glob -file(GLOB_RECURSE rerun_sdk_SRC CONFIGURE_DEPENDS - "*.hpp" - "*.cpp" -) - -add_library(rerun_sdk ${rerun_sdk_SRC}) - -# ------------------------------------------------------------------------------ - -# For rerun.h (Rerun C SDK): -include_directories(SYSTEM ${CMAKE_CURRENT_SOURCE_DIR}/../../crates/rerun_c/src) - -# Make sure the compiler can find include files for rerun -# when other libraries or executables link to rerun: -target_include_directories(rerun_sdk PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) - -# ------------------------------------------------------------------------------ -# Loguru logging library (https://github.com/emilk/loguru): -set(CMAKE_DL_LIBS "dl") # Required by Loguru for backtraces - -# Loguru, see https://github.com/emilk/loguru/blob/master/loguru_cmake_example/CMakeLists.txt -include(FetchContent) -FetchContent_Declare(LoguruGitRepo - GIT_REPOSITORY "https://github.com/emilk/loguru" # can be a filesystem path - GIT_TAG "master" -) - -# set any loguru compile-time flags before calling MakeAvailable() -set(LOGURU_STACKTRACES 1) -FetchContent_MakeAvailable(LoguruGitRepo) # defines target 'loguru::loguru' - -target_link_libraries(rerun_sdk PRIVATE loguru::loguru) - -# ------------------------------------------------------------------------------ -execute_process(COMMAND cargo build -p re_types) # Generates most of the C++ source files -execute_process(COMMAND cargo build -p rerun_c) # We link against this, so must be up-to-date - -# ------------------------------------------------------------------------------ -if(APPLE) - target_link_libraries(rerun_sdk PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/librerun_c.a) - target_link_libraries(rerun_sdk PRIVATE "-framework CoreFoundation" "-framework IOKit") -endif() - -if(LINUX) - target_link_libraries(rerun_sdk PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../target/debug/librerun_c.a) - target_link_libraries(rerun_sdk PRIVATE "-lm") -endif() - -# ----------------------------------------------------------------------------- -# Arrow: -option(ARROW_LINK_SHARED "Link to the Arrow shared library" ON) - -find_package(Arrow REQUIRED) - -# Arrow requires a C++17 compliant compiler -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -message(STATUS "Arrow version: ${ARROW_VERSION}") -message(STATUS "Arrow SO version: ${ARROW_FULL_SO_VERSION}") - -if(ARROW_LINK_SHARED) - target_link_libraries(rerun_sdk PRIVATE Arrow::arrow_shared) -else() - target_link_libraries(rerun_sdk PRIVATE Arrow::arrow_static) -endif()