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
5 changes: 5 additions & 0 deletions recipes/fswatch/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.5)
project(cmake_wrapper)

message(STATUS "Conan CMake Wrapper")
add_subdirectory("src")
AbrilRBS marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions recipes/fswatch/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
sources:
"1.17.1":
url: "https://github.com/emcrisostomo/fswatch/archive/refs/tags/1.17.1.zip"
sha256: "2a2be51807a7138cf50b327a9de29b96892dd357ab3142a5b4e36cb380ee4470"
"1.17.1-36":
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this version, as per semver semantics, would come before 1.17.1, that is, 1.17.1-36 < 1.17.1, which I don't think is the intention here!

We should clarify if upstream is expecting to release a new version soon with this fix, else we'll need to roll our own schema for this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, you're absolutely right. Since the latest commit was two years ago and the repository is more or less in hibernation mode, I don't think there will be a tag or release soon. Is there the possibility to refer to a specific commit without the need to assign it a version?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! We can set this version to 1.17.1.cci.YYYYMMDD for the date of the latest commit, which is our way of indicating that the version comes from a specific commit and is not tagged

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I adapted the 1.17.1-36 version according to the proposed scheme and removed the (faulty) 1.17.1 version.

url: "https://github.com/emcrisostomo/fswatch/archive/refs/tags/1.17.1-36-gba411e0.zip"
sha256: "520220c952208747206197cfdd403114c05f8d5612ccc0be9ded5e9a8261fe63"
87 changes: 87 additions & 0 deletions recipes/fswatch/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import os

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.cmake.toolchain.blocks import is_apple_os
from conan.tools.files import get, copy
from conan.tools.scm import Version

required_conan_version = ">=1.53.0"

class WatcherConan(ConanFile):
name = "fswatch"
description = "A cross-platform file change monitor with multiple backends: Apple OS X File System Events, *BSD kqueue, Solaris/Illumos File Events Notification, Linux inotify, Microsoft Windows and a stat()-based backend.."
license = "GPL-3.0"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/emcrisostomo/fswatch"
topics = ("watch", "filesystem", "event", "header-only")

package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True
}

def export_sources(self):
copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=self.export_sources_folder)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def requirements(self):
if self.settings.os == "Windows":
self.requires("pthreads4w/3.0.0")

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")

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

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)
if self.settings.compiler == "gcc":
if Version(self.settings.compiler.version) < "6":
raise ConanInvalidConfiguration("gcc < 6 is unsupported")

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

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

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

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

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"]

if is_apple_os(self):
self.cpp_info.frameworks.extend(["CoreFoundation", "CoreServices"])
17 changes: 17 additions & 0 deletions recipes/fswatch/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
cmake_minimum_required(VERSION 3.12)
project(test_package LANGUAGES CXX)

find_package(fswatch REQUIRED CONFIG)
find_package(Threads REQUIRED)

if(MACOS)
find_library(COREFOUNDATION_LIBRARY CoreFoundation REQUIRED)
find_library(CORESERVICES_LIBRARY CoreServices REQUIRED)
endif()

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE fswatch::fswatch Threads::Threads)

if(MACOS)
target_link_libraries(${PROJECT_NAME} PRIVATE ${COREFOUNDATION_LIBRARY} ${CORESERVICES_LIBRARY})
endif()
26 changes: 26 additions & 0 deletions recipes/fswatch/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.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", "VirtualRunEnv"
test_type = "explicit"

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

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

int main() {
std::vector<std::string> directory_children = fsw::get_directory_children(".");
for (const auto& it : directory_children) {
std::cout << it << std::endl;
}

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