### Install Protocol Buffers using CMake Build Tools Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/cmake/README.md This snippet demonstrates how to install Protocol Buffers after it has been configured with CMake. It shows commands for different build tools like 'cmake --build', 'nmake', and 'ninja'. The installation process creates 'bin', 'include', and 'lib' directories containing the compiler, headers, and libraries. ```shell cmake --build C:\Path\to\build\protobuf\solution --config Release --target install ``` ```shell C:\Path\to\build\protobuf\release>nmake install ``` ```shell C:\Path\to\build\protobuf\debug>ninja install ``` -------------------------------- ### Build and run Protocol Buffers Go examples Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/examples/README.md Builds and runs Go examples for address book management with Protocol Buffers. Requires protoc and the protoc-gen-go plugin. Installs the plugin using 'go install'. ```bash go install google.golang.org/protobuf/cmd/protoc-gen-go@latest make go ./add_person_go addressbook.data ./list_people_go addressbook.data ``` -------------------------------- ### Install SDL Example Executables and Resources Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/examples/CMakeLists.txt Handles the installation of example executables and associated resource files based on build configurations like SDL_INSTALL_EXAMPLES and platform specifics (RISCOS, MSVC). It ensures that PDB files are installed for MSVC targets. ```cmake if(SDL_INSTALL_EXAMPLES) if(RISCOS) install( FILES ${SDL_EXAMPLE_EXECUTABLES_AIF} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-examples/SDL3 ) else() install( TARGETS ${SDL_EXAMPLE_EXECUTABLES} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-examples/SDL3 ) endif() if(MSVC) foreach(example IN LISTS SDL_EXAMPLE_EXECUTABLES) SDL_install_pdb(${example} "${CMAKE_INSTALL_LIBEXECDIR}/installed-examples/SDL3") endforeach() endif() install( FILES ${RESOURCE_FILES} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}/installed-examples/SDL3 ) endif() ``` -------------------------------- ### Clone and Build ZLib Library from Source Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/cmake/README.md This section details how to obtain the zlib source code using Git and then compile and install it using CMake. It covers creating build directories, configuring with CMake specifying the installation prefix, and building the 'install' target. This is a prerequisite for enabling ZLib support in Protocol Buffers. ```shell C:\Path\to\src>git clone -b v1.2.8 https://github.com/madler/zlib.git C:\Path\to\src>cd zlib C:\Path\to\src\zlib>mkdir C:\Path\to\build\zlib & cd C:\Path\to\build\zlib C:\Path\to\build\zlib>mkdir release & cd release C:\Path\to\build\zlib\release>cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=C:\Path\to\install C:\Path\to\src\zlib C:\Path\to\src\zlib\build\release>cmake --build . --target install ``` -------------------------------- ### Configure Protocol Buffers Installation Prefix Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/src/README.md Specifies how to set a custom installation directory for Protocol Buffers. By default, it installs to /usr/local. This example shows how to configure it to install into /usr instead, which can help with library path issues. ```bash ./configure --prefix=/usr ``` -------------------------------- ### Add Install Directory to System PATH Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/cmake/README.md This command appends the 'bin' directory from the Protocol Buffers installation path to the system's PATH environment variable. This makes executables like 'protoc.exe' accessible from any command prompt without specifying the full path. ```shell C:\Path\to>set PATH=%PATH%;C:\Path\to\install\bin ``` -------------------------------- ### Install Protobuf using vcpkg on Windows Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/src/README.md This command uses the vcpkg package manager to install Protocol Buffers and its 64-bit variant on Windows. It also shows how to install with zlib support. ```powershell >vcpkg install protobuf protobuf:x64-windows >vcpkg install protobuf[zlib] protobuf[zlib]:x64-windows ``` -------------------------------- ### Build and Install Protocol Buffers C++ Runtime and Compiler Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/src/README.md Executes the build and installation process for the Protocol Buffers C++ runtime and the protoc compiler. This involves configuring the build, compiling with parallel jobs, running checks, and installing the binaries and libraries. ```bash ./configure make -j$(nproc) # $(nproc) ensures it uses all cores for compilation make check sudo make install sudo ldconfig # refresh shared library cache. ``` -------------------------------- ### Build and run Protocol Buffers Python examples Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/examples/README.md Builds and runs Python examples for managing an address book with Protocol Buffers. Requires protoc and protobuf Python runtime (installable via pip). Uses shell scripts for executables. ```bash pip install protobuf make python ``` -------------------------------- ### Compile C++ Program with Protocol Buffers using pkg-config Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/src/README.md An example of compiling a C++ program that uses Protocol Buffers. It demonstrates how to pass the compiler and linker flags obtained from pkg-config to the C++ compiler. ```bash c++ my_program.cc my_proto.pb.cc `pkg-config --cflags --libs protobuf` ``` -------------------------------- ### Build with CMake Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/docs/README-porting.md This command demonstrates how to build the project using CMake. It assumes CMake is installed and configured for the current platform. The commands create a build directory, compile the project, and then install it. ```bash cmake -S . -B build && cmake --build build && cmake --install install ``` -------------------------------- ### Build, Install, and Start a Test using CMake Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/docs/README-android.md A convenience CMake target that automates the process of building, installing, and starting a specific test on the Android device. This streamlines the testing workflow. ```cmake cmake --build . --target build-install-start-testsprite ``` -------------------------------- ### Install Unix Tools on Mac with Homebrew Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/src/README.md Installs required Unix development tools such as autoconf, automake, and libtool on macOS using the Homebrew package manager. ```bash brew install autoconf automake libtool ``` -------------------------------- ### Install C++ Build Tools on Ubuntu/Debian Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/src/README.md Installs essential build tools required for compiling Protocol Buffers from source on Ubuntu or Debian-based systems. These include autoconf, automake, libtool, curl, make, g++, and unzip. ```bash sudo apt-get install autoconf automake libtool curl make g++ unzip ``` -------------------------------- ### Configure setup.py for Protobuf Generation Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/python/protobuf_distutils/README.md Example of how to configure a `setup.py` file to use the `protobuf_distutils` extension. It specifies the package name, required setup dependencies, and detailed options for protobuf code generation, including source directories, output directories, and specific proto files. ```python from setuptools import setup setup( # ... name='example_project', # Require this package, but only for setup (not installation): setup_requires=['protobuf_distutils'], options={ # See below for details. 'generate_py_protobufs': { 'source_dir': 'path/to/protos', 'extra_proto_paths': ['path/to/other/project/protos'], 'output_dir': 'path/to/project/sources', # default '.' 'proto_files': ['relative/path/to/just_this_file.proto'], 'protoc': 'path/to/protoc.exe', }, }, ) ``` -------------------------------- ### Download Protocol Buffers Source Code Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/src/README.md Demonstrates how to obtain the Protocol Buffers source code. It shows downloading specific language packages (e.g., C++, C++ and Java, or all languages) from the releases page or cloning the git repository. ```bash git clone https://github.com/protocolbuffers/protobuf.git cd protobuf git submodule update --init --recursive ./autogen.sh ``` -------------------------------- ### Create Bazel Workspace Directory Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/googletest/docs/quickstart-bazel.md Creates a new directory for the Bazel workspace and navigates into it. This directory will contain all source files and build configurations for the project. ```bash mkdir my_workspace && cd my_workspace ``` -------------------------------- ### Basic gMock Test Setup and Expectation Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/googletest/docs/gmock_for_dummies.md Demonstrates the fundamental steps of setting up a test using gMock. It includes importing necessary gMock namespaces, creating a mock object, specifying an expectation on a mock method using `EXPECT_CALL` with `AtLeast`, exercising code that uses the mock, and performing assertions. ```cpp #include "path/to/mock-turtle.h" #include #include using ::testing::AtLeast; TEST(PainterTest, CanDrawSomething) { MockTurtle turtle; EXPECT_CALL(turtle, PenDown()) .Times(AtLeast(1)); Painter painter(&turtle); EXPECT_TRUE(painter.DrawCircle(0, 0, 10)); } ``` -------------------------------- ### Build and Run GoogleTest with Bazel Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/googletest/docs/quickstart-bazel.md Compiles and executes a C++ test target using Bazel. This command builds the `hello_test` target, sets the C++ standard to C++14, and shows all test output. ```bash bazel test --cxxopt=-std=c++14 --test_output=all //:hello_test ``` -------------------------------- ### Build Protocol Buffers examples using bazel Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/examples/README.md Builds all Protocol Buffers example code using bazel. Requires bazel version 0.5.4 or newer. Outputs executables in the 'bazel-bin' directory. ```bash bazel build :all bazel-bin/add_person_cpp addressbook.data ``` -------------------------------- ### Build SDL Examples with CMake Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/docs/README-cmake.md This snippet shows how to enable building the SDL example programs. Adding the '-DSDL_EXAMPLES=ON' flag during the CMake configuration step ensures that the example executables are compiled and accessible within the 'build/examples/' directory. ```shell cmake -S . -B build -DSDL_EXAMPLES=ON ``` -------------------------------- ### Configure Protocol Buffers with ZLib Support Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/cmake/README.md To enable Gzip compression streams in Protocol Buffers, you must configure the build with the `-Dprotobuf_WITH_ZLIB=ON` flag when invoking CMake. This assumes you have already compiled and installed zlib as described previously. If zlib is installed in a non-standard location, you can specify its paths using `-DZLIB_INCLUDE_DIR` and `-DZLIB_LIB`. ```shell cmake -Dprotobuf_WITH_ZLIB=ON .. -DZLIB_INCLUDE_DIR= -DZLIB_LIB= ``` -------------------------------- ### Build and run Protocol Buffers Java examples Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/examples/README.md Builds and runs Java examples for address book management using Protocol Buffers. Requires protoc and protobuf Java runtime (downloaded from Maven). Sets CLASSPATH environment variable. ```bash export CLASSPATH=/path/to/protobuf-java-[version].jar make java ``` -------------------------------- ### Get Protocol Buffers Compiler Flags with pkg-config Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/src/README.md Utilizes pkg-config to retrieve the necessary compiler and linker flags for C++ programs that depend on Protocol Buffers. This is the recommended method for versions 2.2.0 and later. ```bash pkg-config --cflags protobuf # print compiler flags pkg-config --libs protobuf # print linker flags pkg-config --cflags --libs protobuf # print both ``` -------------------------------- ### Install Python Setuptools Extension Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/python/protobuf_distutils/README.md Commands to build and install the setuptools extension. The `develop` command is useful for testing changes to the extension. ```shell python setup.py build python -m pip install . ``` -------------------------------- ### Cloning Protobuf Sources using Git Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/cmake/README.md This command clones the protobuf repository from GitHub using Git. It specifies a branch or tag to retrieve specific versions of the source code. Ensure you have Git installed and accessible in your PATH. ```git git clone -b [release_tag] https://github.com/protocolbuffers/protobuf.git ``` -------------------------------- ### Build and Install with Generated Protobuf Sources Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/python/protobuf_distutils/README.md Steps to trigger the protobuf source generation and subsequently build and install the project. This ensures that generated code is included in the final package. ```shell python setup.py generate_py_protobufs python setup.py build python -m pip install . ``` -------------------------------- ### Build and run Protocol Buffers C++ examples Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/examples/README.md Builds and runs C++ examples for adding and listing people in an address book using Protocol Buffers. Requires protoc and protobuf C++ runtime. Assumes build instructions in ../src/README.md have been followed. ```bash make cpp ./add_person_cpp addressbook.data ./list_people_cpp addressbook.data ``` -------------------------------- ### CMake Configuration for Ninja Generator (Debug) Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/cmake/README.md This command configures the build using CMake with the Ninja generator for a Debug build type. It sets the installation prefix and points to the protobuf source directory. Ninja is known for its speed in building projects. ```cmake cmake -G "Ninja" ^ -DCMAKE_BUILD_TYPE=Debug ^ -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^ C:\Path\to\src\protobuf ``` -------------------------------- ### CMake Configuration for NMake Makefiles (Release) Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/cmake/README.md This command configures the build using CMake with the NMake Makefiles generator for a Release build type. It specifies the installation prefix and the path to the protobuf source directory. This is suitable for Windows environments using NMake. ```cmake cmake -G "NMake Makefiles" ^ -DCMAKE_BUILD_TYPE=Release ^ -DCMAKE_INSTALL_PREFIX=C:\Path\to\install ^ C:\Path\to\src\protobuf ``` -------------------------------- ### IDE Build Configuration Example Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/docs/README-porting.md This snippet lists source files that need to be included when building the project using an IDE or a non-configure build system. It covers various subsystems of the engine, including atomic operations, audio, CPU information, events, file I/O, haptics, joysticks, power management, rendering (software), standard library functions, threading, timers, and video. It also includes dummy drivers for certain subsystems. ```text src/*.c src/atomic/*.c src/audio/*.c src/cpuinfo/*.c src/events/*.c src/file/*.c src/haptic/*.c src/joystick/*.c src/power/*.c src/render/*.c src/render/software/*.c src/stdlib/*.c src/thread/*.c src/timer/*.c src/video/*.c src/audio/disk/*.c src/audio/dummy/*.c src/filesystem/dummy/*.c src/video/dummy/*.c src/haptic/dummy/*.c src/joystick/dummy/*.c src/thread/generic/*.c src/timer/dummy/*.c src/loadso/dummy/*.c ``` -------------------------------- ### Enable HIDAPI Installation and Customize Locations (CMake) Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/src/hidapi/BUILD.cmake.md This example illustrates how to enable the installation of HIDAPI targets and optionally change their default installation directories using GNUInstallDirs variables. This requires CMake 3.13 or later. ```cmake set(HIDAPI_INSTALL_TARGETS ON) set(CMAKE_INSTALL_LIBDIR "lib64") add_subdirectory(hidapi) ``` -------------------------------- ### HIDAPI C Example: Device Communication Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/src/hidapi/README.md This C code snippet demonstrates common HIDAPI functions for initializing the library, opening a device by Vendor ID (VID) and Product ID (PID), retrieving device strings (manufacturer, product, serial number), sending control commands (like toggling an LED and requesting state), reading device responses, and finally closing the device and exiting the library. Error checking is omitted for brevity. Ensure you understand the device specifications before writing data to HID devices. ```c #include // printf #include // wchar_t #include #define MAX_STR 255 int main(int argc, char* argv[]) { int res; unsigned char buf[65]; wchar_t wstr[MAX_STR]; hid_device *handle; int i; // Initialize the hidapi library res = hid_init(); // Open the device using the VID, PID, // and optionally the Serial number. handle = hid_open(0x4d8, 0x3f, NULL); if (!handle) { printf("Unable to open device\n"); hid_exit(); return 1; } // Read the Manufacturer String res = hid_get_manufacturer_string(handle, wstr, MAX_STR); printf("Manufacturer String: %ls\n", wstr); // Read the Product String res = hid_get_product_string(handle, wstr, MAX_STR); printf("Product String: %ls\n", wstr); // Read the Serial Number String res = hid_get_serial_number_string(handle, wstr, MAX_STR); printf("Serial Number String: (%d) %ls\n", wstr[0], wstr); // Read Indexed String 1 res = hid_get_indexed_string(handle, 1, wstr, MAX_STR); printf("Indexed String 1: %ls\n", wstr); // Toggle LED (cmd 0x80). The first byte is the report number (0x0). buf[0] = 0x0; buf[1] = 0x80; res = hid_write(handle, buf, 65); // Request state (cmd 0x81). The first byte is the report number (0x0). buf[0] = 0x0; buf[1] = 0x81; res = hid_write(handle, buf, 65); // Read requested state res = hid_read(handle, buf, 65); // Print out the returned buffer. for (i = 0; i < 4; i++) printf("buf[%d]: %d\n", i, buf[i]); // Close the device hid_close(handle); // Finalize the hidapi library res = hid_exit(); return 0; } ``` -------------------------------- ### TestResult Start Timestamp Method Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/googletest/docs/reference/testing.md Gets the timestamp when the test case started, represented in milliseconds since the UNIX epoch. This can be used to determine the exact start time of the test. ```cpp `TimeInMillis TestResult::start_timestamp() const` ``` -------------------------------- ### Install Unix Tools on Mac with MacPorts Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/src/README.md Installs necessary Unix development tools like autoconf, automake, and libtool on macOS using the MacPorts package manager. This is an alternative to using Homebrew. ```bash sudo /opt/local/bin/port install autoconf automake libtool ``` -------------------------------- ### Surface Creation Example with Palette Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/docs/README-migration.md Demonstrates the updated method for creating an indexed 8-bit surface and obtaining its palette. This replaces the older approach that directly accessed the palette through the surface's format structure. ```c SDL_Surface *surface = SDL_CreateSurface(32, 32, SDL_PIXELFORMAT_INDEX8); SDL_Palette *palette = SDL_CreateSurfacePalette(surface); ... ``` -------------------------------- ### Run SDL Application Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/docs/INTRO-cmake.md This shows how to navigate to the build directory and run the compiled 'hello' executable. It also provides an alternative path for Visual Studio toolchains where the executable might be in a 'Debug' subdirectory. ```sh cd build ./hello ``` ```sh cd build/Debug ./hello ``` -------------------------------- ### Interoperating SDL with Qt 6 using External Wayland Surfaces Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/docs/README-wayland.md This C++ code demonstrates how to initialize SDL to use a Wayland display owned by a Qt application. It shows how to obtain the wl_display and wl_surface from Qt objects and then create an SDL window that wraps the external wl_surface. This example requires Qt 6 and SDL3, and assumes a Wayland environment. ```c++ #include #include #include #include int main(int argc, char *argv[]) { int ret = -1; int done = 0; SDL_PropertiesID props; SDL_Event e; SDL_Window *sdlWindow = NULL; SDL_Renderer *sdlRenderer = NULL; struct wl_display *display = NULL; struct wl_surface *surface = NULL; /* Initialize Qt */ QApplication qtApp(argc, argv); QWindow qtWindow; /* The windowing system must be Wayland. */ if (QApplication::platformName() != "wayland") { goto exit; } { /* Get the wl_display object from Qt */ QNativeInterface::QWaylandApplication *qtWlApp = qtApp.nativeInterface(); display = qtWlApp->display(); if (!display) { goto exit; } } /* Set SDL to use the existing wl_display object from Qt and initialize. */ SDL_SetPointerProperty(SDL_GetGlobalProperties(), SDL_PROP_GLOBAL_VIDEO_WAYLAND_WL_DISPLAY_POINTER, display); SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS); /* Create a basic, frameless QWindow */ qtWindow.setFlags(Qt::FramelessWindowHint); qtWindow.setGeometry(0, 0, 640, 480); qtWindow.show(); { /* Get the native wl_surface backing resource for the window */ QPlatformNativeInterface *qtNative = qtApp.platformNativeInterface(); surface = (struct wl_surface *)qtNative->nativeResourceForWindow("surface", &qtWindow); if (!surface) { goto exit; } } /* Create a window that wraps the wl_surface from the QWindow. * Qt objects should not be flagged as DPI-aware or protocol violations will result. */ props = SDL_CreateProperties(); SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WAYLAND_WL_SURFACE_POINTER, surface); SDL_SetBooleanProperty(props, SDL_PROP_WINDOW_CREATE_OPENGL_BOOLEAN, true); SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_WIDTH_NUMBER, 640); SDL_SetNumberProperty(props, SDL_PROP_WINDOW_CREATE_HEIGHT_NUMBER, 480); sdlWindow = SDL_CreateWindowWithProperties(props); SDL_DestroyProperties(props); if (!sdlWindow) { goto exit; } /* Create a renderer */ sdlRenderer = SDL_CreateRenderer(sdlWindow, NULL); if (!sdlRenderer) { goto exit; } /* Event loop */ while (!done) { while (SDL_PollEvent(&e)) { if (e.type == SDL_EVENT_QUIT) { done = 1; } } SDL_RenderPresent(sdlRenderer); } ret = 0; exit: if (sdlRenderer) SDL_DestroyRenderer(sdlRenderer); if (sdlWindow) SDL_DestroyWindow(sdlWindow); SDL_Quit(); return ret; } ``` -------------------------------- ### Set up Valgrind for Memory Debugging Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/docs/README-android.md Provides steps to clone Valgrind, build it for Android, configure environment variables, create a wrapper script to launch applications with Valgrind, push the script to the device, set it as executable, and configure Android to use the wrapper. ```bash git clone https://sourceware.org/git/valgrind.git ``` ```bash export RANLIB=$NDKROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/arm-linux-androideabi-ranlib ``` ```bash #!/system/bin/sh export TMPDIR=/data/data/org.libsdl.app exec /data/local/Inst/bin/valgrind --log-file=/sdcard/valgrind.log --error-limit=no $* ``` ```bash adb push start_valgrind_app /data/local ``` ```bash adb shell chmod 755 /data/local/start_valgrind_app ``` ```bash adb shell setprop wrap.org.libsdl.app "logwrapper /data/local/start_valgrind_app" ``` ```bash adb pull /sdcard/valgrind.log ``` ```bash adb shell setprop wrap.org.libsdl.app "" ``` -------------------------------- ### Configure Protobuf for Static Libraries Only Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/protobuf/src/README.md This configuration command disables the building of shared libraries and installs only static libraries for Protocol Buffers. This can help mitigate binary compatibility issues. ```shell ./configure --disable-shared ``` -------------------------------- ### Adding SDL Example Executables Macro in CMake Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/examples/CMakeLists.txt This CMake macro `add_sdl_example_executable` simplifies the creation of SDL example executables. It takes sources and optional data files, sets common compiler flags, includes necessary directories, links SDL libraries, and handles platform-specific build configurations (Android, PSP, Emscripten, Windows) and resource installation. ```cmake macro(add_sdl_example_executable TARGET) cmake_parse_arguments(AST "BUILD_DEPENDENT" "" "SOURCES;DATAFILES" ${ARGN}) if(AST_UNPARSED_ARGUMENTS) message(FATAL_ERROR "Unknown argument(s): ${AST_UNPARSED_ARGUMENTS}") endif() if(NOT AST_SOURCES) message(FATAL_ERROR "add_sdl_example_executable needs at least one source") endif() set(EXTRA_SOURCES "") if(AST_DATAFILES) list(APPEND EXTRA_SOURCES ${DATAFILES}) endif() if(ANDROID) add_library(${TARGET} SHARED ${AST_SOURCES} ${EXTRA_SOURCES}) else() add_executable(${TARGET} ${AST_SOURCES} ${EXTRA_SOURCES}) endif() SDL_AddCommonCompilerFlags(${TARGET}) target_include_directories(${TARGET} PRIVATE "${SDL3_SOURCE_DIR}/src/video/khronos") target_link_libraries(${TARGET} PRIVATE SDL3::${sdl_name_component}) list(APPEND SDL_EXAMPLE_EXECUTABLES ${TARGET}) if(AST_DATAFILES) if(PSP OR PS2) add_custom_command(TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E make_directory $/sdl-${TARGET} COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${AST_DATAFILES} $/sdl-${TARGET} WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" ) else() add_dependencies(${TARGET} copy-sdl-example-resources) endif() if(APPLE) # Make sure resource files get installed into macOS/iOS .app bundles. set_target_properties(${TARGET} PROPERTIES RESOURCE "${AST_DATAFILES}") endif() if(EMSCRIPTEN) foreach(res IN LISTS AST_DATAFILES) get_filename_component(res_name "${res}" NAME) target_link_options(${TARGET} PRIVATE "SHELL--embed-file ${res}@${res_name}") endforeach() endif() set_property(TARGET ${TARGET} APPEND PROPERTY ADDITIONAL_CLEAN_FILES "$/$$/>") endif() if(WINDOWS) # CET support was added in VS 16.7 if(MSVC_VERSION GREATER 1926 AND CMAKE_GENERATOR_PLATFORM MATCHES "Win32|x64") set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -CETCOMPAT") endif() elseif(PSP) target_link_libraries(${TARGET} PRIVATE GL) elseif(EMSCRIPTEN) set_property(TARGET ${TARGET} PROPERTY SUFFIX ".html") target_link_options(${TARGET} PRIVATE -sALLOW_MEMORY_GROWTH=1) endif() if(OPENGL_FOUND) target_compile_definitions(${TARGET} PRIVATE HAVE_OPENGL) endif() # FIXME: only add "${SDL3_BINARY_DIR}/include-config-$>" + include paths of external dependencies target_include_directories(${TARGET} PRIVATE "$") endmacro() ``` -------------------------------- ### Install and Manage Android Applications Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/examples/CMakeLists.txt This snippet defines custom targets for installing, uninstalling, and running Android applications on a connected device using ADB. It leverages CMake's ability to execute external commands and integrates with SDL Android helper scripts. ```cmake if(TARGET SdlAndroid::adb) add_custom_target(install-${EXAMPLE} COMMAND "${CMAKE_COMMAND}" -DACTION=install "-DAPKS=$" -P "${SDL3_SOURCE_DIR}/cmake/android/SdlAndroidScript.cmake" DEPENDS "${EXAMPLE}-apk" ) add_custom_target(start-${EXAMPLE} COMMAND "${ADB_BIN}" shell am start-activity -S "${ANDROID_MANIFEST_PACKAGE}/.SDLTestActivity" ) add_custom_target(build-install-start-${EXAMPLE} COMMAND "${CMAKE_COMMAND}" -DACTION=build-install-run "-DEXECUTABLES=${EXAMPLE}" "-DBUILD_FOLDER=${CMAKE_BINARY_DIR}" -P "${SDL3_SOURCE_DIR}/cmake/android/SdlAndroidScript.cmake" ) endif() list(APPEND packages "${ANDROID_MANIFEST_PACKAGE}") list(APPEND install_targets install-${EXAMPLE}) if(TARGET SdlAndroid::adb) add_custom_target(install-sdl-example-apks DEPENDS ${install_targets} VERBATIM ) add_custom_target(uninstall-sdl-example-apks COMMAND "${CMAKE_COMMAND}" "-DADB=$" -DACTION=uninstall "-DPACKAGES=${packages}" -P "${SDL3_SOURCE_DIR}/cmake/android/SdlAndroidScript.cmake" VERBATIM ) endif() ``` -------------------------------- ### Environment Setup and Teardown (C++) Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/googletest/docs/reference/testing.md The Environment::SetUp and Environment::TearDown methods provide a mechanism for global setup and teardown actions that are not tied to specific test suites or individual tests. These are typically used for initializing and cleaning up resources that are shared across the entire test execution. ```cpp class Environment { public: virtual void SetUp(); virtual void TearDown(); // ... }; ``` -------------------------------- ### C++ Class and Struct Usage Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/Docs/CodeStyle.md Enforces the use of 'class' over 'struct' in C++ for consistency, providing an example of a trivial type defined as a class. ```cpp class MyTrivialType { public: int m_x; int m_y; }; ``` -------------------------------- ### Ubuntu HIDAPI Installation via APT Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/src/hidapi/README.md This command demonstrates how to install the HIDAPI development package on Ubuntu using the APT package manager. This is a prerequisite for building applications that utilize HIDAPI on this system. ```sh sudo apt install libhidapi-dev ``` -------------------------------- ### Get Start Timestamp - C++ Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/googletest/docs/reference/testing.md Retrieves the timestamp, in milliseconds since the UNIX epoch, when the test program began execution. This is useful for performance analysis and logging. ```cpp TimeInMillis UnitTest::start_timestamp() const ``` -------------------------------- ### Get Ad Hoc Test Result (C++) Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/SpirvTools/external/googletest/docs/reference/testing.md Retrieve the `TestResult` object that stores properties recorded during the execution of `SetUpTestSuite` and `TearDownTestSuite`. This is useful for inspecting setup and teardown specific results. ```cpp const TestResult& TestSuite::ad_hoc_test_result() const; ``` -------------------------------- ### SDL2 Audio Playback Example Source: https://github.com/godlikepanos/anki-3d-engine/blob/master/ThirdParty/Sdl3/docs/README-migration.md Demonstrates how audio playback was handled in SDL2 using a callback function and SDL_OpenAudioDevice. This serves as a baseline for understanding the migration to SDL3. ```c void SDLCALL MyAudioCallback(void *userdata, Uint8 * stream, int len) { /* Calculate a little more audio here, maybe using `userdata`, write it to `stream` */ } /* ...somewhere near startup... */ SDL_AudioSpec my_desired_audio_format; SDL_zero(my_desired_audio_format); my_desired_audio_format.format = AUDIO_S16; my_desired_audio_format.channels = 2; my_desired_audio_format.freq = 44100; my_desired_audio_format.samples = 1024; my_desired_audio_format.callback = MyAudioCallback; my_desired_audio_format.userdata = &my_audio_callback_user_data; SDL_AudioDeviceID my_audio_device = SDL_OpenAudioDevice(NULL, 0, &my_desired_audio_format, NULL, 0); SDL_PauseAudioDevice(my_audio_device, 0); ```