-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
285 lines (248 loc) · 11.1 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
Include(icecc.cmake)
project(shiboken2)
cmake_minimum_required(VERSION 3.0)
cmake_policy(VERSION 3.0)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules/
${CMAKE_MODULE_PATH})
find_package(Qt5 REQUIRED COMPONENTS Core Xml XmlPatterns)
add_definitions(${Qt5Core_DEFINITIONS})
set(shiboken_MAJOR_VERSION "2")
set(shiboken_MINOR_VERSION "0")
set(shiboken_MICRO_VERSION "0")
set(shiboken2_VERSION "${shiboken_MAJOR_VERSION}.${shiboken_MINOR_VERSION}.${shiboken_MICRO_VERSION}")
option(BUILD_TESTS "Build tests." TRUE)
option(USE_PYTHON_VERSION "Use specific python version to build shiboken2." "")
if (USE_PYTHON_VERSION)
find_package(PythonInterp ${USE_PYTHON_VERSION} REQUIRED)
find_package(PythonLibs ${USE_PYTHON_VERSION} REQUIRED)
else()
find_package(PythonInterp 2.6)
find_package(PythonLibs 2.6)
endif()
set(CLANG_DIR "")
set(CLANG_DIR_SOURCE "")
if (DEFINED ENV{LLVM_INSTALL_DIR})
set(CLANG_DIR $ENV{LLVM_INSTALL_DIR})
set(CLANG_DIR_SOURCE "LLVM_INSTALL_DIR")
elseif (DEFINED ENV{CLANG_INSTALL_DIR})
set(CLANG_DIR $ENV{CLANG_INSTALL_DIR})
set(CLANG_DIR_SOURCE "CLANG_INSTALL_DIR")
else ()
EXEC_PROGRAM("llvm-config" ARGS "--prefix" OUTPUT_VARIABLE CLANG_DIR)
set(CLANG_DIR_SOURCE "llvm-config")
if (NOT "${CLANG_DIR}" STREQUAL "")
EXEC_PROGRAM("llvm-config" ARGS "--version" OUTPUT_VARIABLE CLANG_VERSION)
if (CLANG_VERSION VERSION_LESS 3.9)
message(FATAL_ERROR "LLVM version 3.9 is required (llvm-config detected ${CLANG_VERSION} at ${CLANG_DIR}).")
endif()
endif()
endif()
if ("${CLANG_DIR}" STREQUAL "")
message(FATAL_ERROR "Unable to detect CLANG location by checking LLVM_INSTALL_DIR, CLANG_INSTALL_DIR or running llvm-config.")
elseif (NOT IS_DIRECTORY ${CLANG_DIR})
message(FATAL_ERROR "${CLANG_DIR} detected by ${CLANG_DIR_SOURCE} does not exist.")
endif()
set(CLANG_LIB_NAME "clang")
if(MSVC)
set(CLANG_LIB_NAME "libclang")
endif()
find_library(CLANG_LIBRARY ${CLANG_LIB_NAME} HINTS ${CLANG_DIR}/lib)
if (NOT EXISTS ${CLANG_LIBRARY})
message(FATAL_ERROR "Unable to find Clang library ${CLANG_LIB_NAME} in ${CLANG_DIR}.")
endif()
message(STATUS "CLANG: ${CLANG_DIR}, ${CLANG_LIBRARY} detected by ${CLANG_DIR_SOURCE}")
set(CLANG_EXTRA_INCLUDES ${CLANG_DIR}/include)
set(CLANG_EXTRA_LIBRARIES ${CLANG_LIBRARY})
## For debugging the PYTHON* variables
message("PYTHONLIBS_FOUND: " ${PYTHONLIBS_FOUND})
message("PYTHON_LIBRARIES: " ${PYTHON_LIBRARIES})
message("PYTHON_INCLUDE_DIRS: " ${PYTHON_INCLUDE_DIRS})
message("PYTHON_DEBUG_LIBRARIES: " ${PYTHON_DEBUG_LIBRARIES})
message("PYTHONINTERP_FOUND: " ${PYTHONINTERP_FOUND})
message("PYTHON_EXECUTABLE: " ${PYTHON_EXECUTABLE})
message("PYTHON_VERSION: " ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.${PYTHON_VERSION_PATCH})
# Queries the python sysconfig for the abi flags which need to be inserted into extension suffixes.
# Only present starting with Python 3.2.
# Corresponding configure switches to single letter flags:
# --with-pymalloc -> m
# --with-pydebug -> d
# --with-unicode -> u (rare)
macro(get_python3_abi_flags)
if (NOT PYTHON_ABI_FLAGS)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "if True:
import sysconfig
print(sysconfig.get_config_var('abiflags'))
"
OUTPUT_VARIABLE PYTHON_ABI_FLAGS
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
message("PYTHON_ABI_FLAGS: " ${PYTHON_ABI_FLAGS})
endmacro()
macro(get_python_multi_arch_suffix)
# TODO: This part needs testing to check if it is available on Windows.
# It is present on macOS, but is not used yet.
# Result is something like 'x86_64-linux-gnu'.
if (NOT PYTHON_MULTIARCH_SUFFIX)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "if True:
import sysconfig
print(sysconfig.get_config_var('MULTIARCH'))
"
OUTPUT_VARIABLE PYTHON_MULTIARCH_SUFFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
message("PYTHON_MULTIARCH_SUFFIX: " ${PYTHON_MULTIARCH_SUFFIX})
endmacro()
macro(get_python2_release_suffix)
# Result of imp.get_suffixes() is something like:
# [('_d.so', 'rb', 3), ('module_d.so', 'rb', 3), ('.x86_64-linux-gnu_d.so', 'rb', 3)]
# or alternatively the same but withut the '_d' part.
# The list comprehension is used to choose which suffix to include in library names.
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "if True:
import imp
print('_d' if any([tup[0].endswith('_d.so') for tup in imp.get_suffixes()]) else '')
"
OUTPUT_VARIABLE PYTHON_MODULE_RELEASE_SUFFIX
OUTPUT_STRIP_TRAILING_WHITESPACE)
message("PYTHON_MODULE_RELEASE_SUFFIX: " ${PYTHON_MODULE_RELEASE_SUFFIX})
endmacro()
# Note the quirk that UNIX includes Apple!
if (UNIX AND NOT APPLE)
if (NOT PYTHON_EXTENSION_SUFFIX)
get_python_multi_arch_suffix()
# The suffix added to .so libraries should be differenet between Python 2 and 3.
# The position of the multiarch suffix is different, and the way the debug flag is set
# computed differently.
# In Python 2 there is no standard way to query if the python interpeter was built in debug or
# release build (sysconfig.get_config_var('Py_Debug') can have a different value than you would
# expect if you do a custom Python build). The solution is to query for the import
# suffixes and check if _d is present there. It is present on Linux distribution
# packages of Python, but not in custom built Python builds, because the distros apply their
# custom patches too append the '_d's.
# In Python 3 (starting with 3.2) there is a standard way to check if '_d' needs to be added,
# as well as any other letters, by querying the abiflags sysconfig variable.
if (PYTHON_VERSION_MAJOR EQUAL 2)
get_python2_release_suffix()
if(PYTHON_MULTIARCH_SUFFIX)
set(PYTHON_EXTENSION_SUFFIX ".${PYTHON_MULTIARCH_SUFFIX}")
endif()
set(PYTHON_EXTENSION_SUFFIX "${PYTHON_EXTENSION_SUFFIX}${PYTHON_MODULE_RELEASE_SUFFIX}")
elseif (PYTHON_VERSION_MAJOR EQUAL 3)
get_python3_abi_flags()
set(PYTHON_EXTENSION_SUFFIX ".cpython-${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}${PYTHON_ABI_FLAGS}")
if(PYTHON_MULTIARCH_SUFFIX)
set(PYTHON_EXTENSION_SUFFIX "${PYTHON_EXTENSION_SUFFIX}-${PYTHON_MULTIARCH_SUFFIX}")
endif()
else()
message(FATAL_ERROR "Unsupported PYTHON_VERSION=${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.${PYTHON_VERSION_PATCH}!")
endif()
endif()
message(STATUS "PYTHON_EXTENSION_SUFFIX: ${PYTHON_EXTENSION_SUFFIX}")
endif ()
if (NOT PYTHON_SITE_PACKAGES)
execute_process(
COMMAND ${PYTHON_EXECUTABLE} -c "if True:
from distutils import sysconfig
from os.path import sep
print(sysconfig.get_python_lib(1, 0, prefix='${CMAKE_INSTALL_PREFIX}').replace(sep, '/'))
"
OUTPUT_VARIABLE PYTHON_SITE_PACKAGES
OUTPUT_STRIP_TRAILING_WHITESPACE)
if (NOT PYTHON_SITE_PACKAGES)
message(FATAL_ERROR "Could not detect Python module installation directory.")
elseif (APPLE)
message(STATUS "!!! The generated bindings will be installed on ${PYTHON_SITE_PACKAGES}, is it right!?")
endif()
endif()
if(MSVC)
# Qt5: this flag has changed from /Zc:wchar_t- in Qt4.X
set(CMAKE_CXX_FLAGS "/Zc:wchar_t /GR /EHsc /DWIN32 /D_WINDOWS /D_SCL_SECURE_NO_WARNINGS")
else()
if(CMAKE_HOST_UNIX AND NOT CYGWIN)
add_definitions(-fPIC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fvisibility=hidden -Wno-strict-aliasing")
endif()
set(CMAKE_CXX_FLAGS_DEBUG "-g")
option(ENABLE_GCC_OPTIMIZATION "Enable specific GCC flags to optimization library size and performance. Only available on Release Mode" 0)
if(ENABLE_GCC_OPTIMIZATION)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -Os -Wl,-O1")
if(NOT CMAKE_HOST_APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--hash-style=gnu")
endif()
endif()
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D QT_NO_CAST_FROM_ASCII -D QT_NO_CAST_TO_ASCII")
set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE)
if (WIN32)
set(PATH_SEP "\;")
else()
set(PATH_SEP ":")
endif()
if(CMAKE_HOST_APPLE)
set(OSX_USE_LIBCPP "OFF" CACHE BOOL "Explicitly link the libc++ standard library (useful for osx deployment targets lower than 10.9.")
if(OSX_USE_LIBCPP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
endif()
endif()
add_subdirectory(ApiExtractor)
set(generator_plugin_DIR ${LIB_INSTALL_DIR}/generatorrunner${generator_SUFFIX})
# uninstall target
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall "${CMAKE_COMMAND}"
-P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
set(SHIBOKEN_BUILD_TYPE "Release")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
if(NOT PYTHON_DEBUG_LIBRARIES)
message(WARNING "Python debug shared library not found; assuming python was built with shared library support disabled.")
endif()
if(NOT PYTHON_WITH_DEBUG)
message(WARNING "Compiling shiboken2 with debug enabled, but the python executable was not compiled with debug support.")
else()
add_definitions("-DPy_DEBUG")
set(SBK_ADD_PY_DEBUG_DEFINITION "add_definitions(\"-DPy_DEBUG\")")
set(SBK_PKG_CONFIG_PY_DEBUG_DEFINITION " -DPy_DEBUG")
endif()
set(SBK_PYTHON_LIBRARIES ${PYTHON_DEBUG_LIBRARIES})
set(SHIBOKEN_BUILD_TYPE "Debug")
else()
set(SBK_PYTHON_LIBRARIES ${PYTHON_LIBRARIES})
add_definitions("-DNDEBUG")
endif()
if(APPLE)
set(SBK_PYTHON_LIBRARIES "-undefined dynamic_lookup")
endif()
if(CMAKE_VERSION VERSION_LESS 2.8)
set(SBK_PYTHON_INCLUDE_DIR ${PYTHON_INCLUDE_PATH})
else()
set(SBK_PYTHON_INCLUDE_DIR ${PYTHON_INCLUDE_DIRS})
endif()
add_subdirectory(libshiboken)
add_subdirectory(doc)
# deps found, compile the generator.
if (Qt5Core_FOUND AND PYTHONINTERP_FOUND)
add_subdirectory(generator)
add_subdirectory(shibokenmodule)
if (BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
else()
message(WARNING "Some dependencies were not found, shiboken2 generator compilation disabled!")
endif()
add_subdirectory(data)
# dist target
set(ARCHIVE_NAME ${CMAKE_PROJECT_NAME}-${shiboken2_VERSION})
add_custom_target(dist
COMMAND mkdir -p "${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}" &&
git log > "${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}/ChangeLog" &&
git archive --prefix=${ARCHIVE_NAME}/ HEAD --format=tar --output="${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar" &&
tar -C "${CMAKE_BINARY_DIR}" --owner=root --group=root -r "${ARCHIVE_NAME}/ChangeLog" -f "${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar" &&
bzip2 -f9 "${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar" &&
echo "Source package created at ${CMAKE_BINARY_DIR}/${ARCHIVE_NAME}.tar.bz2."
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})