Skip to content
Snippets Groups Projects
Commit 854ee756 authored by Grégoire Kubler's avatar Grégoire Kubler Committed by Maxence Naud
Browse files

feat: homogeinized cmakelists w backend_cpu

parent e6541e0b
No related branches found
No related tags found
1 merge request!18v0.1.3
...@@ -62,8 +62,16 @@ target_include_directories(${module_name} ...@@ -62,8 +62,16 @@ target_include_directories(${module_name}
# PYTHON BINDING # PYTHON BINDING
if (PYBIND) if (PYBIND)
# Handles Python + pybind11 headers dependencies
include(PybindModuleCreation) include(PybindModuleCreation)
generate_python_binding() generate_python_binding(${CMAKE_PROJECT_NAME} ${module_name})
target_link_libraries(${module_name}
PUBLIC
pybind11::pybind11
PRIVATE
Python::Module
)
endif() endif()
target_compile_features(${module_name} PRIVATE cxx_std_14) target_compile_features(${module_name} PRIVATE cxx_std_14)
...@@ -133,6 +141,9 @@ export(EXPORT ${project}-targets ...@@ -133,6 +141,9 @@ export(EXPORT ${project}-targets
############################################## ##############################################
## Add test ## Add test
if(TEST) if(TEST)
if(PYBIND)
message(FATAL_ERROR "PYBIND and TEST are both enabled. But cannot compile with catch_2.\nChoose between pybind and Catch2 for compilation.")
endif()
enable_testing() enable_testing()
add_subdirectory(unit_tests) add_subdirectory(unit_tests)
endif() endif()
macro(generate_python_binding ) function(generate_python_binding pybind_module_name target_to_bind)
add_definitions(-DPYBIND) add_definitions(-DPYBIND)
Include(FetchContent) Include(FetchContent)
# Use the New FindPython mode, recommanded. Requires CMake 3.15+
find_package(Python 3.7.0
COMPONENTS Interpreter Development.Module
REQUIRED)
set(PYBIND11_FINDPYTHON ON)
set(PYBIND_VERSION v2.10.4) set(PYBIND_VERSION v2.10.4)
set(PYBIND11_FINDPYTHON ON)
message(STATUS "Retrieving pybind ${PYBIND_VERSION} from git") message(STATUS "Retrieving pybind ${PYBIND_VERSION} from git")
FetchContent_Declare( FetchContent_Declare(
PyBind11 PyBind11
GIT_REPOSITORY https://github.com/pybind/pybind11.git GIT_REPOSITORY https://github.com/pybind/pybind11.git
GIT_TAG ${PYBIND_VERSION} # or a later release GIT_TAG ${PYBIND_VERSION} # or a later release
) )
# Use the New FindPython mode, recommanded. Requires CMake 3.15+
find_package(Python COMPONENTS Interpreter Development.Module)
FetchContent_MakeAvailable(PyBind11) FetchContent_MakeAvailable(PyBind11)
message(STATUS "Creating binding for module ${project}") message(STATUS "Creating binding for module ${pybind_module_name}")
file(GLOB_RECURSE pybind_src_files "python_binding/*.cpp") file(GLOB_RECURSE pybind_src_files "python_binding/*.cpp")
pybind11_add_module(${project} MODULE ${pybind_src_files} "NO_EXTRAS") # NO EXTRA required for pip install pybind11_add_module(${pybind_module_name} MODULE ${pybind_src_files} "NO_EXTRAS") # NO EXTRA recquired for pip install
target_include_directories(${project} PUBLIC "python_binding" ${pybind11_INCLUDE_DIRECTORIES}) target_include_directories(${pybind_module_name} PUBLIC "python_binding")
# Handles Python + pybind11 headers dependencies target_link_libraries(${pybind_module_name} PUBLIC ${target_to_bind})
target_link_libraries(${module_name} endfunction()
PRIVATE
Python::Module
PUBLIC
pybind11::pybind11
)
target_link_libraries(${project} PUBLIC ${module_name})
endmacro()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment