📂 Python's platformdirs module for C++
std::println("user_data_dir: {}", dirs.user_data_dir());
std::println("user_config_dir: {}", dirs.user_config_dir());
std::println("user_cache_dir: {}", dirs.user_cache_dir());
std::println("user_state_dir: {}", dirs.user_state_dir());
std::println("user_log_dir: {}", dirs.user_log_dir());
std::println("...and more!");
user_data_dir: ~/.local/share/MyApp/1.0
user_config_dir: ~/.config/MyApp/1.0
user_cache_dir: ~/.cache/MyApp/1.0
user_state_dir: ~/.local/state/MyApp/1.0
user_log_dir: ~/.local/state/MyApp/1.0/log
...and more!
🐍 Same API surface as platformdirs \ 🔺 Works great with CMake \ 💅 Uses platformdirs' opinionated directories \ 🟦 Works on Windows \ 🌌 Works with cosmocc!
Installation
- CMake
find_package()
with FetchContent
fallback
-
include(FetchContent)
FetchContent_Declare(platformdirs
GIT_REPOSITORY https://github.com/jcbhmr/platformdirs-cpp.git
GIT_TAG v0.1.0
FIND_PACKAGE_ARGS 0.1.0...<1)
# Will try find_package(platformdirs 0.1.0...<1) first
FetchContent_MakeAvailable(platformdirs)
# ...
# Now link it into your app/lib target
target_link_libraries(myapp platformdirs::platformdirs)
target_link_libraries(mylib platformdirs::platformdirs)
Usage
main.cpp
#include <print>
#include <platformdirs.h>
return 0;
}
📚 See the complete API surface on the website
💡 Pro tip: there's an included platformdirs
executable which prints a report of all the config dirs for you. It's great for debugging! 😉
Development
cmake --workflow --preset default
cmake --workflow --preset test