This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
170 lines (138 loc) · 8.49 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
cmake_minimum_required(VERSION 3.1)
cmake_policy(VERSION 3.1)
# Consider changing the project name to something relevant for you.
project(PySide2Ads)
# ================================ General configuration ======================================
# Set CPP standard to C++11 minimum.
set(CMAKE_CXX_STANDARD 11)
# The sample library for which we will create bindings. You can change the name to something
# relevant for your project.
set(sample_library "qtadvanceddocking")
# The name of the generated bindings module (as imported in Python). You can change the name
# to something relevant for your project.
set(bindings_library "ads")
# 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_SOURCE_DIR}/bindings.h)
# The typesystem xml file which defines the relationships between the C++ types / functions
# and the corresponding Python equivalents.
set(typesystem_file ${CMAKE_SOURCE_DIR}/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}/${bindings_library}_cdockareatabbar_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_cdockareatitlebar_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_cdockareawidget_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_cdockcomponentsfactory_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_cdockcontainerwidget_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_cdockfocuscontroller_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_cdockmanager_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_cdockoverlay_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_cdocksplitter_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_cdockwidgettab_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_cdockwidget_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_celidinglabel_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_cfloatingdockcontainer_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_ciconprovider_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_module_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_wrapper.cpp
${CMAKE_CURRENT_BINARY_DIR}/${bindings_library}/${bindings_library}_python.h
)
# ================================== Shiboken detection ======================================
if(NOT PYTHON_EXECUTABLE)
find_program(PYTHON_EXECUTABLE "python")
endif()
message(STATUS "Using python interpreter: ${PYTHON_EXECUTABLE}")
find_package(Shiboken2 2.0.0 REQUIRED)
find_package(Shiboken2 COMPONENTS libshiboken REQUIRED)
find_package(PySide2 2.0.0 REQUIRED)
find_package(Qt5 COMPONENTS Widgets Core Gui REQUIRED)
find_package(qtadvanceddocking)
message(STATUS "Qt include dirs: ${Qt5Widgets_INCLUDE_DIRS}")
get_property(SHIBOKEN_INCLUDE_DIRS TARGET Shiboken2::libshiboken PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "Shiboken include dirs: ${SHIBOKEN_INCLUDE_DIRS}")
get_property(PYSIDE_INCLUDE_DIR TARGET PySide2::pyside2 PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "PySide2 include dir: ${PYSIDE_INCLUDE_DIR}")
get_property(ADS_INCLUDE_DIRS TARGET ads::qtadvanceddocking PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "QtAdvancedDocking include dirs: ${ADS_INCLUDE_DIRS}")
add_definitions(${Qt5Widgets_DEFINITIONS})
add_definitions(-DQT_NO_KEYWORDS)
# ====================== Shiboken target for generating binding C++ files ====================
list(JOIN Qt5Widgets_INCLUDE_DIRS ";-I" qt_includes)
set(qt_includes "-I${qt_includes}")
list(JOIN ADS_INCLUDE_DIRS ";-I" ads_includes)
set(ads_includes "-I${ads_includes}")
set(includes ${qt_includes} ${ads_includes})
# Set up the options to pass to shiboken.
set(shiboken_options --generator-set=shiboken --enable-parent-ctor-heuristic
--enable-return-value-heuristic --use-isnull-as-nb_nonzero
--avoid-protected-hack --enable-pyside-extensions
${qt_includes} ${ads_includes}
-I${CMAKE_SOURCE_DIR}/src
-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}
add_custom_command(OUTPUT ${generated_sources}
COMMAND "shiboken2"
${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 =============================
get_property(SHIBOKEN_LIBRARY TARGET Shiboken2::libshiboken PROPERTY IMPORTED_IMPLIB_RELEASE)
get_property(PYSIDE_LIBRARY TARGET PySide2::pyside2 PROPERTY IMPORTED_IMPLIB_RELEASE)
get_property(ADS_LINK_LIBRARIES TARGET ads::qtadvanceddocking PROPERTY INTERFACE_LINK_LIBRARIES)
get_property(ADS_LIBRARY TARGET ads::qtadvanceddocking PROPERTY IMPORTED_IMPLIB_RELEASE)
message(STATUS "QtAdvancedDocking lib: ${ADS_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 ${PYTHON_INCLUDE_DIRS})
target_include_directories(${bindings_library} PRIVATE ${Qt5Widgets_INCLUDE_DIRS})
target_include_directories(${bindings_library} PRIVATE ${SHIBOKEN_PYTHON_INCLUDE_DIRS})
target_include_directories(${bindings_library} PRIVATE ${SHIBOKEN_INCLUDE_DIRS})
target_include_directories(${bindings_library} PRIVATE ${PYSIDE_INCLUDE_DIR})
target_include_directories(${bindings_library} PRIVATE ${PYSIDE_INCLUDE_DIR}/QtCore/)
target_include_directories(${bindings_library} PRIVATE ${PYSIDE_INCLUDE_DIR}/QtWidgets/)
target_include_directories(${bindings_library} PRIVATE ${PYSIDE_INCLUDE_DIR}/QtGui/)
target_include_directories(${bindings_library} PRIVATE ${ADS_INCLUDE_DIRS})
target_include_directories(${bindings_library} PRIVATE
$<INSTALL_INTERFACE:include>
)
target_link_libraries(${bindings_library} PRIVATE ${PYSIDE_LIBRARY})
target_link_libraries(${bindings_library} PRIVATE ${SHIBOKEN_PYTHON_LIBRARIES})
target_link_libraries(${bindings_library} PRIVATE ${SHIBOKEN_LIBRARY})
target_link_libraries(${bindings_library} PRIVATE ${ADS_LINK_LIBRARIES})
target_link_libraries(${bindings_library} PRIVATE ${ADS_LIBRARY})
if (UNIX)
target_link_libraries(${bindings_library} PUBLIC qtadvanceddocking PySide2::pyside2)
endif()
# Adjust the name of generated module.
set_property(TARGET ${bindings_library} PROPERTY PREFIX "")
if(WIN32)
set_property(TARGET ${bindings_library} PROPERTY OUTPUT_NAME
"${bindings_library}${PYTHON_EXTENSION_SUFFIX}")
set_property(TARGET ${bindings_library} PROPERTY SUFFIX "${PYTHON_CONFIG_SUFFIX}.pyd")
else()
set_property(TARGET ${bindings_library} PROPERTY OUTPUT_NAME
"${bindings_library}${PYTHON_CONFIG_SUFFIX}")
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)
# =============================== CMake target - pyi =============================
set(generate_pyi_options QtAds --sys-path
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../..")
# 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}
"${PYTHON_EXECUTABLE}"
"${CMAKE_CURRENT_SOURCE_DIR}/support/generate_pyi.py" ${generate_pyi_options})
add_dependencies("${bindings_library}_pyi" ${bindings_library})