summaryrefslogtreecommitdiffstats
path: root/sources/pyside2/libpyside/CMakeLists.txt
blob: 7b8adfc84a1ce2ebb522f5b3aae39b1d001300ff (plain)
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
project(libpyside)

if(${Qt5Qml_FOUND})
    if(NOT "${Qt5Qml_PRIVATE_INCLUDE_DIRS}" MATCHES "/QtQml/")
        string(REPLACE "/QtCore" "/QtQml" replaceme "${Qt5Core_PRIVATE_INCLUDE_DIRS}")
        list(APPEND Qt5Qml_PRIVATE_INCLUDE_DIRS ${replaceme})
        list(REMOVE_DUPLICATES Qt5Qml_PRIVATE_INCLUDE_DIRS)
    endif()
endif()

if(${Qt5Quick_FOUND})
    if(NOT "${Qt5Quick_PRIVATE_INCLUDE_DIRS}" MATCHES "/QtQuick/")
        string(REPLACE "/QtCore" "/QtQuick" replaceme "${Qt5Core_PRIVATE_INCLUDE_DIRS}")
        list(APPEND Qt5Quick_PRIVATE_INCLUDE_DIRS ${Qt5Qml_PRIVATE_INCLUDE_DIRS})
        list(APPEND Qt5Quick_PRIVATE_INCLUDE_DIRS ${replaceme})
        list(REMOVE_DUPLICATES Qt5Quick_PRIVATE_INCLUDE_DIRS)
    endif()
endif()

set(QML_PRIVATE_API_SUPPORT 0)
if(Qt5Qml_FOUND)
    # Used for registering custom QQuickItem classes defined in Python code.
    set(QML_SUPPORT 1)
    set(QML_INCLUDES ${Qt5Qml_INCLUDE_DIRS})
    set(QML_LIBRARIES ${Qt5Qml_LIBRARIES})

    if(Qt5Qml_PRIVATE_INCLUDE_DIRS)
        # Used for transforming QML exceptions into Python exceptions.
        set(QML_PRIVATE_API_SUPPORT 1)
        set(QML_INCLUDES ${QML_INCLUDES} ${Qt5Qml_PRIVATE_INCLUDE_DIRS})
    else()
        message(WARNING "QML private API include files could not be found, support for catching QML exceptions inside Python code will not work.")
    endif()
else()
    set(QML_SUPPORT 0)
    set(QML_PRIVATE_API_SUPPORT 0)
    set(QML_INCLUDES "")
    set(QML_LIBRARIES "")
endif()

qt5_wrap_cpp(DESTROYLISTENER_MOC "destroylistener.h")

set(libpyside_SRC
    dynamicqmetaobject.cpp
    destroylistener.cpp
    signalmanager.cpp
    globalreceiverv2.cpp
    pysideclassinfo.cpp
    pysidemetafunction.cpp
    pysidesignal.cpp
    pysideslot.cpp
    pysideproperty.cpp
    pysideqflags.cpp
    pysideweakref.cpp
    pyside.cpp
    ${DESTROYLISTENER_MOC}
)

# Add python files to project explorer in Qt Creator, when opening the CMakeLists.txt as a project,
# so you can look up python files with the Locator.
macro(add_other_files)
     foreach(_it ${ARGN})
         if(NOT IS_DIRECTORY ${_it})
             get_filename_component(name ${_it} NAME)
             if(NOT ${_it} MATCHES "^/\\\\..*$;~$")
                 set_source_files_properties(${_it} PROPERTIES HEADER_FILE_ONLY TRUE)
             endif()
         endif()
     endforeach()
endmacro()

# Test files.
file(GLOB_RECURSE pyside_folder_py_files "../*.py")

# Mostly for setup.py.
file(GLOB setup_folder_py_files "../../../*.py")

set(other_files ${pyside_folder_py_files} ${setup_folder_py_files})
add_other_files(${other_files})

add_library(pyside2 SHARED ${libpyside_SRC} ${other_files})
add_library(PySide2::pyside2 ALIAS pyside2)

target_include_directories(pyside2 PRIVATE
    ${QML_INCLUDES}
    ${Qt5Core_PRIVATE_INCLUDE_DIRS}
    ${Qt5Core_INCLUDE_DIRS}
)

target_include_directories(pyside2 PUBLIC
  $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  $<INSTALL_INTERFACE:include/PySide2>
)

target_link_libraries(pyside2
                      PRIVATE Shiboken2::libshiboken
                      PRIVATE ${QML_LIBRARIES}
                      PRIVATE ${Qt5Core_LIBRARIES})

set_target_properties(pyside2 PROPERTIES
                      VERSION ${BINDING_API_VERSION}
                      SOVERSION "${PYSIDE_SO_VERSION}"
                      OUTPUT_NAME "pyside2${pyside2_SUFFIX}${SHIBOKEN_PYTHON_SHARED_LIBRARY_SUFFIX}"
                      DEFINE_SYMBOL PYSIDE_EXPORTS)

