src/Lib/OS/. Each platform has its own implementation file for system information gathering.
Supported platforms
Currently supported platforms:| File | Platform | Status |
|---|---|---|
Windows.cpp | Windows 10/11 | Full support |
Linux.cpp | Linux (glibc/musl) | Full support |
macOS.cpp | macOS 12+ | Full support |
BSD.cpp | FreeBSD, OpenBSD, NetBSD | Full support |
Haiku.cpp | Haiku OS | Full support |
Serenity.cpp | SerenityOS | Full support |
Adding a new platform
Check for existing abstractions
Review the public API in
include/Drac++/Core/System.hpp to see which functions need implementation.Common functions to implement:GetMemInfo()- Memory usage informationGetOperatingSystem()- OS version and nameGetDesktopEnvironment()- Desktop environment detectionGetCpuInfo()- CPU information- And many more…
Implement platform-specific functions
Implement each function using platform-specific APIs. Use preprocessor guards to conditionally compile code.
Platform detection macros
The build system defines these macros for compile-time platform detection:| Macro | Condition |
|---|---|
DRAC_ARCH_X86_64 | x86_64 architecture |
DRAC_ARCH_AARCH64 | ARM64 architecture |
DRAC_ARCH_64BIT | 64-bit pointer size |
DRAC_DEBUG | Debug build |
| Macro | Platform |
|---|---|
__linux__ | Linux |
_WIN32 | Windows |
__APPLE__ | macOS |
__FreeBSD__ | FreeBSD |
__OpenBSD__ | OpenBSD |
__NetBSD__ | NetBSD |
__HAIKU__ | Haiku OS |
Using preprocessor guards
Use preprocessor guards to write platform-specific code:Example: Adding a new system info function
Step 1: Declare in header
Add the function declaration toinclude/Drac++/Core/System.hpp:
Step 2: Implement for Windows
Insrc/Lib/OS/Windows.cpp:
Step 3: Implement for Linux
Insrc/Lib/OS/Linux.cpp:
Step 4: Implement for macOS
Insrc/Lib/OS/macOS.cpp (or create src/Lib/OS/macOS/Battery.mm for Objective-C++):
Platform-specific notes
Windows
- Use
WStringfor Windows API calls requiringwchar_t* - Convert between UTF-8 and UTF-16:
ConvertWStringToUTF8()- Wide string to UTF-8ConvertUTF8ToWString()- UTF-8 to wide string
- Link against Windows libraries:
dwmapi,windowsapp,setupapi,dxgi - Use COM APIs when necessary, ensure proper initialization and cleanup
macOS
- Objective-C++ code goes in
src/Lib/OS/macOS/ - Use
.mmextension for Objective-C++ files - Link frameworks via
appleframeworksdependency in Meson - Use Core Foundation and IOKit for system information
- Always release CF objects with
CFRelease()
Linux
- Optional dependencies:
xcb,wayland-client,dbus-1,pugixml - Check feature flags:
DRAC_USE_XCB- X11/XCB supportDRAC_USE_WAYLAND- Wayland support
- Read system info from:
/proc/- Process and system information/sys/- Device and driver information/etc/- System configuration
BSD
- Use
sysctlandsysctlbynamefor system information - Different BSD variants have different sysctl names
- Check platform macros:
__FreeBSD__,__OpenBSD__,__NetBSD__,__DragonFly__
Testing platform-specific code
When adding platform support:- Test on actual hardware - Virtual machines may not expose all features
- Test edge cases - Missing files, permission denied, invalid values
- Add unit tests - Test parsing and error handling
- Document failure modes - What can go wrong and when
Next steps
Code style
Review code style guidelines
Testing
Learn about testing requirements