Commit a118f79a authored by Baptiste Esteban's avatar Baptiste Esteban
Browse files

Merge branch 'development/fix-pybind11-conan' into 'next'

Fix cmake_find_package generator with pybind11

See merge request !114
parents 689df3e5 f3a76eab
Pipeline #27912 passed with stages
in 23 minutes and 51 seconds
......@@ -98,10 +98,6 @@ endif ()
add_subdirectory(pylene)
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)
endif()
......
......@@ -18,7 +18,6 @@ At first, a ``conanfile.txt`` is created.
[generators]
cmake_find_package
cmake
[requires]
pylene/head@lrde/unstable
......@@ -27,16 +26,8 @@ At first, a ``conanfile.txt`` is created.
[options]
pylene:fPIC=True # or pylene:shared=True
In this conanfile, two Conan's generators are used: the ``cmake`` and
the ``cmake_find_package`` generators. In the previous section, it is specified
that the ``cmake_find_package`` one is prefered but an issue in the Conan Center
Index makes it unusable for Pybind11 (see `here
<https://github.com/conan-io/conan-center-index/pull/4445>`_ for more details).
For the same reason, the Pybind11 package is not a runtime dependency of the
``Pylene-numpy`` library and should be specified as a dependency of the
extension project. Finally, the `fPIC` option is specified as an option for
Pylene, which enable to have the ``Pylene-numpy`` library during the
dependencies installation.
The `fPIC` option is specified as an option for Pylene, which enable to have the
``Pylene-numpy`` library during the dependencies installation.
Then, below is the ``CMakeLists.txt``:
......@@ -45,15 +36,10 @@ Then, below is the ``CMakeLists.txt``:
cmake_minimum_required(VERSION 3.14)
project(pylene_extension)
if (NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake")
message(FATAL_ERROR "Conan dit not run. Please run conan install.")
endif()
include("${CMAKE_CURRENT_BINARY_DIR}/conanbuildinfo.cmake")
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_BINARY_DIR}" "${CONAN_BUILD_DIRS_PYBIND11}")
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_BINARY_DIR}")
find_package(Pylene REQUIRED)
include(pybind11Install)
find_package(pybind11 REQUIRED)
pybind11_add_module(pylene_extension)
target_sources(pylene_extension PRIVATE pylene_extension.cpp)
target_link_libraries(pylene_extension PUBLIC Pylene::Pylene-numpy)
......
......@@ -4,23 +4,22 @@ if (NOT CMAKE_POSITION_INDEPENDENT_CODE)
endif()
find_package(fmt 6.0 REQUIRED)
find_package(pybind11 REQUIRED)
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>
# PYBIND11 INCLUDES TO REMOVE WHEN cmake_find_package FOR PYBIND11 WILL BE FIXED
PRIVATE
${CONAN_INCLUDE_DIRS_PYBIND11}
${PYTHON_INCLUDE_DIRS})
)
target_sources(Pylene-numpy PRIVATE src/core/image_cast.cpp
src/core/numpy_format.cpp)
# REPLACE PYTHON_LIBRARIES BY pybind11::pybind11 WHEN cmake_find_package FOR PYBIND11 WILL BE FIXED
target_link_libraries(Pylene-numpy PUBLIC Pylene ${PYTHON_LIBRARIES})
target_link_libraries(Pylene-numpy PRIVATE fmt::fmt)
target_include_directories(Pylene-numpy PRIVATE ${pybind11_INCLUDE_DIRS})
pybind11_add_module(pylena)
target_link_libraries(pylena PRIVATE Pylene Pylene-numpy ${PYTHON_LIBRARIES})
target_link_libraries(pylena PRIVATE Pylene Pylene-numpy)
target_include_directories(pylena PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_sources(pylena PRIVATE src/module.cpp)
......
project(PyleneTest)
cmake_minimum_required(VERSION 3.11)
# 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")
conan_set_rpath()
endif()
find_package(Pylene REQUIRED COMPONENTS Pylene)
add_executable(main main.cpp)
target_link_libraries(main Pylene::Pylene)
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)
find_package(pybind11 REQUIRED)
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
target_link_libraries(pylene_extension PRIVATE Pylene::Pylene-numpy)
file(COPY ${CMAKE_SOURCE_DIR}/main.py DESTINATION ${CMAKE_BINARY_DIR})
endif(WITH_PYLENE_NUMPY)
\ No newline at end of file
......@@ -4,7 +4,7 @@ import sys
class PyleneTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = [ "cmake_find_package", "cmake" ]
generators = [ "cmake_find_package" ]
requires = ["pybind11/2.6.2"]
......
......@@ -12,16 +12,16 @@ if (UNIX AND NOT CYGWIN)
endif()
endif()
find_package(pybind11 REQUIRED)
# Python module for testing
pybind11_add_module(pylena_test pylena_test.cpp)
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 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)
function(add_python_test filename)
......
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