aboutsummaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2018-05-07 14:18:58 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2018-05-08 08:27:48 +0000
commit91cbb903ac899c9b5ff2184e644c677a56b029db (patch)
treee26d032495cd0aed15ea9cb310738e475fdad427 /sources
parentc2d0e1ac39b7aa96263e9311128eda56fa0f9aa7 (diff)
Improve libclang detection on Linux
This change essentially allows usage of the distro-specific libclang libraries for building shiboken. This required changes to the name of the library that CMake looked for (looking at you Debian). The change also adds an additional compile test to check for the availability of the libclang headers which shiboken uses. This should prevent a failure at build time, and transform it into a nice error message at cmake configure time. Change-Id: I37e019fd5923379436a67d77f92c30efd77620d2 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io> Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources')
-rw-r--r--sources/shiboken2/CMakeLists.txt37
1 files changed, 32 insertions, 5 deletions
diff --git a/sources/shiboken2/CMakeLists.txt b/sources/shiboken2/CMakeLists.txt
index d499ffc22..513c4ed7e 100644
--- a/sources/shiboken2/CMakeLists.txt
+++ b/sources/shiboken2/CMakeLists.txt
@@ -1,5 +1,6 @@
Include(icecc.cmake)
project(shiboken2)
+include(CheckIncludeFileCXX)
cmake_minimum_required(VERSION 3.1)
cmake_policy(VERSION 3.1)
@@ -80,7 +81,7 @@ else ()
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}).")
+ message(FATAL_ERROR "libclang version 3.9 or higher is required (${LLVM_CONFIG} detected ${CLANG_VERSION} at ${CLANG_DIR}).")
endif()
endif()
endif()
@@ -91,14 +92,23 @@ 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")
+# 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_NAME "libclang")
+ set(CLANG_LIB_NAMES libclang)
endif()
-find_library(CLANG_LIBRARY ${CLANG_LIB_NAME} HINTS ${CLANG_DIR}/lib)
+find_library(CLANG_LIBRARY NAMES ${CLANG_LIB_NAMES} HINTS ${CLANG_DIR}/lib)
if (NOT EXISTS ${CLANG_LIBRARY})
- message(FATAL_ERROR "Unable to find Clang library ${CLANG_LIB_NAME} in ${CLANG_DIR}.")
+ 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}")
@@ -127,6 +137,23 @@ message(STATUS "CLANG builtins includes directory chosen: ${CLANG_BUILTIN_INCLUD
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()
+
set(SHIBOKEN_VERSION_FILE_PATH "${CMAKE_SOURCE_DIR}/shiboken_version.py")
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS
${SHIBOKEN_VERSION_FILE_PATH}