aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristián Maureira-Fredes <cristian.maureira-fredes@qt.io>2019-08-14 17:40:18 +0200
committerCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2019-08-28 16:48:38 +0200
commit4d63dfffb661115f58cca60c80c4649ba982e01b (patch)
treedc25bf2dce3684b26dc5794f888146e0558d5f5d
parent5e4d33d8a53ed9df402bf715855e62cbe705621f (diff)
CMake modularization: macros creation
First step of this process that only considers the idea of encapsulate the diffrent CMake processes we currently have in all our main CMakeLists.txt files. This patch simply takes some sections of the existing cmake files and move them to a macro file. Additionally, a couple of macros were written twice in shiboken and pyside, so now they are only once. Task-number: PYSIDE-1033 Change-Id: I2c63d8a2eba3d8951097ec9c9042c782fde5dd62 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/cmake_helpers/helpers.cmake157
-rw-r--r--sources/pyside2/CMakeLists.txt193
-rw-r--r--sources/shiboken2/ApiExtractor/CMakeLists.txt17
-rw-r--r--sources/shiboken2/CMakeLists.txt276
-rw-r--r--sources/shiboken2/data/shiboken_helpers.cmake269
-rw-r--r--sources/shiboken2/shibokenmodule/CMakeLists.txt1
-rw-r--r--sources/shiboken2/tests/CMakeLists.txt14
7 files changed, 486 insertions, 441 deletions
diff --git a/sources/cmake_helpers/helpers.cmake b/sources/cmake_helpers/helpers.cmake
index e64b8d9d3..81b52920c 100644
--- a/sources/cmake_helpers/helpers.cmake
+++ b/sources/cmake_helpers/helpers.cmake
@@ -1,3 +1,160 @@
+macro(collect_essential_modules)
+# Collect all essential modules.
+# note: the order of this list is relevant for dependencies.
+# For instance: Qt5Printsupport must come before Qt5WebKitWidgets.
+set(ALL_ESSENTIAL_MODULES Core Gui Widgets PrintSupport Sql Network Test Concurrent)
+if(UNIX AND NOT APPLE)
+ list(APPEND ALL_ESSENTIAL_MODULES X11Extras)
+endif()
+if(WIN32)
+ list(APPEND ALL_ESSENTIAL_MODULES WinExtras)
+endif()
+if(APPLE)
+ list(APPEND ALL_ESSENTIAL_MODULES MacExtras)
+endif()
+endmacro()
+
+macro(collect_optional_modules)
+# Collect all optional modules.
+set(ALL_OPTIONAL_MODULES Xml XmlPatterns Help Multimedia
+MultimediaWidgets OpenGL OpenGLFunctions Positioning Location Qml Quick QuickWidgets RemoteObjects Scxml Script ScriptTools Sensors TextToSpeech Charts Svg DataVisualization)
+find_package(Qt5UiTools)
+if(Qt5UiTools_FOUND)
+ list(APPEND ALL_OPTIONAL_MODULES UiTools)
+else()
+ set(DISABLE_QtUiTools 1)
+endif()
+if(WIN32)
+ list(APPEND ALL_OPTIONAL_MODULES AxContainer)
+endif()
+# Disabling WebKit by default
+# If WebKit support is needed add the following elements
+# to the list: WebKit WebKitWidgets
+list(APPEND ALL_OPTIONAL_MODULES WebChannel WebEngineCore WebEngine WebEngineWidgets WebSockets)
+if (Qt5Core_VERSION VERSION_GREATER 5.9.3) # Depending on fixes in Qt3D
+ list(APPEND ALL_OPTIONAL_MODULES 3DCore 3DRender 3DInput 3DLogic 3DAnimation 3DExtras)
+endif()
+endmacro()
+
+macro(check_os)
+set(ENABLE_X11 "0")
+set(ENABLE_MAC "0")
+set(ENABLE_WIN "0")
+set(ENABLE_SIMULATOR "0")
+
+if(CMAKE_HOST_APPLE)
+ set(ENABLE_MAC "1")
+ set(AUTO_OS "mac")
+elseif(CMAKE_HOST_WIN32)
+ set(ENABLE_WIN "1")
+ set(AUTO_OS "win")
+elseif(CMAKE_HOST_UNIX)
+ set(ENABLE_X11 "1")
+ set(AUTO_OS "x11")
+else()
+ message(FATAL_ERROR "OS not supported")
+endif()
+endmacro()
+
+macro(use_protected_as_public_hack)
+# 2017-04-24 The protected hack can unfortunately not be disabled, because
+# Clang does produce linker errors when we disable the hack.
+# But the ugly workaround in Python is replaced by a shiboken change.
+if(WIN32 OR DEFINED AVOID_PROTECTED_HACK)
+ message(STATUS "PySide2 will be generated avoiding the protected hack!")
+ set(GENERATOR_EXTRA_FLAGS ${GENERATOR_EXTRA_FLAGS} --avoid-protected-hack)
+ add_definitions(-DAVOID_PROTECTED_HACK)
+else()
+ message(STATUS "PySide will be generated using the protected hack!")
+endif()
+endmacro()
+
+macro(remove_skipped_modules)
+# Removing from the MODULES list the items that were defined with
+# -DSKIP_MODULES on command line
+if (SKIP_MODULES)
+ foreach(s ${SKIP_MODULES})
+ list(REMOVE_ITEM MODULES ${s})
+ endforeach()
+endif()
+
+foreach(m ${MODULES})
+ COLLECT_MODULE_IF_FOUND(${m})
+ list(FIND all_module_shortnames ${m} is_module_collected)
+ # If the module was collected, remove it from disabled modules list.
+ if (NOT is_module_collected EQUAL -1)
+ list(REMOVE_ITEM DISABLED_MODULES ${m})
+ endif()
+endforeach()
+endmacro()
+
+macro(COLLECT_MODULE_IF_FOUND shortname)
+ set(name "Qt5${shortname}")
+ set(_qt_module_name "${name}")
+ if ("${shortname}" STREQUAL "OpenGLFunctions")
+ set(_qt_module_name "Qt5Gui")
+ endif()
+ # Determine essential/optional/missing
+ set(module_state "missing")
+ list(FIND ALL_ESSENTIAL_MODULES "${shortname}" essentialIndex)
+ if(${essentialIndex} EQUAL -1)
+ list(FIND ALL_OPTIONAL_MODULES "${shortname}" optionalIndex)
+ if(NOT ${optionalIndex} EQUAL -1)
+ set(module_state "optional")
+ endif()
+ else()
+ set(module_state "essential")
+ endif()
+
+ # Silence warnings when optional packages are not found when doing a quiet build.
+ set(quiet_argument "")
+ if (QUIET_BUILD AND "${module_state}" STREQUAL "optional")
+ set(quiet_argument "QUIET")
+ endif()
+
+ find_package(${_qt_module_name} ${quiet_argument})
+ # If package is found, _name_found will be equal to 1
+ set(_name_found "${_qt_module_name}_FOUND")
+ # _name_dir will keep the path to the directory where the CMake rules were found
+ # e.g: ~/qt5.9-install/qtbase/lib/cmake/Qt5Core or /usr/lib64/cmake/Qt5Core
+ set(_name_dir "${_qt_module_name}_DIR")
+ # Qt5Core will set the base path to check if all the modules are on the same
+ # directory, to avoid CMake looking in another path.
+ # This will be saved in a global variable at the beginning of the modules
+ # collection process.
+ string(FIND "${name}" "Qt5Core" qtcore_found)
+ if(("${qtcore_found}" GREATER "0") OR ("${qtcore_found}" EQUAL "0"))
+ get_filename_component(_core_abs_dir "${${_name_dir}}/../" ABSOLUTE)
+ # Setting the absolute path where the Qt5Core was found
+ # e.g: ~/qt5.9-install/qtbase/lib/cmake or /usr/lib64/cmake
+ message(STATUS "CORE_ABS_DIR:" ${_core_abs_dir})
+ endif()
+
+ # Getting the absolute path for each module where the CMake was found, to
+ # compare it with CORE_ABS_DIR and check if they are in the same source directory
+ # e.g: ~/qt5.9-install/qtbase/lib/cmake/Qt5Script or /usr/lib64/cmake/Qt5Script
+ get_filename_component(_module_dir "${${_name_dir}}" ABSOLUTE)
+ string(FIND "${_module_dir}" "${_core_abs_dir}" found_basepath)
+
+ # If the module was found, and also the module path is the same as the
+ # Qt5Core base path, we will generate the list with the modules to be installed
+ set(looked_in_message ". Looked in: ${${_name_dir}}")
+ if("${${_name_found}}" AND (("${found_basepath}" GREATER "0") OR ("${found_basepath}" EQUAL "0")))
+ message(STATUS "${module_state} module ${name} found (${ARGN})${looked_in_message}")
+ # record the shortnames for the tests
+ list(APPEND all_module_shortnames ${shortname})
+ else()
+ if("${module_state}" STREQUAL "optional")
+ message(STATUS "optional module ${name} skipped${looked_in_message}")
+ elseif("${module_state}" STREQUAL "essential")
+ message(STATUS "skipped module ${name} is essential!\n"
+ " We do not guarantee that all tests are working.${looked_in_message}")
+ else()
+ message(FATAL_ERROR "module ${name} MISSING${looked_in_message}")
+ endif()
+ endif()
+endmacro()
+
macro(compute_config_py_values
full_version_var_name
)
diff --git a/sources/pyside2/CMakeLists.txt b/sources/pyside2/CMakeLists.txt
index c5dbc623c..16038594a 100644
--- a/sources/pyside2/CMakeLists.txt
+++ b/sources/pyside2/CMakeLists.txt
@@ -9,8 +9,10 @@ cmake_policy(SET CMP0046 NEW)
project(pysidebindings)
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../cmake_helpers/
+ ${CMAKE_CURRENT_SOURCE_DIR}/../shiboken2/data/
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Macros/
${CMAKE_MODULE_PATH})
+include(shiboken_helpers)
include(helpers)
# Don't display "up-to-date / install" messages when installing, to reduce visual clutter.
@@ -128,31 +130,8 @@ if (QtCore_is_framework)
get_filename_component(QT_INCLUDE_DIR "${QT_INCLUDE_DIR}/../../include" ABSOLUTE)
endif()
-if(MSVC)
- # Qt5: this flag has changed from /Zc:wchar_t- in Qt4.X
- set(CMAKE_CXX_FLAGS "/Zc:wchar_t /GR /EHsc /DNOCOLOR /DWIN32 /D_WINDOWS /D_SCL_SECURE_NO_WARNINGS") # XXX
-else()
- if(CMAKE_HOST_UNIX AND NOT CYGWIN)
- 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_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()
+set_cmake_cxx_flags()
- if(CMAKE_HOST_APPLE)
- # ALTERNATIVE_QT_INCLUDE_DIR is deprecated, because CMake takes care of finding the proper
- # include folders using the qmake found in the environment. Only use it for now in case
- # something goes wrong with the cmake process.
- if(ALTERNATIVE_QT_INCLUDE_DIR AND NOT QT_INCLUDE_DIR)
- set(QT_INCLUDE_DIR ${ALTERNATIVE_QT_INCLUDE_DIR})
- endif()
- endif()
-endif()
message(STATUS "*** computed QT_INCLUDE_DIR as ${QT_INCLUDE_DIR}")
set(BINDING_NAME PySide2)
@@ -171,111 +150,13 @@ compute_config_py_values(BINDING_API_VERSION)
include(PySideModules)
-macro(COLLECT_MODULE_IF_FOUND shortname)
- set(name "Qt5${shortname}")
- set(_qt_module_name "${name}")
- if ("${shortname}" STREQUAL "OpenGLFunctions")
- set(_qt_module_name "Qt5Gui")
- endif()
- # Determine essential/optional/missing
- set(module_state "missing")
- list(FIND ALL_ESSENTIAL_MODULES "${shortname}" essentialIndex)
- if(${essentialIndex} EQUAL -1)
- list(FIND ALL_OPTIONAL_MODULES "${shortname}" optionalIndex)
- if(NOT ${optionalIndex} EQUAL -1)
- set(module_state "optional")
- endif()
- else()
- set(module_state "essential")
- endif()
-
- # Silence warnings when optional packages are not found when doing a quiet build.
- set(quiet_argument "")
- if (QUIET_BUILD AND "${module_state}" STREQUAL "optional")
- set(quiet_argument "QUIET")
- endif()
-
- find_package(${_qt_module_name} ${quiet_argument})
- # If package is found, _name_found will be equal to 1
- set(_name_found "${_qt_module_name}_FOUND")
- # _name_dir will keep the path to the directory where the CMake rules were found
- # e.g: ~/qt5.9-install/qtbase/lib/cmake/Qt5Core or /usr/lib64/cmake/Qt5Core
- set(_name_dir "${_qt_module_name}_DIR")
- # Qt5Core will set the base path to check if all the modules are on the same
- # directory, to avoid CMake looking in another path.
- # This will be saved in a global variable at the beginning of the modules
- # collection process.
- string(FIND "${name}" "Qt5Core" qtcore_found)
- if(("${qtcore_found}" GREATER "0") OR ("${qtcore_found}" EQUAL "0"))
- get_filename_component(_core_abs_dir "${${_name_dir}}/../" ABSOLUTE)
- # Setting the absolute path where the Qt5Core was found
- # e.g: ~/qt5.9-install/qtbase/lib/cmake or /usr/lib64/cmake
- message(STATUS "CORE_ABS_DIR:" ${_core_abs_dir})
- endif()
-
- # Getting the absolute path for each module where the CMake was found, to
- # compare it with CORE_ABS_DIR and check if they are in the same source directory
- # e.g: ~/qt5.9-install/qtbase/lib/cmake/Qt5Script or /usr/lib64/cmake/Qt5Script
- get_filename_component(_module_dir "${${_name_dir}}" ABSOLUTE)
- string(FIND "${_module_dir}" "${_core_abs_dir}" found_basepath)
-
- # If the module was found, and also the module path is the same as the
- # Qt5Core base path, we will generate the list with the modules to be installed
- set(looked_in_message ". Looked in: ${${_name_dir}}")
- if("${${_name_found}}" AND (("${found_basepath}" GREATER "0") OR ("${found_basepath}" EQUAL "0")))
- message(STATUS "${module_state} module ${name} found (${ARGN})${looked_in_message}")
- # record the shortnames for the tests
- list(APPEND all_module_shortnames ${shortname})
- else()
- if("${module_state}" STREQUAL "optional")
- message(STATUS "optional module ${name} skipped${looked_in_message}")
- elseif("${module_state}" STREQUAL "essential")
- message(STATUS "skipped module ${name} is essential!\n"
- " We do not guarantee that all tests are working.${looked_in_message}")
- else()
- message(FATAL_ERROR "module ${name} MISSING${looked_in_message}")
- endif()
- endif()
-endmacro()
-
# Set default values for pyside2_global.h
set (Qt5X11Extras_FOUND "0")
set (Qt5Test_FOUND "0")
set (Qt5Widgets_FOUND "0")
-# Collect all essential modules.
-# note: the order of this list is relevant for dependencies.
-# For instance: Qt5Printsupport must come before Qt5WebKitWidgets.
-set(ALL_ESSENTIAL_MODULES Core Gui Widgets PrintSupport Sql Network Test Concurrent)
-if(UNIX AND NOT APPLE)
- list(APPEND ALL_ESSENTIAL_MODULES X11Extras)
-endif()
-if(WIN32)
- list(APPEND ALL_ESSENTIAL_MODULES WinExtras)
-endif()
-if(APPLE)
- list(APPEND ALL_ESSENTIAL_MODULES MacExtras)
-endif()
-
-# Collect all optional modules.
-set(ALL_OPTIONAL_MODULES Xml XmlPatterns Help Multimedia
-MultimediaWidgets OpenGL OpenGLFunctions Positioning Location Qml Quick QuickWidgets RemoteObjects Scxml Script ScriptTools Sensors TextToSpeech Charts Svg DataVisualization)
-find_package(Qt5UiTools)
-if(Qt5UiTools_FOUND)
- list(APPEND ALL_OPTIONAL_MODULES UiTools)
-else()
- set(DISABLE_QtUiTools 1)
-endif()
-if(WIN32)
- list(APPEND ALL_OPTIONAL_MODULES AxContainer)
-endif()
-# Disabling WebKit by default
-# If WebKit support is needed add the following elements
-# to the list: WebKit WebKitWidgets
-list(APPEND ALL_OPTIONAL_MODULES WebChannel WebEngineCore WebEngine WebEngineWidgets WebSockets)
-if (Qt5Core_VERSION VERSION_GREATER 5.9.3) # Depending on fixes in Qt3D
- list(APPEND ALL_OPTIONAL_MODULES 3DCore 3DRender 3DInput 3DLogic 3DAnimation 3DExtras)
-endif()
+collect_essential_modules()
+collect_optional_modules()
# Modules to be built unless specified by -DMODULES on command line
if (NOT MODULES)
@@ -285,22 +166,7 @@ endif()
# This will contain the set of modules for which bindings are not built.
set(DISABLED_MODULES "${ALL_ESSENTIAL_MODULES};${ALL_OPTIONAL_MODULES}")
-# Removing from the MODULES list the items that were defined with
-# -DSKIP_MODULES on command line
-if (SKIP_MODULES)
- foreach(s ${SKIP_MODULES})
- list(REMOVE_ITEM MODULES ${s})
- endforeach()
-endif()
-
-foreach(m ${MODULES})
- COLLECT_MODULE_IF_FOUND(${m})
- list(FIND all_module_shortnames ${m} is_module_collected)
- # If the module was collected, remove it from disabled modules list.
- if (NOT is_module_collected EQUAL -1)
- list(REMOVE_ITEM DISABLED_MODULES ${m})
- endif()
-endforeach()
+remove_skipped_modules()
# Mark all non-collected modules as disabled. This is used for disabling tests
# that depend on the disabled modules.
@@ -323,24 +189,7 @@ endif()
# no more supported: include(${QT_USE_FILE})
# Configure OS support
-set(ENABLE_X11 "0")
-set(ENABLE_MAC "0")
-set(ENABLE_WIN "0")
-set(ENABLE_SIMULATOR "0")
-
-# no more Maemo, no more simulator
-if(CMAKE_HOST_APPLE)
- set(ENABLE_MAC "1")
- set(AUTO_OS "mac")
-elseif(CMAKE_HOST_WIN32)
- set(ENABLE_WIN "1")
- set(AUTO_OS "win")
-elseif(CMAKE_HOST_UNIX)
- set(ENABLE_X11 "1")
- set(AUTO_OS "x11")
-else()
- message(FATAL_ERROR "OS not supported")
-endif()
+check_os()
message(STATUS "Detected OS: ${AUTO_OS}")
# Define supported Qt Version
@@ -379,33 +228,17 @@ set(GENERATOR_EXTRA_FLAGS --generator-set=shiboken
--enable-pyside-extensions
--enable-return-value-heuristic
--use-isnull-as-nb_nonzero)
-# 2017-04-24 The protected hack can unfortunately not be disabled, because
-# Clang does produce linker errors when we disable the hack.
-# But the ugly workaround in Python is replaced by a shiboken change.
-if(WIN32 OR DEFINED AVOID_PROTECTED_HACK)
- message(STATUS "PySide2 will be generated avoiding the protected hack!")
- set(GENERATOR_EXTRA_FLAGS ${GENERATOR_EXTRA_FLAGS} --avoid-protected-hack)
- add_definitions(-DAVOID_PROTECTED_HACK)
-else()
- message(STATUS "PySide will be generated using the protected hack!")
-endif()
+use_protected_as_public_hack()
# Build with Address sanitizer enabled if requested. This may break things, so use at your own risk.
if (SANITIZE_ADDRESS AND NOT MSVC)
- # Currently this does not check that the clang / gcc version used supports Address sanitizer,
- # so once again, use at your own risk.
- add_compile_options("-fsanitize=address" "-g" "-fno-omit-frame-pointer")
- # We need to add the sanitize address option to all linked executables / shared libraries
- # so that proper sanitizer symbols are linked in.
- #
- # Note that when running tests, you may need to set an additional environment variable
- # in set_tests_properties for shiboken2 / pyside tests, or exported in your shell. Address
- # sanitizer will tell you what environment variable needs to be exported. For example:
- # export DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Toolchains/
- # ./XcodeDefault.xctoolchain/usr/lib/clang/8.1.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
- set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_STANDARD_LIBRARIES} -fsanitize=address")
+ setup_sanitize_address()
endif()
+#####################################################################
+# Adding sub-directories to build
+#####################################################################
+
add_subdirectory(libpyside)
find_package(Qt5Designer)
if(Qt5UiTools_FOUND AND Qt5Designer_FOUND)
diff --git a/sources/shiboken2/ApiExtractor/CMakeLists.txt b/sources/shiboken2/ApiExtractor/CMakeLists.txt
index c8a5fb336..c2a4c208e 100644
--- a/sources/shiboken2/ApiExtractor/CMakeLists.txt
+++ b/sources/shiboken2/ApiExtractor/CMakeLists.txt
@@ -30,6 +30,22 @@ parser/enumvalue.cpp
xmlutils.cpp
)
+find_package(Qt5XmlPatterns 5.12)
+find_package(Qt5Xml 5.12)
+find_package(LibXml2 2.6.32)
+find_package(LibXslt 1.1.19)
+
+set(HAS_LIBXSLT 0)
+if (LIBXSLT_FOUND AND LIBXML2_FOUND)
+ set(HAS_LIBXSLT 1)
+endif()
+
+if(NOT Qt5XmlPatterns_FOUND AND NOT HAS_LIBXSLT)
+ set(DISABLE_DOCSTRINGS TRUE)
+ message(WARNING
+ "Documentation will not be built due to missing dependency (no Qt5XmlPatterns found).")
+endif()
+
add_library(apiextractor STATIC ${apiextractor_SRC})
target_include_directories(apiextractor PRIVATE ${CLANG_EXTRA_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR}
@@ -68,6 +84,7 @@ target_compile_definitions(apiextractor PRIVATE CMAKE_CXX_COMPILER="${CMAKE_CXX_
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 (BUILD_TESTS)
+ find_package(Qt5Test 5.12 REQUIRED)
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/tests)
enable_testing()
add_subdirectory(tests)
diff --git a/sources/shiboken2/CMakeLists.txt b/sources/shiboken2/CMakeLists.txt
index be1b4cd7f..c1349cae6 100644
--- a/sources/shiboken2/CMakeLists.txt
+++ b/sources/shiboken2/CMakeLists.txt
@@ -19,42 +19,9 @@ option(USE_PYTHON_VERSION "Use specific python version to build shiboken2." "")
option(DISABLE_DOCSTRINGS "Disable documentation extraction." FALSE)
find_package(Qt5 5.12 REQUIRED COMPONENTS Core)
-find_package(Qt5Xml 5.12)
-find_package(Qt5XmlPatterns 5.12)
-find_package(LibXml2 2.6.32)
-find_package(LibXslt 1.1.19)
-if(BUILD_TESTS)
- find_package(Qt5Test 5.12 REQUIRED)
-endif()
-
-set(HAS_LIBXSLT 0)
-if (LIBXSLT_FOUND AND LIBXML2_FOUND)
- set(HAS_LIBXSLT 1)
-endif()
-
-if(NOT Qt5XmlPatterns_FOUND AND NOT HAS_LIBXSLT)
- set(DISABLE_DOCSTRINGS TRUE)
- message(WARNING
- "Documentation will not be built due to missing dependency (no Qt5XmlPatterns found).")
-endif()
-
-# Don't display "up-to-date / install" messages when installing, to reduce visual clutter.
-if (QUIET_BUILD)
- set(CMAKE_INSTALL_MESSAGE NEVER)
-endif()
-# Override message not to display info messages when doing a quiet build.
if (QUIET_BUILD)
- function(message)
- list(GET ARGV 0 MessageType)
- if (MessageType STREQUAL FATAL_ERROR OR
- MessageType STREQUAL SEND_ERROR OR
- MessageType STREQUAL WARNING OR
- MessageType STREQUAL AUTHOR_WARNING)
- list(REMOVE_AT ARGV 0)
- _message(${MessageType} "${ARGV}")
- endif()
- endfunction()
+ set_quiet_build()
endif()
if (USE_PYTHON_VERSION)
@@ -63,115 +30,11 @@ else()
shiboken_find_required_python()
endif()
-macro(get_python_arch)
- execute_process(
- COMMAND ${PYTHON_EXECUTABLE} -c "if True:
- import sys
- print('64' if sys.maxsize > 2**31-1 else '32')
- "
- OUTPUT_VARIABLE PYTHON_ARCH
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- message("PYTHON_ARCH: " ${PYTHON_ARCH})
-endmacro()
-
if (NOT PYTHON_ARCH)
get_python_arch()
endif()
-macro(get_llvm_config)
- execute_process(
- COMMAND ${PYTHON_EXECUTABLE} -c "if True:
- import os
- import sys
- sys.path.append(os.path.realpath(os.path.join('${CMAKE_CURRENT_LIST_DIR}', '..', '..')))
- from build_scripts.utils import find_llvm_config
- llvmConfig = find_llvm_config()
- if llvmConfig:
- print(llvmConfig)
- "
- OUTPUT_VARIABLE LLVM_CONFIG
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- message("LLVM_CONFIG: " ${LLVM_CONFIG})
-endmacro()
-
-set(CLANG_DIR "")
-set(CLANG_DIR_SOURCE "")
-
-set(clang_not_found_message "Unable to detect CLANG location by checking LLVM_INSTALL_DIR, \
- CLANG_INSTALL_DIR or running llvm-config.")
-
-if (DEFINED ENV{LLVM_INSTALL_DIR})
- set(CLANG_DIR $ENV{LLVM_INSTALL_DIR})
- string(REPLACE "_ARCH_" "${PYTHON_ARCH}" CLANG_DIR "${CLANG_DIR}")
- set(CLANG_DIR_SOURCE "LLVM_INSTALL_DIR")
-elseif (DEFINED ENV{CLANG_INSTALL_DIR})
- set(CLANG_DIR $ENV{CLANG_INSTALL_DIR})
- string(REPLACE "_ARCH_" "${PYTHON_ARCH}" CLANG_DIR "${CLANG_DIR}")
- set(CLANG_DIR_SOURCE "CLANG_INSTALL_DIR")
-else ()
- if (NOT LLVM_CONFIG)
- get_llvm_config()
- endif()
- set(CLANG_DIR_SOURCE "${LLVM_CONFIG}")
- if ("${CLANG_DIR_SOURCE}" STREQUAL "")
- message(FATAL_ERROR "${clang_not_found_message}")
- endif()
-
- EXEC_PROGRAM("${LLVM_CONFIG}" ARGS "--prefix" OUTPUT_VARIABLE CLANG_DIR)
- 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 "libclang version 3.9 or higher is required (${LLVM_CONFIG} detected ${CLANG_VERSION} at ${CLANG_DIR}).")
- endif()
- endif()
-endif()
-
-if ("${CLANG_DIR}" STREQUAL "")
- message(FATAL_ERROR "${clang_not_found_message}")
-elseif (NOT IS_DIRECTORY ${CLANG_DIR})
- message(FATAL_ERROR "${CLANG_DIR} detected by ${CLANG_DIR_SOURCE} does not exist.")
-endif()
-
-# The non-development Debian / Ubuntu packages (e.g. libclang1-6.0) do not ship a
-# libclang.so symlink, but only libclang-6.0.so.1 and libclang.so.1 (adjusted for version number).
-# Thus searching for libclang would not succeed.
-# The "libclang.so" symlink is shipped as part of the development package (libclang-6.0-dev) which
-# we need anyway because of the headers. Thus we will search for libclang.so.1 also, and complain
-# about the headers not being found in a check further down. This is more friendly to the user,
-# so they don't scratch their head thinking that they have already installed the necessary package.
-set(CLANG_LIB_NAMES clang libclang.so libclang.so.1)
-if(MSVC)
- set(CLANG_LIB_NAMES libclang)
-endif()
-
-find_library(CLANG_LIBRARY NAMES ${CLANG_LIB_NAMES} HINTS ${CLANG_DIR}/lib)
-if (NOT EXISTS ${CLANG_LIBRARY})
- string(REPLACE ";" ", " CLANG_LIB_NAMES_STRING "${CLANG_LIB_NAMES}")
- message(FATAL_ERROR "Unable to find the Clang library in ${CLANG_DIR}.\
- Names tried: ${CLANG_LIB_NAMES_STRING}.")
-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})
-
-# Check if one of the required clang headers is found. Error out early at CMake time instead of
-# compile time if not found.
-# It can happen that a user uses a distro-provided libclang.so, but no development header package
-# was installed (e.g. libclang-6.0-dev on Ubuntu).
-set(CMAKE_REQUIRED_INCLUDES ${CLANG_EXTRA_INCLUDES})
-set(CLANG_HEADER_FILE_TO_CHECK "clang-c/Index.h")
-check_include_file_cxx(${CLANG_HEADER_FILE_TO_CHECK} CLANG_INCLUDE_FOUND)
-unset(CMAKE_REQUIRED_INCLUDES)
-if (NOT CLANG_INCLUDE_FOUND)
- # Need to unset so that when installing the package, CMake doesn't complain that the header
- # still isn't found.
- unset(CLANG_INCLUDE_FOUND CACHE)
- message(FATAL_ERROR "Unable to find required Clang header file ${CLANG_HEADER_FILE_TO_CHECK} \
- in ${CLANG_DIR}/include. Perhaps you forgot to install the clang development header \
- package? (e.g. libclang-6.0-dev)")
-endif()
+setup_clang()
set(SHIBOKEN_VERSION_FILE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/shiboken_version.py")
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
@@ -209,29 +72,6 @@ message("PYTHONINTERP_FOUND: " ${PYTHONINTERP_FOUND})
message("PYTHON_EXECUTABLE: " ${PYTHON_EXECUTABLE})
message("PYTHON_VERSION: " ${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}.${PYTHON_VERSION_PATCH})
-macro(get_python_extension_suffix)
- # Result of imp.get_suffixes() depends on the platform, but generally looks something like:
- # [('.cpython-34m-x86_64-linux-gnu.so', 'rb', 3), ('.cpython-34m.so', 'rb', 3),
- # ('.abi3.so', 'rb', 3), ('.so', 'rb', 3), ('.py', 'r', 1), ('.pyc', 'rb', 2)]
- # We pick the first most detailed one, strip of the file extension part.
-
- execute_process(
- COMMAND ${PYTHON_EXECUTABLE} -c "if True:
- import imp, re
- first_suffix = imp.get_suffixes()[0][0]
- res = re.search(r'^(.+)\\.', first_suffix)
- if res:
- first_suffix = res.group(1)
- else:
- first_suffix = ''
- print(first_suffix)
- "
- OUTPUT_VARIABLE PYTHON_EXTENSION_SUFFIX
- OUTPUT_STRIP_TRAILING_WHITESPACE)
- message("PYTHON_EXTENSION_SUFFIX: " ${PYTHON_EXTENSION_SUFFIX})
-endmacro()
-
-
if (NOT PYTHON_EXTENSION_SUFFIX)
get_python_extension_suffix()
endif()
@@ -242,42 +82,15 @@ set(PYTHON_LIMITED_API 0)
shiboken_check_if_limited_api()
if (PYTHON_LIMITED_API)
- if (WIN32 AND NOT EXISTS "${PYTHON_LIMITED_LIBRARIES}")
- message(FATAL_ERROR "The Limited API was enabled, but ${PYTHON_LIMITED_LIBRARIES} was not found!")
- endif()
- message(STATUS "******************************************************")
- message(STATUS "** Limited API enabled ${PYTHON_LIMITED_LIBRARIES}")
- message(STATUS "******************************************************")
+ set_limited_api()
endif()
if (NOT PYTHON_CONFIG_SUFFIX)
- if (PYTHON_VERSION_MAJOR EQUAL 2)
- set(PYTHON_CONFIG_SUFFIX "-python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
- if (PYTHON_EXTENSION_SUFFIX)
- set(PYTHON_CONFIG_SUFFIX "${PYTHON_CONFIG_SUFFIX}${PYTHON_EXTENSION_SUFFIX}")
- endif()
- elseif (PYTHON_VERSION_MAJOR EQUAL 3)
- if (PYTHON_LIMITED_API)
- if(WIN32)
- set(PYTHON_EXTENSION_SUFFIX "")
- else()
- set(PYTHON_EXTENSION_SUFFIX ".abi3")
- endif()
- set(PYTHON_CONFIG_SUFFIX ".abi3")
- else()
- set(PYTHON_CONFIG_SUFFIX "${PYTHON_EXTENSION_SUFFIX}")
- endif()
- endif()
+ set_python_config_suffix()
endif()
if (NOT PYTHON_SHARED_LIBRARY_SUFFIX)
- set(PYTHON_SHARED_LIBRARY_SUFFIX "${PYTHON_CONFIG_SUFFIX}")
-
- # Append a "v" to disambiguate the python version and the shiboken version in the
- # shared library file name.
- if (APPLE AND PYTHON_VERSION_MAJOR EQUAL 2)
- set(PYTHON_SHARED_LIBRARY_SUFFIX "${PYTHON_SHARED_LIBRARY_SUFFIX}v")
- endif()
+ set_python_shared_library_suffix()
endif()
if (NOT PYTHON_CONFIG_SUFFIX)
@@ -291,39 +104,10 @@ message(STATUS "PYTHON_SHARED_LIBRARY_SUFFIX: ${PYTHON_SHARED_LIBRARY_SUFFIX}")
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_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()
+ set_python_site_packages()
endif()
+set_cmake_cxx_flags()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D QT_NO_CAST_FROM_ASCII -D QT_NO_CAST_TO_ASCII")
# Force usage of the C++11 standard, without a silent fallback
@@ -332,8 +116,10 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(LIB_SUFFIX "" CACHE STRING "Define suffix of directory name (32/64)" )
-set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE)
-set(BIN_INSTALL_DIR "bin" CACHE PATH "The subdirectory relative to the install prefix where dlls will be installed (default is /bin)" FORCE)
+set(LIB_INSTALL_DIR "lib${LIB_SUFFIX}" CACHE PATH "The subdirectory relative to the install \
+ prefix where libraries will be installed (default is /lib${LIB_SUFFIX})" FORCE)
+set(BIN_INSTALL_DIR "bin" CACHE PATH "The subdirectory relative to the install prefix where \
+ dlls will be installed (default is /bin)" FORCE)
if (WIN32)
set(PATH_SEP "\;")
@@ -342,26 +128,17 @@ else()
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.")
+ 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()
-# Build with Address sanitizer enabled if requested. This may break things, so use at your own risk.
+# Build with Address sanitizer enabled if requested.
+# This may break things, so use at your own risk.
if (SANITIZE_ADDRESS AND NOT MSVC)
- # Currently this does not check that the clang / gcc version used supports Address sanitizer,
- # so once again, use at your own risk.
- add_compile_options("-fsanitize=address" "-g" "-fno-omit-frame-pointer")
- # We need to add the sanitize address option to all linked executables / shared libraries
- # so that proper sanitizer symbols are linked in.
- #
- # Note that when running tests, you may need to set an additional environment variable
- # in set_tests_properties for shiboken2 / pyside tests, or exported in your shell. Address
- # sanitizer will tell you what environment variable needs to be exported. For example:
- # export DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Toolchains/
- # ./XcodeDefault.xctoolchain/usr/lib/clang/8.1.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
- set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_STANDARD_LIBRARIES} -fsanitize=address")
+ set_sanitize_address()
endif()
# Detect if the python libs were compiled in debug mode
@@ -410,23 +187,12 @@ execute_process(
set(SHIBOKEN_BUILD_TYPE "${CMAKE_BUILD_TYPE}")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
- set(SHIBOKEN_BUILD_TYPE "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()
- set(SBK_PKG_CONFIG_PY_DEBUG_DEFINITION " -DPy_DEBUG")
- endif()
-
- if (PYTHON_WITH_COUNT_ALLOCS)
- set(SBK_PKG_CONFIG_PY_DEBUG_DEFINITION "${SBK_PKG_CONFIG_PY_DEBUG_DEFINITION} -DCOUNT_ALLOCS")
- endif()
+ set_debug_build()
endif()
+######################################################################
+# Adding sub directories to build
+######################################################################
add_subdirectory(ApiExtractor)
set(generator_plugin_DIR ${LIB_INSTALL_DIR}/generatorrunner${generator_SUFFIX})
@@ -451,7 +217,7 @@ if (Qt5Core_FOUND AND PYTHONINTERP_FOUND)
add_subdirectory(tests)
endif()
else()
- message(WARNING "Some dependencies were not found, shiboken2 generator compilation disabled!")
+ message(WARNING "Some dependencies were not found: shiboken2 generator compilation disabled!")
endif()
add_subdirectory(data)
diff --git a/sources/shiboken2/data/shiboken_helpers.cmake b/sources/shiboken2/data/shiboken_helpers.cmake
index f4dd4d5dc..8111fa61f 100644
--- a/sources/shiboken2/data/shiboken_helpers.cmake
+++ b/sources/shiboken2/data/shiboken_helpers.cmake
@@ -1,5 +1,274 @@
include(CMakeParseArguments)
+macro(set_python_shared_library_suffix)
+ set(PYTHON_SHARED_LIBRARY_SUFFIX "${PYTHON_CONFIG_SUFFIX}")
+
+ # Append a "v" to disambiguate the python version and the shiboken version in the
+ # shared library file name.
+ if (APPLE AND PYTHON_VERSION_MAJOR EQUAL 2)
+ set(PYTHON_SHARED_LIBRARY_SUFFIX "${PYTHON_SHARED_LIBRARY_SUFFIX}v")
+ endif()
+endmacro()
+
+macro(set_limited_api)
+ if (WIN32 AND NOT EXISTS "${PYTHON_LIMITED_LIBRARIES}")
+ message(FATAL_ERROR "The Limited API was enabled, but ${PYTHON_LIMITED_LIBRARIES} was not found!")
+ endif()
+ message(STATUS "******************************************************")
+ message(STATUS "** Limited API enabled ${PYTHON_LIMITED_LIBRARIES}")
+ message(STATUS "******************************************************")
+endmacro()
+
+macro(set_debug_build)
+ set(SHIBOKEN_BUILD_TYPE "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()
+ set(SBK_PKG_CONFIG_PY_DEBUG_DEFINITION " -DPy_DEBUG")
+ endif()
+
+ if (PYTHON_WITH_COUNT_ALLOCS)
+ set(SBK_PKG_CONFIG_PY_DEBUG_DEFINITION "${SBK_PKG_CONFIG_PY_DEBUG_DEFINITION} -DCOUNT_ALLOCS")
+ endif()
+endmacro()
+
+macro(setup_sanitize_address)
+ # Currently this does not check that the clang / gcc version used supports Address sanitizer,
+ # so once again, use at your own risk.
+ add_compile_options("-fsanitize=address" "-g" "-fno-omit-frame-pointer")
+ # We need to add the sanitize address option to all linked executables / shared libraries
+ # so that proper sanitizer symbols are linked in.
+ #
+ # Note that when running tests, you may need to set an additional environment variable
+ # in set_tests_properties for shiboken2 / pyside tests, or exported in your shell. Address
+ # sanitizer will tell you what environment variable needs to be exported. For example:
+ # export DYLD_INSERT_LIBRARIES=/Applications/Xcode.app/Contents/Developer/Toolchains/
+ # ./XcodeDefault.xctoolchain/usr/lib/clang/8.1.0/lib/darwin/libclang_rt.asan_osx_dynamic.dylib
+ set(CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_STANDARD_LIBRARIES} -fsanitize=address")
+endmacro()
+
+macro(set_cmake_cxx_flags)
+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")
+ #set(CMAKE_CXX_FLAGS "/Zc:wchar_t /GR /EHsc /DNOCOLOR /DWIN32 /D_WINDOWS /D_SCL_SECURE_NO_WARNINGS") # XXX
+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_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()
+ if(CMAKE_HOST_APPLE)
+ # ALTERNATIVE_QT_INCLUDE_DIR is deprecated, because CMake takes care of finding the proper
+ # include folders using the qmake found in the environment. Only use it for now in case
+ # something goes wrong with the cmake process.
+ if(ALTERNATIVE_QT_INCLUDE_DIR AND NOT QT_INCLUDE_DIR)
+ set(QT_INCLUDE_DIR ${ALTERNATIVE_QT_INCLUDE_DIR})
+ endif()
+ endif()
+endif()
+
+endmacro()
+
+macro(set_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()
+endmacro()
+
+macro(set_python_config_suffix)
+ if (PYTHON_VERSION_MAJOR EQUAL 2)
+ set(PYTHON_CONFIG_SUFFIX "-python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
+ if (PYTHON_EXTENSION_SUFFIX)
+ set(PYTHON_CONFIG_SUFFIX "${PYTHON_CONFIG_SUFFIX}${PYTHON_EXTENSION_SUFFIX}")
+ endif()
+ elseif (PYTHON_VERSION_MAJOR EQUAL 3)
+ if (PYTHON_LIMITED_API)
+ if(WIN32)
+ set(PYTHON_EXTENSION_SUFFIX "")
+ else()
+ set(PYTHON_EXTENSION_SUFFIX ".abi3")
+ endif()
+ set(PYTHON_CONFIG_SUFFIX ".abi3")
+ else()
+ set(PYTHON_CONFIG_SUFFIX "${PYTHON_EXTENSION_SUFFIX}")
+ endif()
+ endif()
+endmacro()
+
+macro(setup_clang)
+ set(CLANG_DIR "")
+ set(CLANG_DIR_SOURCE "")
+
+ set(clang_not_found_message "Unable to detect CLANG location by checking LLVM_INSTALL_DIR, \
+ CLANG_INSTALL_DIR or running llvm-config.")
+
+ if (DEFINED ENV{LLVM_INSTALL_DIR})
+ set(CLANG_DIR $ENV{LLVM_INSTALL_DIR})
+ string(REPLACE "_ARCH_" "${PYTHON_ARCH}" CLANG_DIR "${CLANG_DIR}")
+ set(CLANG_DIR_SOURCE "LLVM_INSTALL_DIR")
+ elseif (DEFINED ENV{CLANG_INSTALL_DIR})
+ set(CLANG_DIR $ENV{CLANG_INSTALL_DIR})
+ string(REPLACE "_ARCH_" "${PYTHON_ARCH}" CLANG_DIR "${CLANG_DIR}")
+ set(CLANG_DIR_SOURCE "CLANG_INSTALL_DIR")
+ else ()
+ if (NOT LLVM_CONFIG)
+ get_llvm_config()
+ endif()
+ set(CLANG_DIR_SOURCE "${LLVM_CONFIG}")
+ if ("${CLANG_DIR_SOURCE}" STREQUAL "")
+ message(FATAL_ERROR "${clang_not_found_message}")
+ endif()
+
+ EXEC_PROGRAM("${LLVM_CONFIG}" ARGS "--prefix" OUTPUT_VARIABLE CLANG_DIR)
+ 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 "libclang version 3.9 or higher is required \
+ (${LLVM_CONFIG} detected ${CLANG_VERSION} at ${CLANG_DIR}).")
+ endif()
+ endif()
+ endif()
+
+ if ("${CLANG_DIR}" STREQUAL "")
+ message(FATAL_ERROR "${clang_not_found_message}")
+ elseif (NOT IS_DIRECTORY ${CLANG_DIR})
+ message(FATAL_ERROR "${CLANG_DIR} detected by ${CLANG_DIR_SOURCE} does not exist.")
+ endif()
+
+ # The non-development Debian / Ubuntu packages (e.g. libclang1-6.0) do not ship a
+ # libclang.so symlink, but only libclang-6.0.so.1 and libclang.so.1 (adjusted for version number).
+ # Thus searching for libclang would not succeed.
+ # The "libclang.so" symlink is shipped as part of the development package (libclang-6.0-dev) which
+ # we need anyway because of the headers. Thus we will search for libclang.so.1 also, and complain
+ # about the headers not being found in a check further down. This is more friendly to the user,
+ # so they don't scratch their head thinking that they have already installed the necessary package.
+ set(CLANG_LIB_NAMES clang libclang.so libclang.so.1)
+ if(MSVC)
+ set(CLANG_LIB_NAMES libclang)
+ endif()
+
+ find_library(CLANG_LIBRARY NAMES ${CLANG_LIB_NAMES} HINTS ${CLANG_DIR}/lib)
+ if (NOT EXISTS ${CLANG_LIBRARY})
+ string(REPLACE ";" ", " CLANG_LIB_NAMES_STRING "${CLANG_LIB_NAMES}")
+ message(FATAL_ERROR "Unable to find the Clang library in ${CLANG_DIR}.\
+ Names tried: ${CLANG_LIB_NAMES_STRING}.")
+ 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})
+
+ # Check if one of the required clang headers is found. Error out early at CMake time instead of
+ # compile time if not found.
+ # It can happen that a user uses a distro-provided libclang.so, but no development header package
+ # was installed (e.g. libclang-6.0-dev on Ubuntu).
+ set(CMAKE_REQUIRED_INCLUDES ${CLANG_EXTRA_INCLUDES})
+ set(CLANG_HEADER_FILE_TO_CHECK "clang-c/Index.h")
+ check_include_file_cxx(${CLANG_HEADER_FILE_TO_CHECK} CLANG_INCLUDE_FOUND)
+ unset(CMAKE_REQUIRED_INCLUDES)
+ if (NOT CLANG_INCLUDE_FOUND)
+ # Need to unset so that when installing the package, CMake doesn't complain that the header
+ # still isn't found.
+ unset(CLANG_INCLUDE_FOUND CACHE)
+ message(FATAL_ERROR "Unable to find required Clang header file ${CLANG_HEADER_FILE_TO_CHECK} \
+ in ${CLANG_DIR}/include. Perhaps you forgot to install the clang development header \
+ package? (e.g. libclang-6.0-dev)")
+ endif()
+endmacro()
+
+macro(set_quiet_build)
+ # Don't display "up-to-date / install" messages when installing, to reduce visual clutter.
+ set(CMAKE_INSTALL_MESSAGE NEVER PARENT_SCOPE)
+ # Override message not to display info messages when doing a quiet build.
+ function(message)
+ list(GET ARGV 0 MessageType)
+ if (MessageType STREQUAL FATAL_ERROR OR
+ MessageType STREQUAL SEND_ERROR OR
+ MessageType STREQUAL WARNING OR
+ MessageType STREQUAL AUTHOR_WARNING)
+ list(REMOVE_AT ARGV 0)
+ _message(${MessageType} "${ARGV}")
+ endif()
+ endfunction()
+endmacro()
+
+macro(get_python_extension_suffix)
+ # Result of imp.get_suffixes() depends on the platform, but generally looks something like:
+ # [('.cpython-34m-x86_64-linux-gnu.so', 'rb', 3), ('.cpython-34m.so', 'rb', 3),
+ # ('.abi3.so', 'rb', 3), ('.so', 'rb', 3), ('.py', 'r', 1), ('.pyc', 'rb', 2)]
+ # We pick the first most detailed one, strip of the file extension part.
+
+ execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -c "if True:
+ import imp, re
+ first_suffix = imp.get_suffixes()[0][0]
+ res = re.search(r'^(.+)\\.', first_suffix)
+ if res:
+ first_suffix = res.group(1)
+ else:
+ first_suffix = ''
+ print(first_suffix)
+ "
+ OUTPUT_VARIABLE PYTHON_EXTENSION_SUFFIX
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ message("PYTHON_EXTENSION_SUFFIX: " ${PYTHON_EXTENSION_SUFFIX})
+endmacro()
+
+macro(get_llvm_config)
+ execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -c "if True:
+ import os
+ import sys
+ sys.path.append(os.path.realpath(os.path.join('${CMAKE_CURRENT_LIST_DIR}', '..', '..')))
+ from build_scripts.utils import find_llvm_config
+ llvmConfig = find_llvm_config()
+ if llvmConfig:
+ print(llvmConfig)
+ "
+ OUTPUT_VARIABLE LLVM_CONFIG
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ message("LLVM_CONFIG: " ${LLVM_CONFIG})
+endmacro()
+
+macro(get_python_arch)
+ execute_process(
+ COMMAND ${PYTHON_EXECUTABLE} -c "if True:
+ import sys
+ print('64' if sys.maxsize > 2**31-1 else '32')
+ "
+ OUTPUT_VARIABLE PYTHON_ARCH
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ message("PYTHON_ARCH: " ${PYTHON_ARCH})
+endmacro()
+
macro(shiboken_parse_all_arguments prefix type flags options multiopts)
cmake_parse_arguments(${prefix} "${flags}" "${options}" "${multiopts}" ${ARGN})
if(DEFINED ${prefix}_UNPARSED_ARGUMENTS)
diff --git a/sources/shiboken2/shibokenmodule/CMakeLists.txt b/sources/shiboken2/shibokenmodule/CMakeLists.txt
index 057a995f8..bbf2677e4 100644
--- a/sources/shiboken2/shibokenmodule/CMakeLists.txt
+++ b/sources/shiboken2/shibokenmodule/CMakeLists.txt
@@ -30,7 +30,6 @@ if(WIN32)
endif()
target_link_libraries(shibokenmodule PUBLIC libshiboken)
-add_dependencies(shibokenmodule shiboken2)
create_generator_target(shibokenmodule)
install(TARGETS shibokenmodule DESTINATION ${PYTHON_SITE_PACKAGES}/shiboken2)
diff --git a/sources/shiboken2/tests/CMakeLists.txt b/sources/shiboken2/tests/CMakeLists.txt
index 085a4344c..464707a9a 100644
--- a/sources/shiboken2/tests/CMakeLists.txt
+++ b/sources/shiboken2/tests/CMakeLists.txt
@@ -1,3 +1,7 @@
+if(BUILD_TESTS)
+ find_package(Qt5Test 5.12 REQUIRED)
+endif()
+
add_subdirectory(libminimal)
if(NOT DEFINED MINIMAL_TESTS)
add_subdirectory(libsample)
@@ -74,24 +78,24 @@ add_subdirectory(dumpcodemodel)
if (NOT APIEXTRACTOR_DOCSTRINGS_DISABLED)
# project(sphinxtabletest)
-#
+#
# # TODO
# set(sphinxtabletest_SRC sphinxtabletest.cpp)
# qt4_automoc(${sphinxtabletest_SRC})
-#
+#
# include_directories(${QT_INCLUDE_DIR}
# ${QT_QTCORE_INCLUDE_DIR}
# ${CMAKE_CURRENT_BINARY_DIR}
# ${qtdoc_generator_SOURCE_DIR})
-#
+#
# add_executable(sphinxtabletest ${sphinxtabletest_SRC})
-#
+#
# target_link_libraries(sphinxtabletest
# ${QT_QTTEST_LIBRARY}
# ${APIEXTRACTOR_LIBRARY}
# qtdoc_generator
# genrunner)
-#
+#
# add_test("sphinxtable" sphinxtabletest)
# if (INSTALL_TESTS)
# install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/sphinxtabletest DESTINATION ${TEST_INSTALL_DIR})