Skip to content

Commit

Permalink
(#23270) platformfolders: add new recipe for platformfolders
Browse files Browse the repository at this point in the history
* platformfolders: add new recipe for platformfolders

* Support shared library

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/platformfolders/all/conanfile.py

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/platformfolders/all/conanfile.py

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/platformfolders/all/conanfile.py

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* PlatfromFolders: fix windows compile error when -o share=True

* Add missing m system lib

---------

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es>
  • Loading branch information
3 people authored May 20, 2024
1 parent 0a5b330 commit 07ce6e8
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/platformfolders/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"4.2.0":
url: "https://github.com/sago007/PlatformFolders/archive/refs/tags/4.2.0.tar.gz"
sha256: "31bb0f64a27315aec8994f226332aaafe9888d00bb69a2ff2dff9912e2f4ccf4"
82 changes: 82 additions & 0 deletions recipes/platformfolders/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
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.tools.microsoft import is_msvc
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 = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"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)

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")
if is_msvc(self):
self.package_type = "static-library"
del self.options.shared

def layout(self):
cmake_layout(self, src_folder="src")

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.get_safe("shared", default=False)
tc.variables["PLATFORMFOLDERS_ENABLE_INSTALL"] = True
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"]
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"])

if self.settings.os in ("Linux", "FreeBSD"):
self.cpp_info.system_libs.append("m")
8 changes: 8 additions & 0 deletions recipes/platformfolders/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(platform_folders REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE sago::platform_folders)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
26 changes: 26 additions & 0 deletions recipes/platformfolders/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)

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")
20 changes: 20 additions & 0 deletions recipes/platformfolders/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#include <string>

#include <sago/platform_folders.h>

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;
}
3 changes: 3 additions & 0 deletions recipes/platformfolders/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"4.2.0":
folder: "all"

0 comments on commit 07ce6e8

Please sign in to comment.