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

[cnpy-1.0] upload lib #4032

Merged
merged 26 commits into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c062578
create cnpy package
hongyx11 Dec 29, 2020
222547b
change python indention
hongyx11 Dec 29, 2020
5c5289e
Update recipes/cnpy/all/test_package/CMakeLists.txt
hongyx11 Dec 30, 2020
e50dbd9
Update recipes/cnpy/all/test_package/conanfile.py
hongyx11 Dec 30, 2020
00a87d7
Update recipes/cnpy/all/conanfile.py
hongyx11 Dec 30, 2020
4468aa5
Update recipes/cnpy/all/conanfile.py
hongyx11 Dec 30, 2020
a1637d4
Update recipes/cnpy/all/conanfile.py
hongyx11 Dec 30, 2020
f9b830d
Update recipes/cnpy/all/conanfile.py
hongyx11 Dec 30, 2020
61c962f
Update recipes/cnpy/all/conanfile.py
hongyx11 Dec 30, 2020
0609113
Fix package version
uilianries Dec 30, 2020
0cf1083
Fix Windows build
uilianries Dec 30, 2020
41cbe90
Export all symbols
uilianries Dec 30, 2020
0452853
cnpy: Update Conan conventions
bincrafters-user Dec 30, 2020
af8ed66
Merge pull request #1 from bincrafters/package/cnpy
hongyx11 Dec 31, 2020
10b925d
fix windows problem
hongyx11 Dec 31, 2020
bc4066f
Update recipes/cnpy/all/conanfile.py
hongyx11 Dec 31, 2020
12102c0
update example test
hongyx11 Dec 31, 2020
ff276c0
Merge branch 'master' of github.com:hongyx11/conan-center-index
hongyx11 Dec 31, 2020
c4bfc6d
add new line
hongyx11 Dec 31, 2020
6195031
update remove exampletest
hongyx11 Dec 31, 2020
ff5f731
update remove exampletest
hongyx11 Dec 31, 2020
213b1f4
Update recipes/cnpy/all/test_package/conanfile.py
hongyx11 Dec 31, 2020
33a0c0e
Update recipes/cnpy/all/test_package/example1.cpp
hongyx11 Dec 31, 2020
4504142
windows
hongyx11 Dec 31, 2020
7159ae8
update
hongyx11 Dec 31, 2020
d5d8896
Update recipes/cnpy/all/conanfile.py
hongyx11 Jan 1, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions recipes/cnpy/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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")
8 changes: 8 additions & 0 deletions recipes/cnpy/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
75 changes: 75 additions & 0 deletions recipes/cnpy/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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"
hongyx11 marked this conversation as resolved.
Show resolved Hide resolved
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
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
hongyx11 marked this conversation as resolved.
Show resolved Hide resolved

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"]
37 changes: 37 additions & 0 deletions recipes/cnpy/all/patches/0001-exclude-example.patch
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions recipes/cnpy/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
16 changes: 16 additions & 0 deletions recipes/cnpy/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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)
55 changes: 55 additions & 0 deletions recipes/cnpy/all/test_package/example1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include"cnpy.h"
#include<complex>
#include<cstdlib>
#include<iostream>
#include<map>
#include<string>

const int Nx = 128;
const int Ny = 64;
const int Nz = 32;

int main()
{
//set random seed so that result is reproducible (for testing)
srand(0);
//create random data
std::vector<std::complex<double>> data(Nx*Ny*Nz);
for(int i = 0;i < Nx*Ny*Nz;i++) data[i] = std::complex<double>(rand(),rand());

//save it to file
cnpy::npy_save("arr1.npy",&data[0],{Nz,Ny,Nx},"w");

//load it into a new array
cnpy::NpyArray arr = cnpy::npy_load("arr1.npy");
std::complex<double>* loaded_data = arr.data<std::complex<double>>();

//make sure the loaded data matches the saved data
assert(arr.word_size == sizeof(std::complex<double>));
assert(arr.shape.size() == 3 && arr.shape[0] == Nz && arr.shape[1] == Ny && arr.shape[2] == Nx);
for(int i = 0; i < Nx*Ny*Nz;i++) assert(data[i] == loaded_data[i]);

//append the same data to file
//npy array on file now has shape (Nz+Nz,Ny,Nx)
cnpy::npy_save("arr1.npy",&data[0],{Nz,Ny,Nx},"a");

//now write to an npz file
//non-array variables are treated as 1D arrays with 1 element
double myVar1 = 1.2;
char myVar2 = 'a';
cnpy::npz_save("out.npz","myVar1",&myVar1,{1},"w"); //"w" overwrites any existing file
cnpy::npz_save("out.npz","myVar2",&myVar2,{1},"a"); //"a" appends to the file we created above
cnpy::npz_save("out.npz","arr1",&data[0],{Nz,Ny,Nx},"a"); //"a" appends to the file we created above

//load a single var from the npz file
cnpy::NpyArray arr2 = cnpy::npz_load("out.npz","arr1");

//load the entire npz file
cnpy::npz_t my_npz = cnpy::npz_load("out.npz");

//check that the loaded myVar1 matches myVar1
cnpy::NpyArray arr_mv1 = my_npz["myVar1"];
double* mv1 = arr_mv1.data<double>();
assert(arr_mv1.shape.size() == 1 && arr_mv1.shape[0] == 1);
assert(mv1[0] == myVar1);
}
3 changes: 3 additions & 0 deletions recipes/cnpy/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"cci.20180601":
folder: all