Skip to content

NoahGWood/PlatformDirs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PlatformDirs

A single-header C++17+ library for retrieving cross-platform application directories such as config, cache, data, and log folders. Supports Windows, macOS, Linux, Android (via JNI), and iOS (via Foundation).

CI Ubuntu CI macOS CI Windows

Features

  • Cross-platform: Windows, macOS, Linux, Android, iOS
  • Clean std::filesystem::path API
  • Header-only, zero external dependencies
  • Supports app-specific folder resolution
  • JNI and Objective-C++ hooks for mobile

Usage

#include "platform_dirs.hpp"

auto config_path = platform_dirs::get_app_dir("MyApp");

Android Setup

You must call platform_dirs::init() with the JNI context before using get_app_dir():

extern "C" JNIEXPORT void JNICALL
Java_com_example_MainActivity_init(JNIEnv* env, jobject ctx) {
    platform_dirs::init(env, ctx);
}

iOS

Include the file in an Objective-C++ (.mm) file if using iOS.

Utility Methods

  • get_app_dir(app_name)
  • get_config_dir(app_name)
  • get_cache_dir(app_name)
  • get_data_dir(app_name)
  • get_log_dir(app_name)
  • get_temp_dir() (no app name needed)

Design Notes

  • Falls back to $HOME/.config or platform-specific conventions
  • Uses getenv() for desktop env vars
  • Android and iOS use system APIs via JNI and Foundation respectively
  • Returns empty path or /tmp if fallback is needed

Build

No build system needed — just include the header. For CMake:

target_include_directories(your_target PRIVATE vendor/PlatformDirs/include)

License

Licensed under GPLv3

About

A lightweight single-header C++17+ library for getting OS-specific config, data, cache, and log directories.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors