How oguztoraman/libmagicxx works
Project type and purpose
• Libmagicxx is a native C++ wrapper library (API-only, no UI) over the libmagic C library, exposing a magic class for file-type recognition.
• It is built and packaged via CMake for consumption by downstream C++ projects, and includes tests, examples, CI workflows, and generated documentation.
File structure
• Top-level CMakeLists.txt, CMakePresets.json, cmake/ modules: define build targets (shared/static libs), packaging and installation rules.
• include/magicxx/: public headers that define the C++ API.
• sources/: implementation of the wrapper (magic.cpp).
• external/: vendored dependencies (googletest, libgnurx, and a copy of the libmagic header).
• tests/: unit tests using GoogleTest.
• examples/: example applications demonstrating API usage.
• documentation/html/: Doxygen-generated API docs.
• .github/workflows/, Containerfile, scripts/: CI/CD pipelines, container builds, release automation, and install scripts.
Key insights from README
• Core functionality: provide C++23 high-level, exception-safe API for libmagic (states, flags, identify calls).
• Package variables for CMake consumers (include dirs, lib dirs, version, shared vs static).
• Multi-platform support (Linux/Windows) and packaging formats (DEB, RPM, NSIS installer).
• Examples and docs are first-class artifacts, integrated into CI.
Components
a. Main components
1. C++ Wrapper Module
• Public API (headers in include/magicxx/)
• Implementation (sources/magic.cpp)
2. libmagic (underlying C library)
• Dynamically or statically linked
3. Build System & Packaging
• CMake core files + custom cmake/ modules
• Packaging config (CPack scripts: DEB, RPM, NSIS)
4. External Dependencies
• libgnurx (regex engine)
• GoogleTest (unit testing)
5. Examples & Tests
• Example executables (in examples/)
• Test suite (in tests/)
6. Documentation
• Doxygen generator → static HTML (documentation/html/)
7. CI/CD Pipelines
• GitHub Actions workflows (build & test on Linux/Windows, deploy docs and packages)
• Containerfile for reproducible builds
b. Relationships and interactions
• The C++ Wrapper invokes libmagic APIs (FFI boundary).
• CMake orchestrates compilation of sources/ into libmagicxx (shared/static), links against libmagic and libgnurx.
• Tests and examples link against the built library.
• Doxygen reads public headers to generate HTML docs.
• CI pipelines trigger CMake builds, run tests, generate docs, and deploy release artifacts.
c. Architectural patterns and principles
• Modular CMake design (separate modules for dependencies, installation, packaging).
• Single shared core component (the wrapper) with optional static linkage.
• Clear separation: public API layer vs private implementation.
• Test-driven validation (GoogleTest).
• Infrastructure as code (CI workflows + scripts directory).
d. Relevant technologies & frameworks
• C++23, libmagic C library
• CMake (with custom modules & CPack)
• GoogleTest (unit testing)
• Doxygen (documentation)
• GitHub Actions (CI/CD)
• Containerfile/Docker for build isolation