Skip to content

Commit 52dbc06

Browse files
committed
#24 fix vtkWrappingPythonCore
1 parent a611e13 commit 52dbc06

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

CMakeLists.txt

+44-35
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,23 @@
3737
# PyChaste needs the cell_based component (and its dependencies)
3838
find_package(Chaste COMPONENTS cell_based)
3939

40+
# Do Chaste project preprocessing, which results in something like:
41+
# add_custom_target(project_PyChaste)
42+
# set(Chaste_project_PyChaste_SOURCE_DIR ...)
43+
# set(Chaste_project_PyChaste_INCLUDE_DIRS ...)
44+
# include_directories("${Chaste_THIRD_PARTY_INCLUDE_DIRS}")
45+
# include_directories("${Chaste_project_PyChaste_INCLUDE_DIRS}")
46+
# include_directories("${Chaste_INCLUDE_DIRS}")
47+
# add_library(chaste_project_PyChaste ...)
48+
# target_link_libraries(chaste_project_PyChaste ...)
49+
chaste_do_project(PyChaste)
50+
51+
add_library(PyChaste_COMMON_DEPS INTERFACE)
52+
53+
# PyChaste needs the Python3 development libraries
54+
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
55+
target_link_libraries(PyChaste_COMMON_DEPS INTERFACE Python3::Module)
56+
4057
# PyChaste needs some additional VTK libraries
4158
if(VTK_MAJOR_VERSION LESS 7)
4259
find_package(VTK REQUIRED COMPONENTS
@@ -71,9 +88,9 @@ else()
7188
IOMovie
7289
RenderingAnnotation
7390
RenderingCore
74-
RenderingFreeType
75-
RenderingOpenGL2
76-
WrappingPythonCore
91+
# RenderingFreeType # needs Freetype::Freetype
92+
# RenderingOpenGL2 # needs X11::X11 and GLEW::GLEW
93+
WrappingPythonCore # needs Python3::Module
7794
)
7895
endif()
7996

@@ -82,20 +99,10 @@ if (VTK_MAJOR_VERSION LESS 9)
8299
list(APPEND Chaste_project_PyChaste_INCLUDE_DIRS "${VTK_INCLUDE_DIRS}")
83100
list(APPEND Chaste_THIRD_PARTY_LIBRARIES "${VTK_LIBRARIES}")
84101
else()
85-
target_link_libraries(Chaste_COMMON_DEPS INTERFACE ${VTK_LIBRARIES})
102+
target_link_libraries(PyChaste_COMMON_DEPS INTERFACE VTK::WrappingPythonCore)
103+
# target_link_libraries(PyChaste_COMMON_DEPS INTERFACE ${VTK_LIBRARIES})
86104
endif ()
87105

88-
# Do Chaste project preprocessing, which results in something like:
89-
# add_custom_target(project_PyChaste)
90-
# set(Chaste_project_PyChaste_SOURCE_DIR ...)
91-
# set(Chaste_project_PyChaste_INCLUDE_DIRS ...)
92-
# include_directories("${Chaste_THIRD_PARTY_INCLUDE_DIRS}")
93-
# include_directories("${Chaste_project_PyChaste_INCLUDE_DIRS}")
94-
# include_directories("${Chaste_INCLUDE_DIRS}")
95-
# add_library(chaste_project_PyChaste ...)
96-
# target_link_libraries(chaste_project_PyChaste ...)
97-
chaste_do_project(PyChaste)
98-
99106
#========================================
100107
# Compiler options
101108
#========================================
@@ -116,8 +123,7 @@ set(PYCHASTE_INCLUDE_DIRS
116123
${CMAKE_CURRENT_SOURCE_DIR}/src/cell_based/
117124
${CMAKE_CURRENT_SOURCE_DIR}/src/ode/
118125
${CMAKE_CURRENT_SOURCE_DIR}/src/tutorial/
119-
${CMAKE_CURRENT_SOURCE_DIR}/src/visualization/
120-
${CMAKE_CURRENT_SOURCE_DIR}/dynamic/)
126+
${CMAKE_CURRENT_SOURCE_DIR}/src/visualization/)
121127