if(Qt5Core_VERSION VERSION_GREATER "5.7.1")
    set_property(TARGET pyside2 PROPERTY CXX_STANDARD 11)
endif()

if(QML_SUPPORT)
    target_compile_definitions(pyside2 PUBLIC PYSIDE_QML_SUPPORT=1)
endif()
target_compile_definitions(pyside2 PRIVATE PYSIDE_QML_PRIVATE_API_SUPPORT=${QML_PRIVATE_API_SUPPORT})

if(PYSIDE_QT_CONF_PREFIX)
    set_property(SOURCE pyside.cpp
                 APPEND
                 PROPERTY COMPILE_DEFINITIONS
                 PYSIDE_QT_CONF_PREFIX=${PYSIDE_QT_CONF_PREFIX})
endif()

#
# install stuff
#

set(libpyside_HEADERS
    destroylistener.h
    dynamicqmetaobject.h
    pysideclassinfo.h
    pysidemacros.h
    signalmanager.h
    pyside.h
    pysidemetafunction.h
    pysidesignal.h
    pysideproperty.h
    pysideqflags.h
    pysideweakref.h
)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
    set(LIBRARY_OUTPUT_SUFFIX ${CMAKE_DEBUG_POSTFIX})
else()
    set(LIBRARY_OUTPUT_SUFFIX ${CMAKE_RELEASE_POSTFIX})
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D QT_NO_CAST_FROM_ASCII -D QT_NO_CAST_TO_ASCII")

# create pkg-config file
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/pyside2.pc.in"
               "${CMAKE_CURRENT_BINARY_DIR}/pyside2${pyside2_SUFFIX}.pc" @ONLY)

# for creating cmake-config files
include(CMakePackageConfigHelpers)

# Build-tree / super project package config file.
set(PYSIDE_PYTHONPATH "${pysidebindings_BINARY_DIR}/PySide2")
set(PYSIDE_TYPESYSTEMS "${pysidebindings_SOURCE_DIR}/PySide2/templates/")
set(PYSIDE_GLUE "${pysidebindings_SOURCE_DIR}/PySide2/glue")

configure_package_config_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/PySide2Config-spec.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/PySide2Config${SHIBOKEN_PYTHON_CONFIG_SUFFIX}.cmake"
     INSTALL_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}"
     PATH_VARS PYSIDE_PYTHONPATH PYSIDE_TYPESYSTEMS PYSIDE_GLUE
     INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}"
)

set(PYSIDE_PYTHONPATH "${PYTHON_SITE_PACKAGES}/PySide2")
set(PYSIDE_TYPESYSTEMS "${CMAKE_INSTALL_PREFIX}/share/PySide2${pyside2_SUFFIX}/typesystems")
set(PYSIDE_GLUE "${CMAKE_INSTALL_PREFIX}/share/PySide2${pyside2_SUFFIX}/glue")

# Install-tree / relocatable package config file.
configure_package_config_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/PySide2Config-spec.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/install/PySide2Config${SHIBOKEN_PYTHON_CONFIG_SUFFIX}.cmake"
     INSTALL_DESTINATION "${LIB_INSTALL_DIR}/cmake/PySide2-${BINDING_API_VERSION}"
     PATH_VARS PYSIDE_PYTHONPATH PYSIDE_TYPESYSTEMS PYSIDE_GLUE
)

configure_file("${CMAKE_CURRENT_SOURCE_DIR}/PySide2Config.cmake.in"
               "${CMAKE_CURRENT_BINARY_DIR}/PySide2Config.cmake" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/PySide2ConfigVersion.cmake.in"
               "${CMAKE_CURRENT_BINARY_DIR}/PySide2ConfigVersion.cmake" @ONLY)

install(FILES ${libpyside_HEADERS}
        DESTINATION include/${BINDING_NAME}${pyside2_SUFFIX})

install(TARGETS pyside2 EXPORT PySide2Targets
                        LIBRARY DESTINATION "${LIB_INSTALL_DIR}"
                        ARCHIVE DESTINATION "${LIB_INSTALL_DIR}"
                        RUNTIME DESTINATION bin)
install(EXPORT PySide2Targets NAMESPACE PySide2::
        DESTINATION "${LIB_INSTALL_DIR}/cmake/PySide2-${BINDING_API_VERSION}")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pyside2${pyside2_SUFFIX}.pc"
        DESTINATION "${LIB_INSTALL_DIR}/pkgconfig")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/PySide2Config.cmake"
        DESTINATION "${LIB_INSTALL_DIR}/cmake/PySide2-${BINDING_API_VERSION}")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/install/PySide2Config${SHIBOKEN_PYTHON_CONFIG_SUFFIX}.cmake"
        DESTINATION "${LIB_INSTALL_DIR}/cmake/PySide2-${BINDING_API_VERSION}")

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/PySide2ConfigVersion.cmake"
        DESTINATION "${LIB_INSTALL_DIR}/cmake/PySide2-${BINDING_API_VERSION}")