Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[platformfolders] Support shared library #2

Merged
merged 1 commit into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions recipes/platformfolders/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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,
}

Expand All @@ -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):
Expand All @@ -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"])
4 changes: 2 additions & 2 deletions recipes/platformfolders/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion recipes/platformfolders/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down