From 81168ea8adb8853ef7dddcfaf42d28c65a5cde0b Mon Sep 17 00:00:00 2001 From: SpaceIm <30052553+SpaceIm@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:50:58 +0200 Subject: [PATCH] (#25273) add new recipe ann/1.1.2 * add ann/1.1.2 * add libm to system libs --- recipes/ann/all/CMakeLists.txt | 29 ++++ recipes/ann/all/conandata.yml | 12 ++ recipes/ann/all/conanfile.py | 71 +++++++++ .../1.1.2-0001-fix-windows-static.patch | 11 ++ ...-0002-fix-cppstd17+-register-keyword.patch | 141 ++++++++++++++++++ recipes/ann/all/test_package/CMakeLists.txt | 7 + recipes/ann/all/test_package/conanfile.py | 26 ++++ recipes/ann/all/test_package/test_package.cpp | 6 + recipes/ann/config.yml | 3 + 9 files changed, 306 insertions(+) create mode 100644 recipes/ann/all/CMakeLists.txt create mode 100644 recipes/ann/all/conandata.yml create mode 100644 recipes/ann/all/conanfile.py create mode 100644 recipes/ann/all/patches/1.1.2-0001-fix-windows-static.patch create mode 100644 recipes/ann/all/patches/1.1.2-0002-fix-cppstd17+-register-keyword.patch create mode 100644 recipes/ann/all/test_package/CMakeLists.txt create mode 100644 recipes/ann/all/test_package/conanfile.py create mode 100644 recipes/ann/all/test_package/test_package.cpp create mode 100644 recipes/ann/config.yml diff --git a/recipes/ann/all/CMakeLists.txt b/recipes/ann/all/CMakeLists.txt new file mode 100644 index 0000000000000..869e7fed035ec --- /dev/null +++ b/recipes/ann/all/CMakeLists.txt @@ -0,0 +1,29 @@ +cmake_minimum_required(VERSION 3.15) +project(ANN LANGUAGES CXX) + +include(GNUInstallDirs) + +file(GLOB ANN_SRC_FILES ${ANN_SRC_DIR}/src/*.cpp) + +add_library(ANN ${ANN_SRC_FILES}) +target_include_directories(ANN PUBLIC ${ANN_SRC_DIR}/include) + +if(WIN32) + if(BUILD_SHARED_LIBS) + set_target_properties(ANN PROPERTIES + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN TRUE + ) + target_compile_definitions(ANN PRIVATE DLL_EXPORTS) + else() + target_compile_definitions(ANN PUBLIC ANN_STATIC) + endif() +endif() + +install(DIRECTORY ${ANN_SRC_DIR}/include/ANN DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install( + TARGETS ANN + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) diff --git a/recipes/ann/all/conandata.yml b/recipes/ann/all/conandata.yml new file mode 100644 index 0000000000000..664adc9ca8f3c --- /dev/null +++ b/recipes/ann/all/conandata.yml @@ -0,0 +1,12 @@ +sources: + "1.1.2": + url: "https://www.cs.umd.edu/~mount/ANN/Files/1.1.2/ann_1.1.2.tar.gz" + sha256: "eea03f2e224b66813226d775053316675375dcec45bd263674c052d9324a49a5" +patches: + "1.1.2": + - patch_file: "patches/1.1.2-0001-fix-windows-static.patch" + patch_description: "Fix windows static" + patch_type: "portability" + - patch_file: "patches/1.1.2-0002-fix-cppstd17+-register-keyword.patch" + patch_description: "Fix compilation with C++17 (or above) standard, by removing register keyword" + patch_type: "portability" diff --git a/recipes/ann/all/conanfile.py b/recipes/ann/all/conanfile.py new file mode 100644 index 0000000000000..01aac4245f259 --- /dev/null +++ b/recipes/ann/all/conanfile.py @@ -0,0 +1,71 @@ +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get +import os + +required_conan_version = ">=1.53.0" + + +class AnnConan(ConanFile): + name = "ann" + description = ( + "ANN is a library written in C++, which supports data structures and " + "algorithms for both exact and approximate nearest neighbor searching " + "in arbitrarily high dimensions." + ) + license = "LGPL-2.1-or-later" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://www.cs.umd.edu/~mount/ANN" + topics = ("nns", "nearest-neighbor-search") + 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) + export_conandata_patches(self) + + 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 source(self): + get(self, **self.conan_data["sources"][self.version], strip_root=True) + + def generate(self): + tc = CMakeToolchain(self) + tc.variables["ANN_SRC_DIR"] = self.source_folder.replace("\\", "/") + tc.generate() + + def build(self): + apply_conandata_patches(self) + cmake = CMake(self) + cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir)) + cmake.build() + + def package(self): + for license_file in ("Copyright.txt", "License.txt"): + copy(self, license_file, src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) + cmake = CMake(self) + cmake.install() + + def package_info(self): + self.cpp_info.libs = ["ANN"] + if self.settings.os == "Windows" and not self.options.shared: + self.cpp_info.defines.append("ANN_STATIC") + if self.settings.os in ["Linux", "FreeBSD"]: + self.cpp_info.system_libs.append("m") diff --git a/recipes/ann/all/patches/1.1.2-0001-fix-windows-static.patch b/recipes/ann/all/patches/1.1.2-0001-fix-windows-static.patch new file mode 100644 index 0000000000000..7e027ada50bbb --- /dev/null +++ b/recipes/ann/all/patches/1.1.2-0001-fix-windows-static.patch @@ -0,0 +1,11 @@ +--- a/include/ANN/ANN.h ++++ b/include/ANN/ANN.h +@@ -59,7 +59,7 @@ + #ifndef ANN_H + #define ANN_H + +-#ifdef WIN32 ++#if defined(_WIN32) && !defined(ANN_STATIC) + //---------------------------------------------------------------------- + // For Microsoft Visual C++, externally accessible symbols must be + // explicitly indicated with DLL_API, which is somewhat like "extern." diff --git a/recipes/ann/all/patches/1.1.2-0002-fix-cppstd17+-register-keyword.patch b/recipes/ann/all/patches/1.1.2-0002-fix-cppstd17+-register-keyword.patch new file mode 100644 index 0000000000000..b7ccbe07fc3a4 --- /dev/null +++ b/recipes/ann/all/patches/1.1.2-0002-fix-cppstd17+-register-keyword.patch @@ -0,0 +1,141 @@ +--- a/src/ANN.cpp ++++ b/src/ANN.cpp +@@ -48,9 +48,9 @@ ANNdist annDist( // interpoint squared distance + ANNpoint p, + ANNpoint q) + { +- register int d; +- register ANNcoord diff; +- register ANNcoord dist; ++ int d; ++ ANNcoord diff; ++ ANNcoord dist; + + dist = 0; + for (d = 0; d < dim; d++) { +--- a/src/kd_fix_rad_search.cpp ++++ b/src/kd_fix_rad_search.cpp +@@ -147,11 +147,11 @@ void ANNkd_split::ann_FR_search(ANNdist box_dist) + + void ANNkd_leaf::ann_FR_search(ANNdist box_dist) + { +- register ANNdist dist; // distance to data point +- register ANNcoord* pp; // data coordinate pointer +- register ANNcoord* qq; // query coordinate pointer +- register ANNcoord t; +- register int d; ++ ANNdist dist; // distance to data point ++ ANNcoord* pp; // data coordinate pointer ++ ANNcoord* qq; // query coordinate pointer ++ ANNcoord t; ++ int d; + + for (int i = 0; i < n_pts; i++) { // check points in bucket + +--- a/src/kd_pr_search.cpp ++++ b/src/kd_pr_search.cpp +@@ -180,12 +180,12 @@ void ANNkd_split::ann_pri_search(ANNdist box_dist) + + void ANNkd_leaf::ann_pri_search(ANNdist box_dist) + { +- register ANNdist dist; // distance to data point +- register ANNcoord* pp; // data coordinate pointer +- register ANNcoord* qq; // query coordinate pointer +- register ANNdist min_dist; // distance to k-th closest point +- register ANNcoord t; +- register int d; ++ ANNdist dist; // distance to data point ++ ANNcoord* pp; // data coordinate pointer ++ ANNcoord* qq; // query coordinate pointer ++ ANNdist min_dist; // distance to k-th closest point ++ ANNcoord t; ++ int d; + + min_dist = ANNprPointMK->max_key(); // k-th smallest distance so far + +--- a/src/kd_search.cpp ++++ b/src/kd_search.cpp +@@ -171,12 +171,12 @@ void ANNkd_split::ann_search(ANNdist box_dist) + + void ANNkd_leaf::ann_search(ANNdist box_dist) + { +- register ANNdist dist; // distance to data point +- register ANNcoord* pp; // data coordinate pointer +- register ANNcoord* qq; // query coordinate pointer +- register ANNdist min_dist; // distance to k-th closest point +- register ANNcoord t; +- register int d; ++ ANNdist dist; // distance to data point ++ ANNcoord* pp; // data coordinate pointer ++ ANNcoord* qq; // query coordinate pointer ++ ANNdist min_dist; // distance to k-th closest point ++ ANNcoord t; ++ int d; + + min_dist = ANNkdPointMK->max_key(); // k-th smallest distance so far + +--- a/src/kd_util.cpp ++++ b/src/kd_util.cpp +@@ -127,10 +127,10 @@ ANNdist annBoxDistance( // compute distance from point to box + const ANNpoint hi, // high point of box + int dim) // dimension of space + { +- register ANNdist dist = 0.0; // sum of squared distances +- register ANNdist t; ++ ANNdist dist = 0.0; // sum of squared distances ++ ANNdist t; + +- for (register int d = 0; d < dim; d++) { ++ for (int d = 0; d < dim; d++) { + if (q[d] < lo[d]) { // q is left of box + t = ANNdist(lo[d]) - ANNdist(q[d]); + dist = ANN_SUM(dist, ANN_POW(t)); +@@ -238,8 +238,8 @@ void annMedianSplit( + int l = 0; // left end of current subarray + int r = n-1; // right end of current subarray + while (l < r) { +- register int i = (r+l)/2; // select middle as pivot +- register int k; ++ int i = (r+l)/2; // select middle as pivot ++ int k; + + if (PA(i,d) > PA(r,d)) // make sure last > pivot + PASWAP(i,r) +--- a/src/pr_queue.h ++++ b/src/pr_queue.h +@@ -86,9 +86,9 @@ public: + PQinfo inf) // item info + { + if (++n > max_size) annError("Priority queue overflow.", ANNabort); +- register int r = n; ++ int r = n; + while (r > 1) { // sift up new item +- register int p = r/2; ++ int p = r/2; + ANN_FLOP(1) // increment floating ops + if (pq[p].key <= kv) // in proper order + break; +@@ -105,9 +105,9 @@ public: + { + kv = pq[1].key; // key of min item + inf = pq[1].info; // information of min item +- register PQkey kn = pq[n--].key;// last item in queue +- register int p = 1; // p points to item out of position +- register int r = p<<1; // left child of p ++ PQkey kn = pq[n--].key;// last item in queue ++ int p = 1; // p points to item out of position ++ int r = p<<1; // left child of p + while (r <= n) { // while r is still within the heap + ANN_FLOP(2) // increment floating ops + // set r to smaller child of p +--- a/src/pr_queue_k.h ++++ b/src/pr_queue_k.h +@@ -100,7 +100,7 @@ public: + PQKkey kv, // key value + PQKinfo inf) // item info + { +- register int i; ++ int i; + // slide larger values up + for (i = n; i > 0; i--) { + if (mk[i-1].key > kv) diff --git a/recipes/ann/all/test_package/CMakeLists.txt b/recipes/ann/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..fe5808fbfdff7 --- /dev/null +++ b/recipes/ann/all/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(ann REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} test_package.cpp) +target_link_libraries(${PROJECT_NAME} PRIVATE ann::ann) diff --git a/recipes/ann/all/test_package/conanfile.py b/recipes/ann/all/test_package/conanfile.py new file mode 100644 index 0000000000000..0a6bc68712d90 --- /dev/null +++ b/recipes/ann/all/test_package/conanfile.py @@ -0,0 +1,26 @@ +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): + bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package") + self.run(bin_path, env="conanrun") diff --git a/recipes/ann/all/test_package/test_package.cpp b/recipes/ann/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..8a2ab526c32b2 --- /dev/null +++ b/recipes/ann/all/test_package/test_package.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + ANNpoint queryPt = annAllocPt(2); + return 0; +} diff --git a/recipes/ann/config.yml b/recipes/ann/config.yml new file mode 100644 index 0000000000000..8d13aefb6b4fb --- /dev/null +++ b/recipes/ann/config.yml @@ -0,0 +1,3 @@ +versions: + "1.1.2": + folder: all