Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jcbhmr/platformdirs-cpp
📂 Python's platformdirs module for C++
https://github.com/jcbhmr/platformdirs-cpp
cmake cpp cpp-library platformdirs port xdg
Last synced: 9 days ago
JSON representation
📂 Python's platformdirs module for C++
- Host: GitHub
- URL: https://github.com/jcbhmr/platformdirs-cpp
- Owner: jcbhmr
- License: mit
- Created: 2024-08-01T21:42:11.000Z (5 months ago)
- Default Branch: main
- Last Pushed: 2024-08-16T22:50:27.000Z (4 months ago)
- Last Synced: 2024-10-27T11:19:14.390Z (about 2 months ago)
- Topics: cmake, cpp, cpp-library, platformdirs, port, xdg
- Language: C++
- Homepage: https://jcbhmr.me/platformdirs-cpp
- Size: 63.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# platformdirs for C++
📂 Python's [platformdirs](https://pypi.org/project/platformdirs/) module for C++
```cpp
auto dirs = platformdirs::platform_dirs(app_name, app_author, "1.0");
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](https://pypi.org/project/platformdirs/) \
🔺 Works great with CMake \
💅 Uses platformdirs' opinionated directories \
**🟦 Works on Windows** \
🌌 Works with [cosmocc](https://github.com/jart/cosmopolitan/tree/master/tool/cosmocc)!## Installation
![CMake](https://img.shields.io/static/v1?style=for-the-badge&message=CMake&color=064F8C&logo=CMake&logoColor=FFFFFF&label=)
- CMake
find_package()
withFetchContent
fallback -
```cmake
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
![C++](https://img.shields.io/static/v1?style=for-the-badge&message=C%2B%2B&color=00599C&logo=C%2B%2B&logoColor=FFFFFF&label=)
main.cpp
```cpp
#include
#include
int main() {
std::println("my app config: {}", platformdirs::user_config_dir("myapp", "me", "1.2.3"));
return 0;
}
```
[📚 See the complete API surface on the website](https://jcbhmr.me/platformdirs/)
💡 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](https://img.shields.io/static/v1?style=for-the-badge&message=CMake&color=064F8C&logo=CMake&logoColor=FFFFFF&label=)
```sh
cmake --workflow --preset default
cmake --workflow --preset test
```