forked from mborgerson/pyside6_qtads
-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
266 lines (210 loc) · 11.2 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
cmake_minimum_required(VERSION 3.16)
cmake_policy(VERSION 3.16)
# Enable policy to run automoc on generated files.
if(POLICY CMP0071)
cmake_policy(SET CMP0071 NEW)
endif()
# ================================ General configuration ======================================
project(PySide6QtAds)
# Find Python
find_package (Python3 COMPONENTS Interpreter Development)
if(NOT Python3_Interpreter_FOUND)
message(FATAL_ERROR "Python3 not found")
endif()
message(STATUS "Using python: ${Python3_EXECUTABLE}")
# https://bugreports.qt.io/browse/QTBUG-89754
set(OpenGL_GL_PREFERENCE "LEGACY")
# Find the required Qt packages
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
find_package(Shiboken6 6.0.0 REQUIRED)
find_package(PySide6 6.0.0 REQUIRED)
# Set CPP standard to C++11 minimum.
set(CMAKE_CXX_STANDARD 11)
# The C++ project library for which we will create bindings.
set(qtads_subdir "Qt-Advanced-Docking-System")
set(qtads_dir ${CMAKE_CURRENT_SOURCE_DIR}/${qtads_subdir})
add_subdirectory(${qtads_subdir} EXCLUDE_FROM_ALL)
set(project_library "qtadvanceddocking")
# The name of the generated bindings module (as imported in Python).
set(bindings_library "PySide6QtAds")
# The header file with all the types and functions for which bindings will be generated.
# Usually it simply includes other headers of the library you are creating bindings for.
set(wrapped_header ${CMAKE_CURRENT_SOURCE_DIR}/src/bindings.h)
# The typesystem xml file which defines the relationships between the C++ types / functions
# and the corresponding Python equivalents.
set(typesystem_file ${CMAKE_CURRENT_SOURCE_DIR}/src/bindings.xml)
# Specify which C++ files will be generated by shiboken. This includes the module wrapper
# and a '.cpp' file per C++ type. These are needed for generating the module shared
# library.
set(generated_sources
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdockareatabbar_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdockareatitlebar_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdockareawidget_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdockcomponentsfactory_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdockcontainerwidget_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdockfocuscontroller_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdockingstatereader_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdockmanager_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdockoverlay_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdockoverlaycross_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdocksplitter_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdockwidget_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cdockwidgettab_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_celidinglabel_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cfloatingdockcontainer_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cfloatingdragpreview_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_ciconprovider_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_cspacerwidget_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_ctitlebarbutton_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_ifloatingwidget_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/ads_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/pyside6qtads_module_wrapper.cpp
)
# ================================== Shiboken detection ======================================
# Query for the shiboken generator path, Python path, include paths and linker flags.
get_property(shiboken_include_dir TARGET Shiboken6::libshiboken PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
get_property(shiboken_shared_libraries TARGET Shiboken6::libshiboken PROPERTY IMPORTED_IMPLIB_RELEASE)
get_property(pyside_include_dir TARGET PySide6::pyside6 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
get_property(pyside_shared_libraries TARGET PySide6::pyside6 PROPERTY IMPORTED_IMPLIB_RELEASE)
find_program(shiboken_path "shiboken6${CMAKE_EXECUTABLE_SUFFIX}")
if(NOT EXISTS ${shiboken_path})
message(FATAL_ERROR "Shiboken executable not found at path: ${shiboken_path}")
endif()
# ==================================== RPATH configuration ====================================
if(UNIX AND NOT APPLE)
set(CMAKE_INSTALL_RPATH "$ORIGIN/lib:$ORIGIN/../PySide6/:$ORIGIN/../PySide6/Qt/lib:$ORIGIN/../shiboken6")
endif()
if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path/lib;@loader_path/../PySide6/;@loader_path/../PySide6/Qt/lib;@loader_path/../shiboken6")
set(MACOSX_RPATH TRUE)
endif()
# ============================== Qt Includes for project_library ==============================
# Get the relevant Qt include dirs, to pass them on to shiboken.
set(QT_INCLUDE_DIR "")
get_target_property(QT_INCLUDE_DIR_LIST Qt6::Core INTERFACE_INCLUDE_DIRECTORIES)
foreach(_Q ${QT_INCLUDE_DIR_LIST})
if(NOT "${_Q}" MATCHES "QtCore$")
set(QT_INCLUDE_DIR "${_Q}")
endif()
endforeach()
if(QT_INCLUDE_DIR STREQUAL "")
message(FATAL_ERROR "Unable to obtain the Qt include directory")
endif()
set(QT_INCLUDES "")
list(APPEND QT_INCLUDES "-I${QT_INCLUDE_DIR}")
get_property(QT_CORE_INCLUDE_DIRS TARGET Qt6::Core PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
foreach(INCLUDE_DIR ${QT_CORE_INCLUDE_DIRS})
list(APPEND QT_INCLUDES "-I${INCLUDE_DIR}")
endforeach()
get_property(QT_GUI_INCLUDE_DIRS TARGET Qt6::Gui PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
foreach(INCLUDE_DIR ${QT_GUI_INCLUDE_DIRS})
list(APPEND QT_INCLUDES "-I${INCLUDE_DIR}")
endforeach()
get_property(QT_WIDGETS_INCLUDE_DIRS TARGET Qt6::Widgets PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
foreach(INCLUDE_DIR ${QT_WIDGETS_INCLUDE_DIRS})
list(APPEND QT_INCLUDES "-I${INCLUDE_DIR}")
endforeach()
# Check if Qt is a framework build on macOS. This affects how include paths should be handled.
get_target_property(QtCore_is_framework Qt6::Core FRAMEWORK)
if (QtCore_is_framework)
# Get the path to the Qt framework dir.
set(QT_FRAMEWORK_INCLUDE_DIR "${QT6_INSTALL_PREFIX}/${QT6_INSTALL_LIBS}")
message(STATUS "*** QT_FRAMEWORK_INCLUDE_DIR is ${QT_FRAMEWORK_INCLUDE_DIR}")
list(APPEND QT_INCLUDES "--framework-include-paths=${QT_FRAMEWORK_INCLUDE_DIR}")
endif()
# We need to include the headers for the module bindings that we use
set(pyside_additional_includes "")
foreach(INCLUDE_DIR ${pyside_include_dir})
list(APPEND pyside_additional_includes "${INCLUDE_DIR}/QtCore")
list(APPEND pyside_additional_includes "${INCLUDE_DIR}/QtGui")
list(APPEND pyside_additional_includes "${INCLUDE_DIR}/QtWidgets")
endforeach()
# ====================== Shiboken target for generating binding C++ files ====================
set(implicit_includes)
foreach(_current ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
set(implicit_includes ${implicit_includes} "-I${_current}")
endforeach()
# Set up the options to pass to shiboken.
set(shiboken_options --generator-set=shiboken --enable-parent-ctor-heuristic
--enable-pyside-extensions --enable-return-value-heuristic --use-isnull-as-nb_nonzero
--avoid-protected-hack
${QT_INCLUDES}
${implicit_includes}
-I${qtads_dir}/src
-T${CMAKE_CURRENT_SOURCE_DIR}
-T${PYSIDE_TYPESYSTEMS}
--output-directory=${CMAKE_CURRENT_BINARY_DIR}
)
set(generated_sources_dependencies ${wrapped_header} ${typesystem_file})
# Add custom target to run shiboken to generate the binding cpp files.
add_custom_command(OUTPUT ${generated_sources}
COMMAND ${shiboken_path}
${shiboken_options} ${wrapped_header} ${typesystem_file}
DEPENDS ${generated_sources_dependencies}
IMPLICIT_DEPENDS CXX ${wrapped_header}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Running generator for ${typesystem_file}.")
# =============================== CMake target - bindings_library =============================
# Set the cpp files which will be used for the bindings library.
set(${bindings_library}_sources ${generated_sources})
# Define and build the bindings library.
add_library(${bindings_library} MODULE ${${bindings_library}_sources})
# Apply relevant include and link flags.
target_include_directories(${bindings_library} PRIVATE ${pyside_additional_includes})
target_include_directories(${bindings_library} PRIVATE ${pyside_include_dir})
target_include_directories(${bindings_library} PRIVATE ${Python3_INCLUDE_DIRS})
target_include_directories(${bindings_library} PRIVATE ${shiboken_include_dir})
target_include_directories(${bindings_library} PRIVATE "${CMAKE_SOURCE_DIR}/src")
target_link_libraries(${bindings_library} PRIVATE Qt6::Widgets)
target_link_libraries(${bindings_library} PRIVATE ${project_library})
target_link_libraries(${bindings_library} PRIVATE ${pyside_shared_libraries})
target_link_libraries(${bindings_library} PRIVATE ${shiboken_shared_libraries})
if (UNIX)
target_link_libraries(${bindings_library} PUBLIC PySide6::pyside6)
endif()
target_compile_options(qtadvanceddocking PRIVATE -Og)
target_compile_options(${bindings_library} PRIVATE -Og)
target_compile_definitions(${bindings_library} PRIVATE "-DPy_LIMITED_API=0x03070000")
# Adjust the name of generated module.
set_property(TARGET ${bindings_library} PROPERTY PREFIX "")
set_property(TARGET ${bindings_library} PROPERTY OUTPUT_NAME
"${bindings_library}${PYTHON_EXTENSION_SUFFIX}")
if(WIN32)
set_property(TARGET ${bindings_library} PROPERTY SUFFIX ".pyd")
endif()
# Make sure the linker doesn't complain about not finding Python symbols on macOS.
if(APPLE)
set_target_properties(${bindings_library} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
endif(APPLE)
if (WIN32)
target_link_directories(${bindings_library} PRIVATE ${Python3_LIBRARY_DIRS})
endif()
# ===================================== CMake target - pyi ====================================
set(generate_pyi_options ${bindings_library} --sys-path
"${CMAKE_CURRENT_BINARY_DIR}")
# Add target to generate pyi file, which depends on the module target.
add_custom_target("${bindings_library}_pyi" ALL
COMMAND ${CMAKE_COMMAND} -E env ${ld_prefix}
"${Python3_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/support/generate_pyi.py" ${generate_pyi_options}
BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}.pyi")
add_dependencies("${bindings_library}_pyi" ${bindings_library})
# ================================= Dubious deployment section ================================
install(TARGETS ${bindings_library}
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}
)
if(NOT BUILD_STATIC)
install(TARGETS ${project_library}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()
install(FILES ${hinting_stub_files}
DESTINATION "${CMAKE_INSTALL_PREFIX}")
install(FILES
"${qtads_dir}/LICENSE"
"${qtads_dir}/gnu-lgpl-v2.1.md"
DESTINATION license/ads
COMPONENT license
)