### Example Installation Commands (Linux/macOS & Windows) Source: https://github.com/milkmull/vertex/blob/main/README.md Provides concrete examples for installing the Vertex library on both Linux/macOS and Windows systems using the `cmake --install` command. It specifies common installation paths and build configurations. Dependencies include a previously built Vertex library. ```bash # Linux/macOS cmake --install . --prefix /usr/local --config Debug cmake --install . --prefix /usr/local --config Release # Windows cmake --install . --prefix "C:\Program Files\Vertex" --config Debug cmake --install . --prefix "C:\Program Files\Vertex" --config Release ``` -------------------------------- ### Install Vertex Library (Cross-Platform) Source: https://github.com/milkmull/vertex/blob/main/README.md This command demonstrates how to install the built Vertex library and its associated files to a specified location on the system. It supports cross-platform installation by accepting an install path and build configuration (Debug/Release). Dependencies include a previously built Vertex library. ```bash cmake --install . --prefix --config ``` -------------------------------- ### Install PDB Debug Files for Windows (CMake) Source: https://github.com/milkmull/vertex/blob/main/vertex/CMakeLists.txt This snippet handles the installation of Program Database (PDB) files, which are essential for debugging on Windows with MSVC. It conditionally installs PDB files for shared libraries in the binary directory or, for static libraries, it uses a CMake script to locate and install PDB files from the install directory. ```cmake # Install PDB files (for debugging on Windows) if(MSVC) if(VX_BUILD_SHARED_LIBS) # For shared libs we can just set it up like this install(FILES "$" DESTINATION "${CMAKE_INSTALL_BINDIR}" CONFIGURATIONS Debug OPTIONAL) else() # For static libs we need to manually locate the pdb files in the install directory and install them install(CODE " file(GLOB_RECURSE PDB_FILES \"${CMAKE_BINARY_DIR}/lib/Vertex*.pdb\") foreach(PDB \${PDB_FILES}) file(INSTALL DESTINATION \"${CMAKE_INSTALL_PREFIX}/lib\" TYPE FILE FILES \${PDB}) endforeach() " CONFIGURATIONS Debug) endif() endif() ``` -------------------------------- ### Configure and Build Vertex with Options (Bash) Source: https://github.com/milkmull/vertex/blob/main/README.md This example shows how to configure and build the Vertex library with specific CMake options, such as setting the build type to Release and enabling unit tests. It's useful for customizing the build process based on project needs. Dependencies include CMake and a C++17 compiler. ```bash cmake .. -DCMAKE_BUILD_TYPE=Release -DVX_BUILD_TESTS=ON cmake --build . ``` -------------------------------- ### Install Headers and Library Targets (CMake) Source: https://github.com/milkmull/vertex/blob/main/vertex/CMakeLists.txt This section covers the installation of project headers and the main Vertex library. It installs header files matching '*.hpp' and exports both header and library targets for use by other CMake projects. It also specifies destinations for static libraries, shared libraries, and runtime files. ```cmake # Install headers install( DIRECTORY "include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" FILES_MATCHING PATTERN "*.hpp" ) # Install and export headers interface install( TARGETS Vertex_Headers EXPORT VertexHeaderTargets INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" ) # Install library (Vertex shared or static) install( TARGETS Vertex EXPORT VertexTargets ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" # For static libraries LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" # For shared libraries RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" # For executables (if any) FRAMEWORK DESTINATION "." ) ``` -------------------------------- ### Configure Test Installation (CMake) Source: https://github.com/milkmull/vertex/blob/main/test/CMakeLists.txt A CMake function to conditionally install test targets. It uses the `install` command to place executables, libraries, and archives into a 'test' subdirectory within the installation prefix. This functionality is controlled by the `VX_INSTALL_TESTS` variable. ```cmake function(vx_configure_test_install TARGET) if(VX_INSTALL_TESTS) install(TARGETS ${TARGET} ARCHIVE DESTINATION "${CMAKE_INSTALL_PREFIX}/test" # For static libraries LIBRARY DESTINATION "${CMAKE_INSTALL_PREFIX}/test" # For shared libraries RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}/test" # For executables ) endif() endfunction() ``` -------------------------------- ### Manipulate Pixels and Surfaces with Vertex C++ Source: https://context7.com/milkmull/vertex/llms.txt This C++ code showcases surface and pixel manipulation using the vx::pixel and vx::math libraries. It demonstrates creating surfaces with various pixel formats, filling them with color, setting and getting individual pixels, direct pixel access, retrieving surface properties, accessing raw data, converting between formats, iterating over pixels, generating palettes, and creating surfaces from raw data. Ensure Vertex library is linked. ```cpp #include #include using namespace vx::pixel; using namespace vx::math; // Create surfaces with different pixel formats surface_rgba8 rgba_surf(800, 600); // 8-bit RGBA surface_rgb8 rgb_surf(640, 480); // 8-bit RGB surface_r8 grayscale(512, 512); // 8-bit grayscale // Fill with color rgba_surf.fill(color(0.2f, 0.3f, 0.8f, 1.0f)); // Set individual pixels rgba_surf.set_pixel(100, 50, color::red()); rgba_surf.set_pixel(vec2i(200, 100), color::green()); // Get pixel values color pixel_color = rgba_surf.get_pixel(100, 50); color default_color = rgba_surf.get_pixel(9999, 9999, color::black()); // Direct pixel access auto& raw_pixel = rgba_surf.at(10, 20); raw_pixel = raw_pixel_type(color::blue()); // Surface properties size_t width = rgba_surf.width(); size_t height = rgba_surf.height(); size_t pixel_count = rgba_surf.pixel_count(); math::recti bounds = rgba_surf.get_rect(); // Raw data access uint8_t* data = rgba_surf.data(); size_t data_size = rgba_surf.data_size(); // Convert between pixel formats surface_rgb8 converted = rgba_surf.convert(); // Iterate over all pixels for (auto it = rgba_surf.begin(); it != rgba_surf.end(); ++it) { color c = static_cast(*it); // Process pixel *it = raw_pixel(c * 0.5f); // Darken } // Generate palette from surface colors palette pal = rgba_surf.generate_palette(); // Copy from raw data const uint8_t* source_data = /* ... */; surface_rgba8 from_data(source_data, 256, 256); ``` -------------------------------- ### Random Number Generation in Vertex C++ Source: https://context7.com/milkmull/vertex/llms.txt Provides examples of generating high-quality random numbers using the PCG algorithm within Vertex. Includes generating random integers, floats, booleans, values within ranges, and using distributions. Requires the `` header. ```cpp #include // Create RNG with system entropy vx::random::rng rng; // Generate random values uint32_t random_uint = rng.randi(); // Full uint32_t range float random_float = rng.randf(); // [0.0, 1.0) bool random_bool = rng.randb(); // true or false // Generate random values in range int dice_roll = rng.randi_range(1, 6); // [1, 6] float position = rng.randf_range(-10.0f, 10.0f); // [-10.0, 10.0] // Generate random ASCII character char random_char = rng.ascii(); // [32, 126] // Seed with specific value for reproducibility rng.seed(42); // Use distributions directly vx::random::uniform_int_distribution dist(0, 100); int value = dist(rng.use_generator()); vx::random::normal_distribution normal(0.0f, 1.0f); float gaussian_value = normal(rng.use_generator()); vx::random::bernoulli_distribution coin_flip(0.5); bool heads = coin_flip(rng.use_generator()); ``` -------------------------------- ### Install Vertex Shared Library (CMake) Source: https://github.com/milkmull/vertex/blob/main/test/CMakeLists.txt Conditionally installs the Vertex shared library to the test destination. This command is executed only if both `VX_INSTALL_TESTS` and `VX_BUILD_SHARED_LIBS` are enabled, ensuring the shared library is available alongside the tests. ```cmake if(VX_INSTALL_TESTS AND VX_BUILD_SHARED_LIBS) install(FILES "$" DESTINATION "${CMAKE_INSTALL_PREFIX}/test") endif() ``` -------------------------------- ### Build OS Shared Library (CMake) Source: https://github.com/milkmull/vertex/blob/main/test/src/vertex_test/os/CMakeLists.txt Creates a shared library named 'os_shared_library' using the 'shared_library_lib.cpp' source file. It also sets the FOLDER property for organization, applies common compiler flags, hides public symbols, and configures test installation. ```cmake add_library(os_shared_library SHARED "${CMAKE_CURRENT_SOURCE_DIR}/shared_library_lib.cpp") set_target_properties(os_shared_library PROPERTIES FOLDER "Tests/os") vx_add_common_compiler_flags(os_shared_library) vx_hide_public_symbols(os_shared_library) vx_configure_test_install(os_shared_library) ``` -------------------------------- ### Uninstall Vertex Library (Cross-Platform) Source: https://github.com/milkmull/vertex/blob/main/README.md This command utilizes CMake to uninstall previously installed Vertex library files from the system. It's a crucial command for clean uninstallation. Dependencies include a CMake build environment where the uninstall target is available. ```bash cmake --build . --target uninstall ``` -------------------------------- ### Generate CMake Package Configuration Files (CMake) Source: https://github.com/milkmull/vertex/blob/main/vertex/CMakeLists.txt This CMake configuration generates package configuration files (`.cmake`) required for other projects to find and use the installed Vertex library. It uses `write_basic_package_version_file` and `configure_package_config_file` to create version and configuration files, respectively, placing them in the install's cmake directory. ```cmake # Install the cmake config files include(CMakePackageConfigHelpers) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/VertexConfigVersion.cmake" VERSION ${PROJECT_VERSION} COMPATIBILITY AnyNewerVersion ) configure_package_config_file( "${PROJECT_SOURCE_DIR}/cmake/VertexConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/VertexConfig.cmake" PATH_VARS CMAKE_INSTALL_PREFIX INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/VertexConfigVersion.cmake" "${CMAKE_CURRENT_BINARY_DIR}/VertexConfig.cmake" DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" ) ``` -------------------------------- ### Add Test Executable Target (CMake) Source: https://github.com/milkmull/vertex/blob/main/test/CMakeLists.txt A CMake function to add a test executable target. It groups source files, creates the executable, applies common settings like folder organization and compiler flags, links necessary libraries (Vertex and a test interface), and defines a testing macro. It also handles post-build commands for shared library copying and configures installation. ```cmake function(vx_add_test TARGET PATH SOURCES) # Group source files for IDEs source_group("" FILES ${SOURCES}) # Create the test executable add_executable(${TARGET} ${SOURCES}) set_target_properties(${TARGET} PROPERTIES FOLDER "Tests/${PATH}") # Apply standard library settings and common flags vx_add_common_compiler_flags(${TARGET}) vx_hide_public_symbols(${TARGET}) # Link against Vertex target_link_libraries(${TARGET} PRIVATE Vertex) # Link against the test interface to inherit include directories target_link_libraries(${TARGET} PRIVATE vertex_test_interface) # Add testing definition target_compile_definitions(${TARGET} PRIVATE -DVX_TESTING) # Handle shared library copying for tests if(VX_BUILD_SHARED_LIBS) add_custom_command( TARGET ${TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "$" "$" COMMENT "Ensuring Vertex shared library is up-to-date for ${TARGET}." DEPENDS Vertex ) endif() # Configure installation if enabled vx_configure_test_install(${TARGET}) endfunction() ``` -------------------------------- ### Process Management in Vertex C++ Source: https://context7.com/milkmull/vertex/llms.txt Illustrates launching and controlling child processes, including I/O redirection and capturing output. Also covers retrieving and setting environment variables for the current process. Requires the `` header. ```cpp #include // Launch a background process vx::os::process proc; vx::os::process::config cfg; cfg.args = {"--verbose", "--output=result.txt"}; cfg.background = true; cfg.working_directory = vx::os::path("/home/user/project"); // Capture stdout and stderr cfg.stdout_option = vx::os::process::io_option::create; cfg.stderr_option = vx::os::process::io_option::create; if (proc.start(cfg)) { // Read process output vx::os::io_stream& stdout_stream = proc.get_stdout(); std::string line; while (stdout_stream.read_line(line)) { // Process output line by line } // Wait for completion proc.join(); // Get exit code int exit_code; if (proc.get_exit_code(&exit_code)) { if (exit_code == 0) { // Success } } } // Get current process information auto pid = vx::os::this_process::get_pid(); auto env = vx::os::this_process::get_environment(); auto path_var = vx::os::this_process::get_environment_variable("PATH"); // Set environment variable vx::os::this_process::set_environment_variable("MY_VAR", "value"); ``` -------------------------------- ### Clone and Navigate Vertex Repository (Bash) Source: https://github.com/milkmull/vertex/blob/main/README.md This snippet shows how to clone the Vertex repository from GitHub and then navigate into the newly created directory. It's a standard first step for anyone wanting to work with the Vertex codebase. ```bash git clone https://github.com/milkmull/Vertex.git cd Vertex ``` -------------------------------- ### Perform Filesystem Operations with Vertex C++ Source: https://context7.com/milkmull/vertex/llms.txt This C++ code demonstrates various filesystem operations using the vx::os::filesystem library. It covers checking file existence and type, retrieving file information, managing directories, iterating through directory contents, file copying, moving, deletion, path manipulations, and accessing system-specific paths and disk space information. Ensure the Vertex library is linked. ```cpp #include using namespace vx::os; using namespace vx::os::filesystem; // Check file existence and type if (exists("data.txt")) { if (is_regular_file("data.txt")) { // It's a file } else if (is_directory("data.txt")) { // It's a directory } } // Get file information file_info info = get_file_info("document.pdf"); if (info.exists()) { size_t file_size = info.size; time::time_point modified = info.modify_time; file_permissions perms = info.permissions; } // Directory operations path current = get_current_path(); set_current_path("/home/user/project"); create_directory("output"); create_directories("path/to/nested/dirs"); // Iterate directory contents for (const directory_entry& entry : directory_iterator("./data")) { if (entry.is_regular_file()) { std::cout << "File: " << entry.path.string() << "\n"; } else if (entry.is_directory()) { std::cout << "Dir: " << entry.path.string() << "\n"; } } // Recursive directory iteration for (const directory_entry& entry : recursive_directory_iterator(".")) { if (entry.is_regular_file()) { std::cout << entry.path.string() << " (" << entry.info.size << " bytes)\n"; } } // Copy, move, and delete copy_file("source.txt", "dest.txt", true); // overwrite if exists rename("old_name.txt", "new_name.txt"); remove("temp.txt"); size_t removed_count = remove_all("temp_dir"); // Path operations path absolute_path = absolute("../relative/path"); path relative_path = relative("/home/user/file.txt", "/home"); path canonical_path = canonical("path/with/../dots"); // Check if two paths point to same file if (equivalent("file1.txt", "symlink_to_file1.txt")) { // Same file } // System paths path temp_dir = get_temp_path(); path home = get_user_folder(user_folder::home); path documents = get_user_folder(user_folder::documents); path downloads = get_user_folder(user_folder::downloads); // Disk space information space_info space = space("/"); std::cout << "Capacity: " << space.capacity << " bytes\n"; std::cout << "Free: " << space.free << " bytes\n"; std::cout << "Available: " << space.available << " bytes\n"; // Permissions update_permissions( "script.sh", file_permissions::owner_all | file_permissions::group_read, file_permission_operator::replace ); ``` -------------------------------- ### Load and Save Images (C++) Source: https://context7.com/milkmull/vertex/llms.txt Demonstrates loading images from files (PNG, JPEG, BMP), accessing pixel data, performing pixel-wise operations like grayscale conversion, and saving processed or newly created images. Requires the 'vertex/image' library. ```cpp #include #include #include using namespace vx::img; // Load image from file image img; if (load("photo.png", img)) { // Access image properties size_t width = img.width(); size_t height = img.height(); pixel_format format = img.format(); // Get as surface if (format == pixel_format::rgba_8) { surface_rgba8& surf = img.as_rgba8(); // Process pixels for (size_t y = 0; y < height; ++y) { for (size_t x = 0; x < width; ++x) { color c = surf.get_pixel(x, y); // Apply grayscale float gray = 0.299f * c.r + 0.587f * c.g + 0.114f * c.b; surf.set_pixel(x, y, color(gray, gray, gray, c.a)); } } // Save processed image write_png("output.png", img); } } // Create and save new image surface_rgb8 gradient(256, 256); for (size_t y = 0; y < 256; ++y) { for (size_t x = 0; x < 256; ++x) { float r = static_cast(x) / 255.0f; float g = static_cast(y) / 255.0f; gradient.set_pixel(x, y, color(r, g, 0.0f)); } } image gradient_img(std::move(gradient)); write_png("gradient.png", gradient_img); write_jpeg("gradient.jpg", gradient_img, 90); // 90% quality write_bmp("gradient.bmp", gradient_img); ``` -------------------------------- ### Export Library Targets for CMake Integration (CMake) Source: https://github.com/milkmull/vertex/blob/main/vertex/CMakeLists.txt This section defines how the Vertex library targets are exported for use in other CMake projects. It installs an export file for header targets and conditionally installs either `VertexSharedTargets.cmake` or `VertexStaticTargets.cmake` based on the build configuration (`VX_BUILD_SHARED_LIBS`), ensuring correct target information is provided. ```cmake #-------------------------------------------------------------------- # Export Library Targets #-------------------------------------------------------------------- # Install export file for headers install(EXPORT VertexHeaderTargets FILE "VertexHeaderTargets.cmake" NAMESPACE Vertex:: DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" ) # Export shared or static library targets based on the build if(VX_BUILD_SHARED_LIBS) install(EXPORT VertexTargets FILE "VertexSharedTargets.cmake" NAMESPACE Vertex:: DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" ) else() install(EXPORT VertexTargets FILE "VertexStaticTargets.cmake" NAMESPACE Vertex:: DESTINATION "${CMAKE_INSTALL_PREFIX}/cmake" ) endif() ``` -------------------------------- ### File I/O Operations in Vertex C++ Source: https://context7.com/milkmull/vertex/llms.txt Demonstrates reading and writing files using Vertex's cross-platform file I/O operations. Supports writing strings, binary data, and line-based text, as well as file existence checks and streaming operations. Requires the `` header. ```cpp #include // Write text to a file vx::os::file::write_file("output.txt", "Hello, Vertex!"); // Read entire file into string std::string content; if (vx::os::file::read_file("input.txt", content)) { // File successfully loaded } // Streaming file operations vx::os::file f; if (f.open("data.bin", vx::os::file::mode::read_write_create)) { // Write binary data uint32_t magic = 0x12345678; f.write(magic); // Write array float values[] = {1.0f, 2.0f, 3.0f}; f.write(values, 3); // Write line with platform-specific ending f.write_line("Text data"); // Seek and read f.seek(0, vx::os::stream_position::begin); uint32_t read_magic; f.read(read_magic); f.close(); } // Check file existence if (vx::os::file::exists("config.ini")) { // File exists } ``` -------------------------------- ### Build Vertex Library - Windows (PowerShell) Source: https://github.com/milkmull/vertex/blob/main/README.md This code demonstrates how to build the Vertex library on Windows using CMake from the command line (PowerShell). It covers creating a build directory, configuring the build with specific Visual Studio generators and architecture, and executing the build command for both Debug and Release configurations. This requires CMake and a compatible C++ compiler (like MSVC). ```powershell # Create and enter a build directory mkdir build; cd build # Configure for Debug build cmake .. -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Debug # Build using MSBuild cmake --build . --config Debug # Alternatively, for Release build cmake .. -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release cmake --build . --config Release ``` -------------------------------- ### C++ Threading and Synchronization with Vertex OS Primitives Source: https://context7.com/milkmull/vertex/llms.txt Demonstrates creating and managing threads, using mutexes for synchronization, and performing atomic operations. It includes thread creation, joining, identification, sleeping, mutex locking/unlocking with lock guards, and atomic variable manipulation like incrementing, loading, storing, and compare-and-exchange. ```cpp #include #include #include using namespace vx::os; // Create and run threads thread worker([](void* user_data) -> uint32_t { int* value = static_cast(user_data); // Perform work *value = 42; return 0; }, &data); worker.join(); // Wait for completion // Thread identification thread::id tid = worker.get_id(); thread::id current = this_thread::get_id(); // Thread sleep this_thread::sleep_for(1000); // Sleep for 1000 milliseconds // Mutex for synchronization mutex mtx; std::vector shared_data; thread producer([](void* data) -> uint32_t { auto* info = static_cast(data); info->mtx->lock(); info->data->push_back(123); info->mtx->unlock(); return 0; }, &work_info); // Lock guard pattern { lock_guard lock(mtx); shared_data.push_back(456); } // Automatically unlocked // Atomic operations atomic counter(0); counter.fetch_add(1); // Atomic increment int value = counter.load(); counter.store(100); bool swapped = counter.compare_exchange_strong(100, 200); ``` -------------------------------- ### Build Vertex Library - Linux/macOS (Bash) Source: https://github.com/milkmull/vertex/blob/main/README.md This section details the process of building the Vertex library on Linux or macOS using CMake. It includes creating a build directory, configuring for Debug or Release builds, and executing the build command. Dependencies include CMake and a C++17 compiler. ```bash # Create and enter a build directory mkdir build && cd build # Configure for Debug build cmake .. -DCMAKE_BUILD_TYPE=Debug # Build the project cmake --build . # Alternatively, for Release build cmake .. -DCMAKE_BUILD_TYPE=Release cmake --build . ``` -------------------------------- ### Matrix and Transformation Operations in C++ Source: https://context7.com/milkmull/vertex/llms.txt Handles matrix creation, transformations (translation, rotation, scaling), and projection matrices (orthographic, perspective). It also includes view matrix generation using 'look_at' and performs matrix inversions, transpositions, and determinant calculations. ```cpp #include using namespace vx::math; // Create transformation matrices mat4f identity = mat4f::identity(); mat4f translation = translate(vec3f(10.0f, 5.0f, 0.0f)); mat4f rotation = rotate_z(radians(45.0f)); mat4f scale_mat = scale(vec3f(2.0f, 2.0f, 2.0f)); // Combine transformations mat4f transform = translation * rotation * scale_mat; // Apply transformation to vector vec3f point(1.0f, 0.0f, 0.0f); vec4f homogeneous(point, 1.0f); vec4f transformed = transform * homogeneous; // Projection matrices mat4f ortho = ortho2d(0.0f, 800.0f, 0.0f, 600.0f); mat4f persp = perspective( radians(45.0f), // FOV 16.0f / 9.0f, // Aspect ratio 0.1f, // Near plane 100.0f // Far plane ); // View matrix (look at) vec3f eye(0.0f, 5.0f, 10.0f); vec3f center(0.0f, 0.0f, 0.0f); vec3f up(0.0f, 1.0f, 0.0f); mat4f view = look_at(eye, center, up); // Matrix operations mat4f inverted = inverse(transform); mat4f transposed = transpose(transform); float determinant_val = determinant(transform); ``` -------------------------------- ### Define General Main Source Files (CMake) Source: https://github.com/milkmull/vertex/blob/main/vertex/src/vertex_impl/app/main/CMakeLists.txt This snippet uses CMake's GLOB command to find all source files in the current directory matching the pattern, typically the main application entry points. These files are then added to the 'Vertex' target's sources. ```cmake file(GLOB VX_APP_MAIN_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/main_internal.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/main.cpp" ) target_sources(Vertex PRIVATE ${VX_APP_MAIN_SOURCE_FILES}) ``` -------------------------------- ### Displaying Build Configuration Summary in CMake Source: https://github.com/milkmull/vertex/blob/main/CMakeLists.txt This CMake code prints a summary of the project's build configuration options to the console during the configuration phase. It uses `message(STATUS ...)` and a helper macro `print_option` (assumed to be defined elsewhere) to display the status of various build flags. ```cmake message(STATUS "-----------------------------------------") message(STATUS "Vertex Configuration Summary:") message(STATUS "-----------------------------------------") # Build / Runtime print_option(VX_BUILD_SHARED_LIBS "Shared Libraries") print_option(VX_DUMMY_PLATFORM "Dummy Platform") print_option(VX_MATH_SIMD_ENABLED "SIMD Math") print_option(VX_GUI_APP "GUI Application") # print_option(VX_ENABLE_ASAN "AddressSanitizer") # uncomment if needed # Library Modules print_option(VX_IMAGE_ENABLED "Image Module") # print_option(VX_NETWORK_ENABLED "Network Module") # App Features print_option(VX_APP_ENABLED "Application Features") if(VX_APP_ENABLED) print_option(VX_APP_VIDEO_ENABLED " Video Backend") print_option(VX_APP_RENDERER_ENABLED " Renderer Backend") print_option(VX_APP_AUDIO_ENABLED " Audio Backend") endif() # Testing / Sandbox print_option(VX_BUILD_TESTS "Build Tests") print_option(VX_INSTALL_TESTS "Install Tests") print_option(VX_BUILD_SANDBOX "Build Sandbox") message(STATUS "-----------------------------------------") ``` -------------------------------- ### Include Dummy Module Headers (CMake) Source: https://github.com/milkmull/vertex/blob/main/vertex/src/vertex_impl/os/CMakeLists.txt This CMake code snippet uses the `file(GLOB ...)` command to collect all header files from the '_platform/dummy' directory. These headers are intended for a dummy or generic implementation of system modules. The collected files are then added as source files to the 'Vertex' target. ```cmake file(GLOB VX_OS_DUMMY_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_file.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_filesystem.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_locale.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_mutex.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_process.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_random.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_shared_library.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_system_info.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_thread.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_time.hpp" ) target_sources(Vertex PRIVATE ${VX_OS_DUMMY_SOURCE_FILES}) ``` -------------------------------- ### String Utilities: Checks, Transformations, Search, Split/Join (C++) Source: https://context7.com/milkmull/vertex/llms.txt Provides a comprehensive set of C++ string manipulation functions, including character and string validation (digits, alpha, hex), case conversion, case-insensitive comparison, substring searching, whitespace trimming, prefix/suffix operations, splitting by delimiters, joining elements, repetition, reversal, and numeric/hex conversions. Requires the 'vertex/util/string' library. ```cpp #include using namespace vx::str; // Character and string checks bool is_num = is_digit('5'); // true bool all_alpha = is_alpha("Hello"); // true bool all_alnum = is_alnum("Test123"); // true bool is_hex_val = is_hex("0xFF", true); // true // Case conversion std::string upper = to_upper("hello"); // "HELLO" std::string lower = to_lower("WORLD"); // "world" std::string titled = title("hello world"); // "Hello World" // Case-insensitive comparison bool same = casecmp("Hello", "HELLO"); // true // String search bool has_substr = contains("Hello World", "World"); // true size_t count_char = count("banana", 'a'); // 3 bool starts = starts_with("filename.txt", "file"); // true bool ends = ends_with("document.pdf", ".pdf"); // true // Whitespace trimming std::string trimmed = strip(" hello "); // "hello" std::string left = lstrip(" hello "); // "hello " std::string right = rstrip(" hello "); // " hello" // Prefix/suffix operations std::string no_prefix = trim_prefix("prefix_name", "prefix_"); // "name" std::string no_suffix = trim_suffix("file.txt", ".txt"); // "file" // String modification std::string removed = remove("banana", 'a'); // "bnn" std::string replaced = replace("hello world", "world", "C++"); // "hello C++" // Splitting and joining std::vector parts = split("a,b,c", ','); // ["a", "b", "c"] std::vector words = split_words(" hello world "); // ["hello", "world"] std::vector lines = split_lines("line1\nline2"); // ["line1", "line2"] std::string joined = join(parts.begin(), parts.end(), ", "); // "a, b, c" std::string concat_str = concat(words.begin(), words.end()); // "helloworld" // Repetition and reversal std::string repeated = repeat("ab", 3); // "ababab" std::string reversed = reverse("hello"); // "olleh" // Numeric conversions int32_t num = to_int32("42"); uint64_t big_num = to_uint64("9876543210"); float f = to_float("3.14159"); double d = to_double("2.71828"); // Hex string conversion uint8_t data[] = {0xDE, 0xAD, 0xBE, 0xEF}; std::string hex = to_hex_string(data, 4); // "DEADBEEF" ``` -------------------------------- ### GLOB Dummy Video Source Files (CMake) Source: https://github.com/milkmull/vertex/blob/main/vertex/src/vertex_impl/app/video/CMakeLists.txt Collects header files for dummy video and window modules. These are typically used for testing or as placeholders when a specific platform implementation is not available. The GLOB command simplifies the process of including multiple related files. ```cmake file(GLOB VX_APP_VIDEO_DUMMY_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_features.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_video.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_window.hpp" ) target_sources(Vertex PRIVATE ${VX_APP_VIDEO_DUMMY_SOURCE_FILES}) ``` -------------------------------- ### Include General Application Source Files (CMake) Source: https://github.com/milkmull/vertex/blob/main/vertex/src/vertex_impl/app/CMakeLists.txt This snippet uses CMake's `file(GLOB ...)` command to collect all source files for the general application components. These files are then added to the 'Vertex' target using `target_sources`. ```cmake file(GLOB VX_APP_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/app_internal.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/app.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/message_box_internal.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/message_box.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/hints.cpp" ) target_sources(Vertex PRIVATE ${VX_APP_SOURCE_FILES}) ``` -------------------------------- ### Configure Shared Library Test - CMake Source: https://github.com/milkmull/vertex/blob/main/test/install/CMakeLists.txt This snippet sets up a test executable for the Vertex shared library. It links against both the headers and the shared library (`Vertex::Vertex_Shared`). For Windows, it includes a custom command to copy the DLL to the executable directory after the build. It provides a warning if the shared library is not found. ```cmake if(TARGET Vertex::Vertex_Shared) message(STATUS "Linking against Vertex shared library.") add_executable(shared_library_test shared_main.cpp) target_link_libraries(shared_library_test PRIVATE Vertex::Headers Vertex::Vertex_Shared) get_target_property(SHARED_LIB_LOCATION Vertex::Vertex_Shared LOCATION) message(STATUS "Found shared library at: ${SHARED_LIB_LOCATION}") if(WIN32 AND SHARED_LIB_LOCATION) add_custom_command(TARGET shared_library_test POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "$" "$" ) message(STATUS "Configured to copy DLL to executable directory.") endif() else() message(WARNING "Vertex shared library not found. Skipping shared library test.") endif() ``` -------------------------------- ### Configure Static Library Test - CMake Source: https://github.com/milkmull/vertex/blob/main/test/install/CMakeLists.txt This snippet configures a test executable for the Vertex static library. It links against both the headers and the static library (`Vertex::Vertex_Static`). It prints the location of the static library and includes a warning if the static library is not found. ```cmake if(TARGET Vertex::Vertex_Static) message(STATUS "Linking against Vertex static library.") add_executable(static_library_test static_main.cpp) target_link_libraries(static_library_test PRIVATE Vertex::Headers Vertex::Vertex_Static) get_target_property(STATIC_LIB_LOCATION Vertex::Vertex_Static LOCATION) message(STATUS "Found static library at: ${STATIC_LIB_LOCATION}") else() message(WARNING "Vertex static library not found. Skipping static library test.") endif() ``` -------------------------------- ### Add OS Filesystem Test (CMake) Source: https://github.com/milkmull/vertex/blob/main/test/src/vertex_test/os/CMakeLists.txt Defines and adds the 'test_os_filesystem' test case for the 'os' component, linking it to the 'filesystem.cpp' source file. This ensures filesystem-related tests are part of the build. ```cmake vx_add_test(test_os_filesystem "os" "${CMAKE_CURRENT_SOURCE_DIR}/filesystem.cpp") ``` -------------------------------- ### Add Vertex Project Subdirectories in CMake Source: https://github.com/milkmull/vertex/blob/main/vertex/include/vertex/app/CMakeLists.txt This snippet demonstrates how to add subdirectories to the CMake build process for the Vertex project. It includes the 'hints' and 'event' modules unconditionally. The 'input' and 'video' modules are added conditionally, only if VX_APP_VIDEO_ENABLED is true, allowing for modular build configurations. ```cmake add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/hints") add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/event") if(VX_APP_VIDEO_ENABLED) add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/input") add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/video") endif() ``` -------------------------------- ### Define Dummy Event Header Files (CMake) Source: https://github.com/milkmull/vertex/blob/main/vertex/src/vertex_impl/app/event/CMakeLists.txt This CMake snippet defines header files for dummy event modules. It uses `file(GLOB ...)` to find header files in a dummy platform directory and `target_sources` to link them to the 'Vertex' target. This is typically used for maintaining cross-platform compatibility when platform-specific implementations are not available. ```cmake file(GLOB VX_APP_EVENT_DUMMY_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/_platform/dummy/dummy_event.hpp" ) target_sources(Vertex PRIVATE ${VX_APP_EVENT_DUMMY_SOURCE_FILES}) ``` -------------------------------- ### Creating an Uninstall Target in CMake Source: https://github.com/milkmull/vertex/blob/main/CMakeLists.txt This CMake snippet configures an uninstall target for the project. It uses `configure_file` to generate an `Uninstall.cmake` script and then adds a custom target named 'uninstall' to execute it. ```cmake configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Uninstall.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/cmake/Uninstall.cmake" IMMEDIATE @ONLY ) add_custom_target(uninstall COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake/Uninstall.cmake" ) ``` -------------------------------- ### Add OS Process Test and Dependency (CMake) Source: https://github.com/milkmull/vertex/blob/main/test/src/vertex_test/os/CMakeLists.txt Adds the 'test_os_process' test case for the 'os' component using 'process.cpp'. It also explicitly adds a dependency on 'os_child_process', ensuring child process functionalities are available for process tests. ```cmake vx_add_test(test_os_process "os" "${CMAKE_CURRENT_SOURCE_DIR}/process.cpp") add_dependencies(test_os_process os_child_process) ``` -------------------------------- ### Define Executable and Source Groups (CMake) Source: https://github.com/milkmull/vertex/blob/main/sandbox/CMakeLists.txt Defines the main executable target 'Sandbox' and organizes source files into logical groups using CMake. It specifies the main source file and includes subdirectories for header and source files. Dependencies include CMake commands and source files within the project. ```cmake add_executable(Sandbox "${CMAKE_CURRENT_SOURCE_DIR}/src/sandbox.cpp") add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/include/sandbox") add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/src") vx_create_source_groups(Sandbox "${CMAKE_CURRENT_SOURCE_DIR}") target_sources(Sandbox PRIVATE ${SB_FILES}) target_include_directories(Sandbox PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include") ``` -------------------------------- ### Post-Build Copy for Shared Libraries (CMake) Source: https://github.com/milkmull/vertex/blob/main/sandbox/CMakeLists.txt Adds a custom build command to copy the 'Vertex' shared library (DLL) to the output directory of the 'Sandbox' executable after the build, but only if VX_BUILD_SHARED_LIBS is enabled. This ensures the executable can find its dependencies. Dependencies include CMake commands and the 'Vertex' target. ```cmake if(VX_BUILD_SHARED_LIBS) add_custom_command(TARGET Sandbox POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy "$" # This gets the full path to the Vertex DLL "$" # This gets the output directory of the Sandbox executable ) endif() ``` -------------------------------- ### Define General Event Source Files (CMake) Source: https://github.com/milkmull/vertex/blob/main/vertex/src/vertex_impl/app/event/CMakeLists.txt This CMake snippet defines a list of general source and header files for event handling in the Vertex application. It uses `file(GLOB ...)` to collect files matching a pattern and `target_sources` to add them to the 'Vertex' target. Dependencies include CMake and the specified directory structure. ```cmake file(GLOB VX_APP_EVENT_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/event_watch.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/event_watch.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/temporary_memory_pool.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/_platform/platform_event.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/event_internal.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/event.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/signal.cpp" ) target_sources(Vertex PRIVATE ${VX_APP_EVENT_SOURCE_FILES}) ``` -------------------------------- ### Add OS File Test (CMake) Source: https://github.com/milkmull/vertex/blob/main/test/src/vertex_test/os/CMakeLists.txt Registers a new test target 'test_os_file' for the 'os' component, which will execute tests defined in the 'file.cpp' source file. This is a standard way to include file-related tests in the build system. ```cmake vx_add_test(test_os_file "os" "${CMAKE_CURRENT_SOURCE_DIR}/file.cpp") ``` -------------------------------- ### Link Libraries and Set Windows Subsystem (CMake) Source: https://github.com/milkmull/vertex/blob/main/sandbox/CMakeLists.txt Configures linking for the 'Sandbox' executable and conditionally sets the Windows subsystem based on the VX_GUI_APP variable. This ensures correct behavior for GUI applications on Windows. Dependencies include CMake commands and the 'Vertex' library. ```cmake target_link_libraries(Sandbox PRIVATE Vertex) # On Windows, set the correct subsystem automatically if(WIN32 AND VX_GUI_APP) # GUI subsystem (WinMain entry point, no console) set_target_properties(Sandbox PROPERTIES LINK_FLAGS "/SUBSYSTEM:WINDOWS") endif() ``` -------------------------------- ### Define OS Path Source Files (CMake) Source: https://github.com/milkmull/vertex/blob/main/test/src/vertex_test/os/CMakeLists.txt Uses CMake's file GLOB command to find all source files for the OS path functionality, including 'path.hpp' and 'path.cpp', and stores them in the VX_OS_PATH_SRC_FILES variable. This simplifies managing multiple source files for a component. ```cmake file(GLOB VX_OS_PATH_SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/path.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/path.cpp" ) ``` -------------------------------- ### Include stb_image Library Headers (CMake) Source: https://github.com/milkmull/vertex/blob/main/vertex/src/vertex_impl/image/CMakeLists.txt Configures the Vertex target to include the header files for the stb_image library. This allows the project to use stb_image for image loading and writing functionalities. No external dependencies are required beyond the stb_image source files. ```cmake target_include_directories(Vertex PRIVATE "${VX_THIRD_PARTY_DIR}/stb_image/include") file(GLOB STB_IMAGE_FILES "${VX_THIRD_PARTY_DIR}/stb_image/include/stb_image/stb_image.h" "${VX_THIRD_PARTY_DIR}/stb_image/include/stb_image/stb_image_write.h" ) target_sources(Vertex PRIVATE ${STB_IMAGE_FILES}) ``` -------------------------------- ### Include Vertex Input Header Files in CMake Source: https://github.com/milkmull/vertex/blob/main/vertex/include/vertex/app/input/CMakeLists.txt This snippet demonstrates how to use the `file(GLOB ...)` command in CMake to gather all input-related header files and then include them in the `Vertex` target's sources. This ensures that all necessary input functionalities are compiled with the main application. ```cmake file(GLOB VX_APP_INPUT_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}/clipboard.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/mouse.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/keyboard.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/keycode.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/scancode.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/touch.hpp" "${CMAKE_CURRENT_SOURCE_DIR}/pen.hpp" ) target_sources(Vertex PRIVATE ${VX_APP_INPUT_HEADER_FILES}) ``` -------------------------------- ### Include Directories for Vertex Library (CMake) Source: https://github.com/milkmull/vertex/blob/main/vertex/CMakeLists.txt Sets the include directories for the Vertex library. It defines public include paths for both build-time and install-time, and a private include path for source files. The Vertex_Headers target also has an interface include path defined. ```cmake # Include directories for headers target_include_directories(Vertex PUBLIC "$" # When building the project PUBLIC "$" # When using the installed project PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src" ) # Header-only interface to be inherited by builds linking against Vertex target_include_directories(Vertex_Headers INTERFACE "$" # When building the project "$" # When using the installed project ) ``` -------------------------------- ### Configuring IDE Folder Grouping in CMake Source: https://github.com/milkmull/vertex/blob/main/CMakeLists.txt This CMake command enables folder grouping for IDEs, organizing project files into collapsible folders within the development environment for better project navigation. ```cmake set_property(GLOBAL PROPERTY USE_FOLDERS ON) ``` -------------------------------- ### Add OS System Info Test (CMake) Source: https://github.com/milkmull/vertex/blob/main/test/src/vertex_test/os/CMakeLists.txt Adds a test case named 'test_os_system_info' for the 'os' component, linking it to the 'system_info.cpp' source file. This is a standard CMake function for defining test targets. ```cmake vx_add_test(test_os_system_info "os" "${CMAKE_CURRENT_SOURCE_DIR}/system_info.cpp") ``` -------------------------------- ### CMake: Include Standard and Custom Modules Source: https://github.com/milkmull/vertex/blob/main/CMakeLists.txt Includes standard CMake modules like CheckCXXCompilerFlag, CMakePushCheckState, and GNUInstallDirs, along with Vertex-specific modules for configuration, macros, functions, and checks. ```cmake # Include standard CMake modules include(CheckCXXCompilerFlag) include(CMakePushCheckState) include(GNUInstallDirs) # Include Vertex-specific modules include(cmake/Config.cmake) include(cmake/Macros.cmake) include(cmake/Functions.cmake) include(cmake/Checks.cmake) ```