aboutsummaryrefslogtreecommitdiffstats
path: root/sources/shiboken2/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'sources/shiboken2/CMakeLists.txt')
-rw-r--r--sources/shiboken2/CMakeLists.txt276
1 files changed, 21 insertions, 255 deletions
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)