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

Fix cmake_find_package generator with pybind11

parent 689df3e5
Pipeline #27513 failed with stage
in 19 minutes and 22 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()
......
......@@ -4,23 +4,21 @@ 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 PUBLIC Pylene pybind11::headers)
target_link_libraries(Pylene-numpy PRIVATE fmt::fmt)
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,6 +12,8 @@ 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)
......
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