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

fswatch: add package #25895

Merged
merged 14 commits into from
Nov 18, 2024
4 changes: 4 additions & 0 deletions recipes/fswatch/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.17.1.cci.20220902":
url: "https://github.com/emcrisostomo/fswatch/archive/ba411e0d0fabcd5cbf0881f1380482e2f5ab9f47.zip"
sha256: "278476f0f2178bf59dac494c07d6a9b9d181eac8d14f37d17eaf8c6d04a3b4d9"
94 changes: 94 additions & 0 deletions recipes/fswatch/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import os
from conan import ConanFile
from conan.tools.build import check_min_cppstd, cross_building
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import get, copy, replace_in_file, rmdir
from conan.tools.microsoft import is_msvc
from conan.tools.apple import is_apple_os
from conan.errors import ConanInvalidConfiguration


required_conan_version = ">=2.0.9"


class WatcherConan(ConanFile):
name = "fswatch"
description = "A cross-platform file change monitor with multiple backends"
license = "GPL-3.0-or-later"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/emcrisostomo/fswatch"
topics = ("watch", "filesystem", "event", "monitor")
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True
}
implements = ["auto_shared_fpic"]

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

def validate_build(self):
if is_apple_os(self) and cross_building(self):
# INFO: Cmake error: "VERSION_GREATER_EQUAL" "9.0" Unknown arguments specified
raise ConanInvalidConfiguration(f"{self.ref} does not support cross-building on {self.settings.os}")

def validate(self):
check_min_cppstd(self, 11)
if is_msvc(self):
# INFO: fswatch requires pthread always and fails CMake when using MSVC
raise ConanInvalidConfiguration(f"{self.ref} does not support MSVC due pthread requirement.")

def requirements(self):
self.requires("libgettext/0.22")

def build_requirements(self):
self.tool_requires("gettext/0.22.5")

def _apply_patches(self):
# Remove hardcoded CXX standard
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"set(CMAKE_CXX_STANDARD 11)",
"")

# Dont compile tests
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"add_subdirectory(test/src)",
"")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
self._apply_patches()

def generate(self):
tc = CMakeToolchain(self)
tc.generate()
tc = CMakeDeps(self)
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "LICENSE*", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(self, "COPYING*", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.libs = ["fswatch"]
self.cpp_info.set_property("cmake_file_name", "fswatch")
self.cpp_info.set_property("cmake_target_name", "fswatch::fswatch")

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m", "pthread"]
elif self.settings.os == "Macos":
self.cpp_info.frameworks = ["CoreFoundation", "CoreServices"]
7 changes: 7 additions & 0 deletions recipes/fswatch/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(fswatch REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE fswatch::fswatch)
25 changes: 25 additions & 0 deletions recipes/fswatch/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from conan import ConanFile
from conan.tools.cmake import cmake_layout, CMake
from conan.tools.build import can_run

import os

class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
9 changes: 9 additions & 0 deletions recipes/fswatch/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include <cstdlib>

#include <libfswatch/c++/path_utils.hpp>

int main() {
const auto directory_children = fsw::get_directory_children(".");

return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/fswatch/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.17.1.cci.20220902":
folder: all