Commit 3886b827 authored by Baptiste Esteban's avatar Baptiste Esteban
Browse files

WIP packaging and build system + fix Pylene-numpy shared library usage

parent bda3faff
Pipeline #26593 failed with stages
in 4 minutes and 25 seconds
......@@ -97,15 +97,13 @@ endif ()
# Subdirectories
add_subdirectory(pylene)
if (PYLENE_BUILD_PYTHON AND CMAKE_POSITION_INDEPENDENT_CODE)
if (PYLENE_BUILD_PYTHON)
# Until the cmake_find_package conan generator will be broken for pybind11 with conan 1.33,
# we will use these two lines
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CONAN_BUILD_MODULE_PATH_PYBIND11}")
include(pybind11Install)
add_custom_target(build_python)
add_subdirectory(pylene-python)
elseif (PYLENE_BUILD_PYTHON)
message(WARNING "Position Independent Code disabled. Skip Python bindings...")
endif()
if (NOT PYLENE_BUILD_LIBS_ONLY)
......
......@@ -11,14 +11,11 @@ class Pylene(ConanFile):
options = {
"shared": [True, False],
"fPIC": [True, False],
"pylena_numpy": [True, False]
}
default_options = {
"shared": False,
"fPIC": False,
"pylena_numpy": False,
"gtest:shared": False,
"boost:shared": True
}
generators = [ "cmake", "cmake_paths", "cmake_find_package" ]
......@@ -45,16 +42,16 @@ class Pylene(ConanFile):
tools.check_min_cppstd(self, "20")
if self.options.shared:
del self.options.fPIC
if self.options.pylena_numpy and self.options.fPIC:
if self.options.shared or self.options.fPIC or tools.os_info.is_windows:
self.requires.add("pybind11/2.6.2")
elif self.options.pylena_numpy:
self.output.warn("fPIC option set to False. Skipping pylena_numpy component. To build pylena_numpy component, please set fPIC option to True.")
def build(self):
cmake = CMake(self)
cmake.definitions["PYLENE_BUILD_LIBS_ONLY"] = "YES"
if self.options.fPIC and self.options.pylena_numpy:
if self.options.shared or self.options.fPIC or tools.os_info.is_windows:
cmake.definitions["PYLENE_BUILD_PYTHON"] = "YES"
else:
self.output.warn("fPIC disabled. Skipping python bindings build...")
cmake.configure()
cmake.build()
cmake.install()
......@@ -74,9 +71,9 @@ class Pylene(ConanFile):
self.cpp_info.components["Pylene"].includedirs = [os.path.join(self.package_folder, "include")]
self.cpp_info.components["Pylene"].requires = ["range-v3::range-v3", "fmt::fmt", "tbb::tbb", "xsimd::xsimd"]
if self.options.fPIC and self.options.pylena_numpy:
if self.options.shared or self.options.fPIC or tools.os_info.is_windows:
self.cpp_info.components["Pylene-numpy"].names["cmake_find_pakage"] = "Pylene-numpy"
self.cpp_info.components["Pylene-numpy"].names["cmake_find_pakage_multi"] = "Pylena-numpy"
self.cpp_info.components["Pylene-numpy"].names["cmake_find_pakage_multi"] = "Pylene-numpy"
self.cpp_info.components["Pylene-numpy"].libs = ["Pylene-numpy"]
self.cpp_info.components["Pylene-numpy"].requires = ["Pylene", "pybind11::pybind11"]
self.cpp_info.components["Pylene-numpy"].includedirs = [os.path.join(self.package_folder, "include")]
......
pybind11_find_import(numpy REQUIRED)
add_library(Pylena_numpy)
add_library(Pylene::Pylena_numpy ALIAS Pylena_numpy)
target_include_directories(Pylena_numpy PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
add_library(Pylene-numpy)
add_library(Pylene::Pylene-numpy ALIAS Pylene-numpy)
target_include_directories(Pylene-numpy PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
# PRIVATE TO REMOVE WHEN cmake_find_package FOR PYBIND11 WILL BE FIXED
PRIVATE
# PYBIND11 INCLUDES TO REMOVE WHEN cmake_find_package FOR PYBIND11 WILL BE FIXED
PUBLIC
${CONAN_INCLUDE_DIRS_PYBIND11}
${PYTHON_INCLUDE_DIRS})
target_sources(Pylena_numpy PRIVATE src/core/image_cast.cpp
target_sources(Pylene-numpy PRIVATE src/core/image_cast.cpp
src/core/numpy_format.cpp)
target_link_libraries(Pylena_numpy PUBLIC Pylene)
# REPLACE PYTHON_LIBRARIES BY pybind11::pybind11 WHEN cmake_find_package FOR PYBIND11 WILL BE FIXED
target_link_libraries(Pylene-numpy PUBLIC Pylene ${PYTHON_LIBRARIES})
pybind11_add_module(pylena)
target_link_libraries(pylena PRIVATE Pylene Pylena_numpy)
target_link_libraries(pylena PRIVATE Pylene Pylene-numpy ${PYTHON_LIBRARIES})
target_include_directories(pylena PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_sources(pylena PRIVATE src/module.cpp)
include(GNUInstallDirs)
install(TARGETS Pylena_numpy
install(TARGETS Pylene-numpy
EXPORT PyleneTargets)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/pln/core/image_cast.hpp
......
......@@ -10,18 +10,18 @@ namespace pln
/// \brief Convert a NumPy array to a ndbuffer_image
/// \param[in] arr A NumPy array
/// \return A ndbuffer_image
mln::ndbuffer_image from_numpy(pybind11::array arr);
PYBIND11_EXPORT mln::ndbuffer_image from_numpy(pybind11::array arr);
/// \brief Convert a ndbuffer_image array to a NumPy
/// \param[in] arr A ndbuffer_image
/// \return A NumPy array
pybind11::object to_numpy(mln::ndbuffer_image img);
PYBIND11_EXPORT pybind11::object to_numpy(mln::ndbuffer_image img);
/// \brief Export the binding of the class
/// ndbuffer_image_data
/// \param[in] m The module in which the class will be exported
void init_pylena_numpy(pybind11::module& m);
PYBIND11_EXPORT void init_pylena_numpy(pybind11::module& m);
} // namespace pln
namespace pybind11::detail
......
project(PyleneTest)
cmake_minimum_required(VERSION 3.11)
if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conan_paths.cmake")
include("${CMAKE_CURRENT_BINARY_DIR}/conan_paths.cmake")
endif()
# Conan's 'cmake' generator is used only for pybind11. Will be remove
# when the cmake_find_package generator will work for pybind11
if (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake")
include("${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake")
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CONAN_BUILD_DIRS_PYBIND11}")
include(pybind11Install)
conan_set_rpath()
endif()
find_package(Pylene COMPONENTS Pylene REQUIRED)
find_package(Pylene REQUIRED COMPONENTS Pylene)
add_executable(main main.cpp)
target_link_libraries(main Pylene::Pylene)
if (WITH_PYLENA_NUMPY)
find_package(Pylene COMPONENTS pylena_numpy REQUIRED)
pybind11_add_module(pylene_extension pylene_extension.cpp)
target_link_libraries(pylene_extension PRIVATE Pylene::Pylene Pylene::pylena_numpy)
target_include_directories(pylene_extension PRIVATE ${CONAN_INCLUDE_DIRS_PYBIND11})
if (WITH_PYLENE_NUMPY)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CONAN_BUILD_DIRS_PYBIND11}") # TO REMOVE WHEN cmake_find_package FOR PYBIND11 WORKS
include(pybind11Install) # TO REMOVE WHEN cmake_find_package FOR PYBIND11 WORKS
find_package(Pylene REQUIRED COMPONENTS Pylene-numpy)
pybind11_add_module(pylene_extension)
target_sources(pylene_extension PRIVATE pylene_extension.cpp)
target_link_libraries(pylene_extension PRIVATE Pylene::Pylene-numpy) # CONAN_LIBS_PYBIND11 TO REMOVE WHEN cmake_find_package FOR PYBIND11 WORKS
file(COPY ${CMAKE_SOURCE_DIR}/main.py DESTINATION ${CMAKE_BINARY_DIR})
endif(WITH_PYLENA_NUMPY)
\ No newline at end of file
endif(WITH_PYLENE_NUMPY)
\ No newline at end of file
from conans import ConanFile, CMake
from conans import ConanFile, CMake, tools
import os
import sys
......@@ -8,10 +8,10 @@ class PyleneTestConan(ConanFile):
def build(self):
os.remove(os.path.join(self.build_folder, "Findpybind11.cmake"))
cmake = CMake(self)
if self.options["pylene"].pylena_numpy and self.options["pylene"].fPIC:
cmake.definitions["WITH_PYLENA_NUMPY"] = "YES"
if self.options["pylene"].shared or self.options["pylene"].fPIC or tools.os_info.is_windows:
os.remove(os.path.join(self.build_folder, "Findpybind11.cmake")) # TO REMOVE WHEN cmake_find_package FOR PYBIND11 WORK
cmake.definitions["WITH_PYLENE_NUMPY"] = "YES"
cmake.configure()
cmake.build()
......@@ -21,4 +21,5 @@ class PyleneTestConan(ConanFile):
def test(self):
self.run(".{}main".format(os.sep))
if self.options["pylene"].shared or self.options["pylene"].fPIC or tools.os_info.is_windows:
self.run("{} main.py".format(sys.executable))
......@@ -43,6 +43,6 @@ add_subdirectory(morpho)
add_subdirectory(labeling)
add_subdirectory(contrib)
add_subdirectory(bp)
if (PYLENE_BUILD_PYTHON AND CMAKE_POSITION_INDEPENDENT_CODE)
if (PYLENE_BUILD_PYTHON)
add_subdirectory(python)
endif()
\ No newline at end of file
# Python module for testing
pybind11_add_module(pylena_test pylena_test.cpp)
target_link_libraries(pylena_test PRIVATE Pylene Pylena_numpy)
target_link_libraries(pylena_test PRIVATE Pylene Pylene-numpy)
target_include_directories(pylena_test PRIVATE ${CONAN_INCLUDE_DIRS_PYBIND11} ${PYTHON_INCLUDE_DIRS}) # TO REMOVE WHEN cmake_find_package FOR PYBIND11 WILL BE FIXED
add_dependencies(build-tests pylena_test)
# Dummy extension for testing
pybind11_add_module(pylena_extension extension_pylena_numpy.cpp)
target_link_libraries(pylena_extension PRIVATE Pylene Pylena_numpy)
target_link_libraries(pylena_extension PRIVATE Pylene Pylene-numpy)
target_include_directories(pylena_extension PRIVATE ${CONAN_INCLUDE_DIRS_PYBIND11} ${PYTHON_INCLUDE_DIRS}) # TO REMOVE WHEN cmake_find_package FOR PYBIND11 WILL BE FIXED
add_dependencies(build-tests pylena_extension)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment