37
37
# PyChaste needs the cell_based component (and its dependencies)
38
38
find_package (Chaste COMPONENTS cell_based)
39
39
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
+
40
57
# PyChaste needs some additional VTK libraries
41
58
if (VTK_MAJOR_VERSION LESS 7)
42
59
find_package (VTK REQUIRED COMPONENTS
71
88
IOMovie
72
89
RenderingAnnotation
73
90
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
77
94
)
78
95
endif ()
79
96
@@ -82,20 +99,10 @@ if (VTK_MAJOR_VERSION LESS 9)
82
99
list (APPEND Chaste_project_PyChaste_INCLUDE_DIRS "${VTK_INCLUDE_DIRS} " )
83
100
list (APPEND Chaste_THIRD_PARTY_LIBRARIES "${VTK_LIBRARIES} " )
84
101
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})
86
104
endif ()
87
105
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
-
99
106
#========================================
100
107
# Compiler options
101
108
#========================================
@@ -116,8 +123,7 @@ set(PYCHASTE_INCLUDE_DIRS
116
123
${CMAKE_CURRENT_SOURCE_DIR} /src/cell_based/
117
124
${CMAKE_CURRENT_SOURCE_DIR} /src/ode/
118
125
${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/)
121
127
122
128
# Non-wrapper code needs to be put in a separate shared library
123
129
set (PYCHASTE_SHARED_LIB
@@ -183,44 +189,47 @@ set (PYCHASTE_PYTHON_MODULE_LOCATIONS
183
189
${CMAKE_CURRENT_BINARY_DIR} /python/chaste/
184
190
${CMAKE_CURRENT_BINARY_DIR} /python/chaste/tutorial/)
185
191
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
+
186
198
# 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" )
190
201
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 )
193
204
list (GET PYCHASTE_PYTHON_MODULE_LOCATIONS ${idx} module_dir)
194
205
195
206
# 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)
197
208
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} )
203
211
204
- set_target_properties (${module_prefix}${module_name }
212
+ set_target_properties (${module_library_name }
205
213
PROPERTIES
206
214
LIBRARY_OUTPUT_DIRECTORY ${module_dir}
207
215
PREFIX "${PYTHON_MODULE_PREFIX} "
208
216
SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX} " )
209
217
210
218
# 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}
212
220
pybind11::module
213
- ${PYTHON3_LIBRARIES}
221
+ Python3::Module
214
222
${Chaste_THIRD_PARTY_LIBRARIES}
223
+ Chaste_COMMON_DEPS
224
+ PyChaste_COMMON_DEPS
215
225
${Chaste_LIBRARIES}
216
226
${PYCHASTE_SHARED_LIB} )
217
227
218
- add_dependencies (${module_prefix}${module_name } chaste_project_PyChaste)
228
+ add_dependencies (${module_library_name } chaste_project_PyChaste)
219
229
endforeach ()
220
230
221
231
# Target for building all module shared libraries
222
232
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} )
226
235
endforeach ()
0 commit comments