Skip to content

cnpy: conan v2 support #14287

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

Merged
merged 1 commit into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 9 deletions recipes/cnpy/all/CMakeLists.txt

This file was deleted.

3 changes: 1 addition & 2 deletions recipes/cnpy/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ sources:
sha256: "5120abc54a564efa92c642cc0199cc4fd3f345901157de9fbbdcedbb34d28d8a"
patches:
"cci.20180601":
- patch_file: "patches/0001-exclude-example.patch"
base_path: "source_subfolder"
- patch_file: "patches/0001-fix-cmake.patch"
72 changes: 35 additions & 37 deletions recipes/cnpy/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,73 +1,71 @@
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get
import os
import glob

from conans import ConanFile, CMake, tools
required_conan_version = ">=1.53.0"


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"
topics = ("numpy", "npy", "npz")
homepage = "https://github.com/rogersce/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

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

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"
def export_sources(self):
export_conandata_patches(self)

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

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

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

def requirements(self):
self.requires("zlib/1.2.11")
self.requires("zlib/1.2.13", transitive_headers=True, transitive_libs=True)

def validate(self):
if self.info.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 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)
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

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

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
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()
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
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"]
Original file line number Diff line number Diff line change
@@ -1,34 +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)
@@ -1,30 +1,18 @@
-CMAKE_MINIMUM_REQUIRED(VERSION 3.0 FATAL_ERROR)
-if(COMMAND cmake_policy)
- cmake_policy(SET CMP0003 NEW)
-endif(COMMAND cmake_policy)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.8)

project(CNPY)
-project(CNPY)
+project(CNPY LANGUAGES CXX)

-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})
-include_directories(${ZLIB_INCLUDE_DIRS})

-add_library(cnpy SHARED "cnpy.cpp")
+add_library(cnpy "cnpy.cpp")
target_link_libraries(cnpy ${ZLIB_LIBRARIES})
-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)
-
+add_library(cnpy "cnpy.cpp")
+target_compile_features(cnpy PUBLIC cxx_std_11)
+set_target_properties(cnpy PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
+target_link_libraries(cnpy PUBLIC ZLIB::ZLIB)
+install(TARGETS "cnpy" LIBRARY DESTINATION lib ARCHIVE DESTINATION lib RUNTIME DESTINATION bin)

-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)
Expand Down
14 changes: 7 additions & 7 deletions recipes/cnpy/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.1.0)
project(test_package CXX)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES 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)
find_package(cnpy REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE cnpy::cnpy)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
21 changes: 15 additions & 6 deletions recipes/cnpy/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os

from conans import ConanFile, CMake, tools

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
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 not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/cnpy/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
17 changes: 17 additions & 0 deletions recipes/cnpy/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

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

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)