aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2020-09-01 10:25:26 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2020-09-01 14:19:30 +0000
commite44e21f14d8b10b1832c5db5459bf26f287ab6e8 (patch)
tree36fe96342c33da0adc8c55b520154461933fc323
parent33ffeaff9d7ae53493691e61e875dfcc4ab3b19a (diff)
shiboken2: Use the cmake targets provided by LLVM
Rework the CMakeLists to find libclang in a more standardized way, still allowing for using the environment variables. Task-number: PYSIDE-1339 Task-number: PYSIDE-904 Change-Id: I0dd9425a0a9ed082f668bb1bcb09a9278346e528 Reviewed-by: Christian Tismer <tismer@stackless.com>
-rw-r--r--sources/shiboken2/ApiExtractor/CMakeLists.txt4
-rw-r--r--sources/shiboken2/data/shiboken_helpers.cmake91
2 files changed, 16 insertions, 79 deletions
diff --git a/sources/shiboken2/ApiExtractor/CMakeLists.txt b/sources/shiboken2/ApiExtractor/CMakeLists.txt
index 28644fe49..1e135a46e 100644
--- a/sources/shiboken2/ApiExtractor/CMakeLists.txt
+++ b/sources/shiboken2/ApiExtractor/CMakeLists.txt
@@ -51,12 +51,12 @@ endif()
set(DISABLE_DOCSTRINGS ${DISABLE_DOCSTRINGS} PARENT_SCOPE)
add_library(apiextractor STATIC ${apiextractor_SRC})
-target_include_directories(apiextractor PRIVATE ${CLANG_EXTRA_INCLUDES}
+target_include_directories(apiextractor PRIVATE ${CLANG_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/parser)
target_link_libraries(apiextractor PUBLIC Qt${QT_MAJOR_VERSION}::Core)
-target_link_libraries(apiextractor PRIVATE ${CLANG_EXTRA_LIBRARIES})
+target_link_libraries(apiextractor PRIVATE libclang)
if (HAS_LIBXSLT)
target_compile_definitions(apiextractor PUBLIC HAVE_LIBXSLT)
diff --git a/sources/shiboken2/data/shiboken_helpers.cmake b/sources/shiboken2/data/shiboken_helpers.cmake
index 5e0c6ea72..094aef3e9 100644
--- a/sources/shiboken2/data/shiboken_helpers.cmake
+++ b/sources/shiboken2/data/shiboken_helpers.cmake
@@ -123,85 +123,22 @@ macro(set_python_config_suffix)
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)
+ # Find libclang using the environment variables LLVM_INSTALL_DIR,
+ # CLANG_INSTALL_DIR using standard cmake.
+ # Use CLANG_INCLUDE_DIRS and link to libclang.
+ if(DEFINED ENV{LLVM_INSTALL_DIR})
+ list(PREPEND CMAKE_PREFIX_PATH "$ENV{LLVM_INSTALL_DIR}")
+ list(PREPEND CMAKE_FIND_ROOT_PATH "$ENV{LLVM_INSTALL_DIR}")
+ elseif(DEFINED ENV{CLANG_INSTALL_DIR})
+ list(PREPEND CMAKE_PREFIX_PATH "$ENV{CLANG_INSTALL_DIR}")
+ list(PREPEND CMAKE_FIND_ROOT_PATH "$ENV{CLANG_INSTALL_DIR}")
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()
+ find_package(Clang CONFIG REQUIRED)
+ # CLANG_LIBRARY is read out from the cmake cache to deploy libclang
+ get_target_property(CLANG_LIBRARY_NAME libclang IMPORTED_LOCATION_RELEASE)
+ set(CLANG_LIBRARY "${CLANG_LIBRARY_NAME}" CACHE FILEPATH "libclang")
+ message(STATUS "CLANG: ${Clang_DIR}, ${CLANG_LIBRARY} detected")
endmacro()
macro(set_quiet_build)