From f247f400d86e82fd2a350aa95c1f5398ce8e3582 Mon Sep 17 00:00:00 2001 From: xyz1001 Date: Tue, 26 Mar 2024 11:24:19 +0800 Subject: [PATCH] platformfolders: add new recipe for platformfolders --- recipes/platformfolders/all/conandata.yml | 4 ++ recipes/platformfolders/all/conanfile.py | 70 +++++++++++++++++++ .../all/test_package/CMakeLists.txt | 8 +++ .../all/test_package/conanfile.py | 26 +++++++ .../all/test_package/test_package.cpp | 20 ++++++ recipes/platformfolders/config.yml | 3 + 6 files changed, 131 insertions(+) create mode 100644 recipes/platformfolders/all/conandata.yml create mode 100644 recipes/platformfolders/all/conanfile.py create mode 100644 recipes/platformfolders/all/test_package/CMakeLists.txt create mode 100644 recipes/platformfolders/all/test_package/conanfile.py create mode 100644 recipes/platformfolders/all/test_package/test_package.cpp create mode 100644 recipes/platformfolders/config.yml diff --git a/recipes/platformfolders/all/conandata.yml b/recipes/platformfolders/all/conandata.yml new file mode 100644 index 0000000000000..be79160f2c84f --- /dev/null +++ b/recipes/platformfolders/all/conandata.yml @@ -0,0 +1,4 @@ +sources: + "4.2.0": + url: "https://github.com/sago007/PlatformFolders/archive/refs/tags/4.2.0.tar.gz" + sha256: "31bb0f64a27315aec8994f226332aaafe9888d00bb69a2ff2dff9912e2f4ccf4" diff --git a/recipes/platformfolders/all/conanfile.py b/recipes/platformfolders/all/conanfile.py new file mode 100644 index 0000000000000..8b4f2170876c9 --- /dev/null +++ b/recipes/platformfolders/all/conanfile.py @@ -0,0 +1,70 @@ +from conan import ConanFile +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout +from conan.tools.files import copy, get, rmdir +from conan.errors import ConanInvalidConfiguration +import os + +required_conan_version = ">=1.53.0" + + +class PlatformFoldersConan(ConanFile): + name = "platformfolders" + license = "MIT" + homepage = "https://github.com/sago007/PlatformFolders" + url = "https://github.com/conan-io/conan-center-index" + description = "A C++ library to look for special directories like \"My Documents\" and \"%APPDATA%\" so that you do not need to write Linux, Windows or Mac OS X specific code" + topics = ("multi-platform", "xdg", "standardpaths", "special-folders") + package_type = "static-library" + settings = "os", "arch", "compiler", "build_type" + options = { + "fPIC": [True, False], + } + default_options = { + "fPIC": True, + } + + @property + def _minimum_cpp_standard(self): + return 11 + + def validate(self): + if self.settings.compiler.cppstd: + check_min_cppstd(self, self._minimum_cpp_standard) + if not self.settings.os in ("Windows", "Macos", "Linux"): + raise ConanInvalidConfiguration("This library only supports Windows, macOS and Linux") + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def layout(self): + cmake_layout(self, src_folder="src") + + def build_requirements(self): + self.tool_requires("cmake/[>=3.1 <4]") + + def source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["PLATFORMFOLDERS_BUILD_TESTING"] = False + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def package(self): + copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() + + rmdir(self, os.path.join(self.package_folder, "cmake")) + rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) + + def package_info(self): + self.cpp_info.libs = ["platform_folders"] + diff --git a/recipes/platformfolders/all/test_package/CMakeLists.txt b/recipes/platformfolders/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..cb747ceeb1e6d --- /dev/null +++ b/recipes/platformfolders/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(platformfolders REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE platformfolders::platformfolders) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11) diff --git a/recipes/platformfolders/all/test_package/conanfile.py b/recipes/platformfolders/all/test_package/conanfile.py new file mode 100644 index 0000000000000..34be4a6e879fa --- /dev/null +++ b/recipes/platformfolders/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +from conan import ConanFile +from conan import ConanFile +from conan.tools.build import can_run +from conan.tools.cmake import CMake, cmake_layout +import os + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv" + test_type = "explicit" + + def layout(self): + cmake_layout(self) + + def requirements(self): + self.requires(self.tested_reference_str, run=can_run(self)) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if can_run(self): + self.run(os.path.join(self.cpp.build.bindirs[0], "test_package"), env="conanrun") diff --git a/recipes/platformfolders/all/test_package/test_package.cpp b/recipes/platformfolders/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..4570e8f5de608 --- /dev/null +++ b/recipes/platformfolders/all/test_package/test_package.cpp @@ -0,0 +1,20 @@ +#include +#include + +#include + +int main() { + std::cout << "Config: " << sago::getConfigHome() << "\n"; + std::cout << "Data: " << sago::getDataHome() << "\n"; + std::cout << "State: " << sago::getStateDir() << "\n"; + std::cout << "Cache: " << sago::getCacheDir() << "\n"; + std::cout << "Documents: " << sago::getDocumentsFolder() << "\n"; + std::cout << "Desktop: " << sago::getDesktopFolder() << "\n"; + std::cout << "Pictures: " << sago::getPicturesFolder() << "\n"; + std::cout << "Music: " << sago::getMusicFolder() << "\n"; + std::cout << "Video: " << sago::getVideoFolder() << "\n"; + std::cout << "Download: " << sago::getDownloadFolder() << "\n"; + std::cout << "Save Games 1: " << sago::getSaveGamesFolder1() << "\n"; + std::cout << "Save Games 2: " << sago::getSaveGamesFolder2() << "\n"; + return 0; +} diff --git a/recipes/platformfolders/config.yml b/recipes/platformfolders/config.yml new file mode 100644 index 0000000000000..1b309b8e878d8 --- /dev/null +++ b/recipes/platformfolders/config.yml @@ -0,0 +1,3 @@ +versions: + "4.2.0": + folder: "all"