From d2a17b8b9fd4a6bde0045a1ce65de7d568b6eb39 Mon Sep 17 00:00:00 2001 From: Uilian Ries Date: Mon, 1 Apr 2024 16:16:48 +0200 Subject: [PATCH] Support shared library Signed-off-by: Uilian Ries --- recipes/platformfolders/all/conanfile.py | 25 +++++++++++++------ .../all/test_package/CMakeLists.txt | 4 +-- .../all/test_package/conanfile.py | 2 +- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/recipes/platformfolders/all/conanfile.py b/recipes/platformfolders/all/conanfile.py index 8b4f2170876c9..145c878684f22 100644 --- a/recipes/platformfolders/all/conanfile.py +++ b/recipes/platformfolders/all/conanfile.py @@ -2,6 +2,7 @@ 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.tools.microsoft import is_msvc from conan.errors import ConanInvalidConfiguration import os @@ -13,14 +14,16 @@ class PlatformFoldersConan(ConanFile): 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" + 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" + package_type = "library" settings = "os", "arch", "compiler", "build_type" options = { + "shared": [True, False], "fPIC": [True, False], } default_options = { + "shared": False, "fPIC": True, } @@ -31,25 +34,29 @@ def _minimum_cpp_standard(self): 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") + if is_msvc(self) and self.options.shared: + # See https://github.com/sago007/PlatformFolders/pull/29 + raise ConanInvalidConfiguration(f"{self.ref} does not support shared libraries with MSVC.") def config_options(self): if self.settings.os == "Windows": del self.options.fPIC + def configure(self): + if self.options.shared: + self.options.rm_safe("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.variables["PLATFORMFOLDERS_BUILD_SHARED_LIBS"] = self.options.shared + tc.variables["PLATFORMFOLDERS_ENABLE_INSTALL"] = True tc.generate() def build(self): @@ -67,4 +74,6 @@ def package(self): def package_info(self): self.cpp_info.libs = ["platform_folders"] - + self.cpp_info.set_property("cmake_file_name", "platform_folders") + self.cpp_info.set_property("cmake_target_name", "sago::platform_folders") + self.cpp_info.set_property("cmake_target_aliases", ["platform_folders"]) diff --git a/recipes/platformfolders/all/test_package/CMakeLists.txt b/recipes/platformfolders/all/test_package/CMakeLists.txt index cb747ceeb1e6d..c75dde66e6a67 100644 --- a/recipes/platformfolders/all/test_package/CMakeLists.txt +++ b/recipes/platformfolders/all/test_package/CMakeLists.txt @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.15) project(test_package LANGUAGES CXX) -find_package(platformfolders REQUIRED CONFIG) +find_package(platform_folders REQUIRED CONFIG) add_executable(${PROJECT_NAME} test_package.cpp) -target_link_libraries(${PROJECT_NAME} PRIVATE platformfolders::platformfolders) +target_link_libraries(${PROJECT_NAME} PRIVATE sago::platform_folders) 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 index 34be4a6e879fa..b8c7713c1ed31 100644 --- a/recipes/platformfolders/all/test_package/conanfile.py +++ b/recipes/platformfolders/all/test_package/conanfile.py @@ -14,7 +14,7 @@ def layout(self): cmake_layout(self) def requirements(self): - self.requires(self.tested_reference_str, run=can_run(self)) + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self)