122128
# Non-wrapper code needs to be put in a separate shared library
123129
set(PYCHASTE_SHARED_LIB
@@ -183,44 +189,47 @@ set (PYCHASTE_PYTHON_MODULE_LOCATIONS
183189
${CMAKE_CURRENT_BINARY_DIR}/python/chaste/
184190
${CMAKE_CURRENT_BINARY_DIR}/python/chaste/tutorial/)
185191

192+
# The module library name must be the same as the pybind11 module name
193+
# defined in the main wrapper e.g. `dynamic/wrappers/ode/ode.main.cpp`
194+
# defines a pybind11 module `_chaste_project_PyChaste_ode`. By convention,
195+
# the name starts with an underscore. The usual 'lib' prefix is disabled.
196+
set(PYCHASTE_PYTHON_MODULE_PREFIX "_chaste_project_PyChaste_")
197+
186198
# Create a shared library target for each module
187-
list(LENGTH PYCHASTE_PYTHON_MODULES max_module_idx)
188-
math(EXPR max_module_idx "${max_module_idx} - 1")
189-
set(module_prefix "_chaste_project_PyChaste_")
199+
list(LENGTH PYCHASTE_PYTHON_MODULES max_idx)
200+
math(EXPR max_idx "${max_idx} - 1")
190201

191-
foreach(idx RANGE ${max_module_idx})
192-
list(GET PYCHASTE_PYTHON_MODULES ${idx} module_name)
202+
foreach(idx RANGE ${max_idx})
203+
list(GET PYCHASTE_PYTHON_MODULES ${idx} module)
193204
list(GET PYCHASTE_PYTHON_MODULE_LOCATIONS ${idx} module_dir)
194205

195206
# Glob the module's wrapper code from the `dynamic` directory
196-
file(GLOB module_sources ${CMAKE_CURRENT_SOURCE_DIR}/dynamic/wrappers/${module_name}/*.cpp)
207+
file(GLOB module_sources ${CMAKE_CURRENT_SOURCE_DIR}/dynamic/wrappers/${module}/*.cpp)
197208

198-
# The module library name here must be the same as the pybind11 module name
199-
# defined in the main wrapper e.g. `dynamic/wrappers/ode/ode.main.cpp`
200-
# defines a pybind11 module `_chaste_project_PyChaste_ode`. By convention,
201-
# the name starts with an underscore. The usual 'lib' prefix is disabled.
202-
add_library(${module_prefix}${module_name} SHARED ${module_sources})
209+
set(module_library_name ${PYCHASTE_PYTHON_MODULE_PREFIX}${module})
210+
add_library(${module_library_name} SHARED ${module_sources})
203211

204-
set_target_properties(${module_prefix}${module_name}
212+
set_target_properties(${module_library_name}
205213
PROPERTIES
206214
LIBRARY_OUTPUT_DIRECTORY ${module_dir}
207215
PREFIX "${PYTHON_MODULE_PREFIX}"
208216
SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}")
209217

210218
# The order here is important - pybind11 and python come first
211-
target_link_libraries(${module_prefix}${module_name}
219+
target_link_libraries(${module_library_name}
212220
pybind11::module
213-
${PYTHON3_LIBRARIES}
221+
Python3::Module
214222
${Chaste_THIRD_PARTY_LIBRARIES}
223+
Chaste_COMMON_DEPS
224+
PyChaste_COMMON_DEPS
215225
${Chaste_LIBRARIES}
216226
${PYCHASTE_SHARED_LIB})
217227

218-
add_dependencies(${module_prefix}${module_name} chaste_project_PyChaste)
228+
add_dependencies(${module_library_name} chaste_project_PyChaste)
219229
endforeach()
220230

221231
# Target for building all module shared libraries
222232
add_custom_target(project_PyChaste_Python)
223-
foreach(idx RANGE ${max_module_idx})
224-
list(GET PYCHASTE_PYTHON_MODULES ${idx} module_name)
225-
add_dependencies(project_PyChaste_Python ${module_prefix}${module_name})
233+
foreach(module IN LISTS PYCHASTE_PYTHON_MODULES)
234+
add_dependencies(project_PyChaste_Python ${PYCHASTE_PYTHON_MODULE_PREFIX}${module})
226235
endforeach()

0 commit comments

Comments
 (0)