Skip to content

Commit

Permalink
Support shared library
Browse files Browse the repository at this point in the history
Signed-off-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
uilianries authored and xyz1001 committed May 10, 2024
1 parent f247f40 commit d2a17b8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
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

0 comments on commit d2a17b8

Please sign in to comment.