diff --git a/recipes/cnpy/all/CMakeLists.txt b/recipes/cnpy/all/CMakeLists.txt new file mode 100644 index 0000000000000..faa97ba1ac412 --- /dev/null +++ b/recipes/cnpy/all/CMakeLists.txt @@ -0,0 +1,9 @@ +cmake_minimum_required(VERSION 3.4) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup() + +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) + +add_subdirectory("source_subfolder") diff --git a/recipes/cnpy/all/conandata.yml b/recipes/cnpy/all/conandata.yml new file mode 100644 index 0000000000000..953d832ba545b --- /dev/null +++ b/recipes/cnpy/all/conandata.yml @@ -0,0 +1,8 @@ +sources: + "cci.20180601": + url: "https://github.com/rogersce/cnpy/archive/4e8810b1a8637695171ed346ce68f6984e585ef4.tar.gz" + sha256: "5120abc54a564efa92c642cc0199cc4fd3f345901157de9fbbdcedbb34d28d8a" +patches: + "cci.20180601": + - patch_file: "patches/0001-exclude-example.patch" + base_path: "source_subfolder" diff --git a/recipes/cnpy/all/conanfile.py b/recipes/cnpy/all/conanfile.py new file mode 100644 index 0000000000000..794d778b22da5 --- /dev/null +++ b/recipes/cnpy/all/conanfile.py @@ -0,0 +1,73 @@ +import os +import glob + +from conans import ConanFile, CMake, tools + +class CnpyConan(ConanFile): + name = "cnpy" + description = "library to read/write .npy and .npz files in C/C++" + license = "MIT" + topics = ("conan", "cnpy") + homepage = "https://github.com/hongyx11/cnpy" + url = "https://github.com/conan-io/conan-center-index" + exports_sources = ["CMakeLists.txt", "patches/*"] + generators = "cmake", "cmake_find_package" + settings = "os", "arch", "compiler", "build_type" + _cmake = None + + options = { + "shared": [True, False], + "fPIC": [True, False] + } + default_options = { + "shared": False, + "fPIC": True + } + + @property + def _source_subfolder(self): + return "source_subfolder" + + @property + def _build_subfolder(self): + return "build_subfolder" + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + del self.options.fPIC + + def requirements(self): + self.requires("zlib/1.2.11") + + def source(self): + tools.get(**self.conan_data["sources"][self.version]) + extracted_dir = glob.glob(self.name + "-*")[0] + os.rename(extracted_dir, self._source_subfolder) + + def build(self): + for patch in self.conan_data.get("patches", {}).get(self.version, []): + tools.patch(**patch) + cmake = self._configure_cmake() + cmake.build() + + def _configure_cmake(self): + if self._cmake: + return self._cmake + self._cmake = CMake(self) + self._cmake.definitions["ENABLE_STATIC"] = not self.options.shared + self._cmake.configure(build_folder=self._build_subfolder) + return self._cmake + + def package(self): + self.copy("LICENSE", dst="licenses", src=self._source_subfolder) + cmake = self._configure_cmake() + cmake.install() + + def package_info(self): + self.cpp_info.names["cmake_find_package"] = "cnpy" + self.cpp_info.names["cmake_find_package_multi"] = "cnpy" + self.cpp_info.libs = ["cnpy"] diff --git a/recipes/cnpy/all/patches/0001-exclude-example.patch b/recipes/cnpy/all/patches/0001-exclude-example.patch new file mode 100644 index 0000000000000..f39f242261c6a --- /dev/null +++ b/recipes/cnpy/all/patches/0001-exclude-example.patch @@ -0,0 +1,37 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 9eb550f..d57c6dd 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -5,26 +5,17 @@ endif(COMMAND cmake_policy) + + project(CNPY) + +-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +- +-option(ENABLE_STATIC "Build static (.a) library" ON) +- + find_package(ZLIB REQUIRED) + + include_directories(${ZLIB_INCLUDE_DIRS}) + +-add_library(cnpy SHARED "cnpy.cpp") ++add_library(cnpy "cnpy.cpp") + target_link_libraries(cnpy ${ZLIB_LIBRARIES}) +-install(TARGETS "cnpy" LIBRARY DESTINATION lib PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) +- +-if(ENABLE_STATIC) +- add_library(cnpy-static STATIC "cnpy.cpp") +- set_target_properties(cnpy-static PROPERTIES OUTPUT_NAME "cnpy") +- install(TARGETS "cnpy-static" ARCHIVE DESTINATION lib) +-endif(ENABLE_STATIC) ++set_property(TARGET cnpy PROPERTY CXX_STANDARD 11) ++install(TARGETS "cnpy" ++ LIBRARY DESTINATION lib PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE ++ ARCHIVE DESTINATION lib ++ RUNTIME DESTINATION bin) + + install(FILES "cnpy.h" DESTINATION include) +-install(FILES "mat2npz" "npy2mat" "npz2mat" DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) + +-add_executable(example1 example1.cpp) +-target_link_libraries(example1 cnpy) diff --git a/recipes/cnpy/all/test_package/CMakeLists.txt b/recipes/cnpy/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..9145952903057 --- /dev/null +++ b/recipes/cnpy/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1.0) +project(test_package CXX) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() +add_executable(${PROJECT_NAME} example1.cpp) +target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11) diff --git a/recipes/cnpy/all/test_package/conanfile.py b/recipes/cnpy/all/test_package/conanfile.py new file mode 100644 index 0000000000000..ea57a464900be --- /dev/null +++ b/recipes/cnpy/all/test_package/conanfile.py @@ -0,0 +1,17 @@ +import os + +from conans import ConanFile, CMake, tools + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self.settings): + bin_path = os.path.join("bin", "test_package") + self.run(bin_path, run_environment=True) diff --git a/recipes/cnpy/all/test_package/example1.cpp b/recipes/cnpy/all/test_package/example1.cpp new file mode 100644 index 0000000000000..99a4af4d04a9a --- /dev/null +++ b/recipes/cnpy/all/test_package/example1.cpp @@ -0,0 +1,15 @@ +#include +#include +#include"cnpy.h" + +int main() { + const size_t Nx = 16; + const size_t Ny = 16; + const size_t Nz = 16; + + std::vector data(Nx*Ny*Nz); + for(int i = 0;i < Nx*Ny*Nz;i++) data[i] = rand(); + cnpy::npy_save("arr1.npy",&data[0],{Nz,Ny,Nx},"w"); + cnpy::NpyArray arr = cnpy::npy_load("arr1.npy"); + return 0; +} diff --git a/recipes/cnpy/config.yml b/recipes/cnpy/config.yml new file mode 100644 index 0000000000000..6a02f84aa19d5 --- /dev/null +++ b/recipes/cnpy/config.yml @@ -0,0 +1,3 @@ +versions: + "cci.20180601": + folder: all