Commit e181ec2c authored by Simon Hausmann's avatar Simon Hausmann
Browse files

Port qdoc's libclang detection to the configure system


This is just an initial rough port with a custom config detection. More
things can be refined in the future, for example turning libclang into
a library to be used with QMAKE_USE.

Fixes: QTBUG-72259
Change-Id: Iaf3c42f76b79bdfd07476173c2fd0f4060c11fea
Reviewed-by: default avatarPaul Wicking <paul.wicking@qt.io>
Reviewed-by: default avatarMartin Smith <martin.smith@qt.io>
Showing with 82 additions and 21 deletions
{
"subconfigs": [
"src/qdoc"
]
}
load(qt_find_clang)
load(qt_parts) load(qt_parts)
{
"module": "qdoc",
"tests": {
"libclang": {
"label": "libclang",
"test": "libclang",
"type": "libclang"
}
},
"features": {
"qdoc": {
"label": "QDoc",
"condition": "tests.libclang",
"output": [
"privateFeature",
{ "type": "varAssign", "name": "CLANG_LIBS", "value": "tests.libclang.libs" },
{ "type": "varAssign", "name": "CLANG_INCLUDEPATH", "value": "tests.libclang.includepath" },
{ "type": "varAssign", "name": "CLANG_LIBDIR", "value": "tests.libclang.libdir" },
{ "type": "varAssign", "name": "CLANG_DEFINES", "value": "tests.libclang.defines" },
{ "type": "varAssign", "name": "CLANG_VERSION", "value": "tests.libclang.version" }
]
}
},
"report": [
{
"type": "warning",
"condition": "!features.qdoc",
"message": "QDoc will not be compiled, probably because libclang could not be located. This means that you cannot build the Qt documentation.
Either ensure that llvm-config is in your PATH environment variable, or set LLVM_INSTALL_DIR to the location of your llvm installation.
On Linux systems you may be able to install libclang from a package. On macOS you could use Homebrew's llvm package.
On Windows you need to set LLVM_INSTALL_DIR to the installation path."
}
],
"summary": [
{
"section": "Qt Tools",
"entries": [
"qdoc"
]
}
]
}
config_clang_done: return()
defineReplace(extractVersion) { return($$replace(1, ^(\\d+\\.\\d+\\.\\d+)(svn)?$, \\1)) } defineReplace(extractVersion) { return($$replace(1, ^(\\d+\\.\\d+\\.\\d+)(svn)?$, \\1)) }
defineReplace(extractMajorVersion) { return($$replace(1, ^(\\d+)\\.\\d+\\.\\d+(svn)?$, \\1)) } defineReplace(extractMajorVersion) { return($$replace(1, ^(\\d+)\\.\\d+\\.\\d+(svn)?$, \\1)) }
defineReplace(extractMinorVersion) { return($$replace(1, ^\\d+\\.(\\d+)\\.\\d+(svn)?$, \\1)) } defineReplace(extractMinorVersion) { return($$replace(1, ^\\d+\\.(\\d+)\\.\\d+(svn)?$, \\1)) }
...@@ -39,10 +37,9 @@ defineReplace(findLLVMVersionFromLibDir) { ...@@ -39,10 +37,9 @@ defineReplace(findLLVMVersionFromLibDir) {
return($$candidateVersion) return($$candidateVersion)
} }
isEmpty(QDOC_USE_STATIC_LIBCLANG): QDOC_USE_STATIC_LIBCLANG = $$(QDOC_USE_STATIC_LIBCLANG) defineTest(qtConfTest_libclang) {
cache(QDOC_USE_STATIC_LIBCLANG) isEmpty(QDOC_USE_STATIC_LIBCLANG): QDOC_USE_STATIC_LIBCLANG = $$(QDOC_USE_STATIC_LIBCLANG)
for(_, $$list(_)) { # just a way to break easily
equals(QMAKE_HOST.os, Windows) { equals(QMAKE_HOST.os, Windows) {
# on Windows we have only two host compilers, MSVC or mingw. The former we never # on Windows we have only two host compilers, MSVC or mingw. The former we never
# use for cross-compilation where it isn't also the target compiler. The latter # use for cross-compilation where it isn't also the target compiler. The latter
...@@ -66,8 +63,7 @@ for(_, $$list(_)) { # just a way to break easily ...@@ -66,8 +63,7 @@ for(_, $$list(_)) { # just a way to break easily
clangInstallDir = $$replace(LLVM_INSTALL_DIR, _ARCH_, 32) clangInstallDir = $$replace(LLVM_INSTALL_DIR, _ARCH_, 32)
isEmpty(LLVM_INSTALL_DIR) { isEmpty(LLVM_INSTALL_DIR) {
win32 { win32 {
log("Set the LLVM_INSTALL_DIR environment variable to configure clang location (required to build qdoc).$$escape_expand(\\n)") return(false)
break()
} }
macos { macos {
# Default to homebrew llvm on macOS. The CLANG_VERSION test below will complain if missing. # Default to homebrew llvm on macOS. The CLANG_VERSION test below will complain if missing.
...@@ -92,16 +88,14 @@ for(_, $$list(_)) { # just a way to break easily ...@@ -92,16 +88,14 @@ for(_, $$list(_)) { # just a way to break easily
isEmpty(CLANG_VERSION) { isEmpty(CLANG_VERSION) {
!isEmpty(LLVM_INSTALL_DIR): \ !isEmpty(LLVM_INSTALL_DIR): \
error("Cannot determine clang version at $${clangInstallDir}.") error("Cannot determine clang version at $${clangInstallDir}.")
log("Set the LLVM_INSTALL_DIR environment variable to configure clang location.$$escape_expand(\\n)") return(false)
break()
} }
LIBCLANG_MAIN_HEADER = $$CLANG_INCLUDEPATH/clang-c/Index.h LIBCLANG_MAIN_HEADER = $$CLANG_INCLUDEPATH/clang-c/Index.h
!exists($$LIBCLANG_MAIN_HEADER) { !exists($$LIBCLANG_MAIN_HEADER) {
!isEmpty(LLVM_INSTALL_DIR): \ !isEmpty(LLVM_INSTALL_DIR): \
error("Cannot find libclang's main header file, candidate: $${LIBCLANG_MAIN_HEADER}.") error("Cannot find libclang's main header file, candidate: $${LIBCLANG_MAIN_HEADER}.")
log("Set the LLVM_INSTALL_DIR environment variable to configure clang location.$$escape_expand(\\n)") return(false)
break()
} }
!contains(QMAKE_DEFAULT_LIBDIRS, $$CLANG_LIBDIR): CLANG_LIBS = -L$${CLANG_LIBDIR} !contains(QMAKE_DEFAULT_LIBDIRS, $$CLANG_LIBDIR): CLANG_LIBS = -L$${CLANG_LIBDIR}
...@@ -319,15 +313,31 @@ for(_, $$list(_)) { # just a way to break easily ...@@ -319,15 +313,31 @@ for(_, $$list(_)) { # just a way to break easily
!versionIsAtLeast($$CLANG_VERSION, "3.9.0") { !versionIsAtLeast($$CLANG_VERSION, "3.9.0") {
log("LLVM/Clang version >= 3.9.0 required, version provided: $${CLANG_VERSION}.$$escape_expand(\\n)") log("LLVM/Clang version >= 3.9.0 required, version provided: $${CLANG_VERSION}.$$escape_expand(\\n)")
log("Clang was found in $${clangInstallDir}. Set the LLVM_INSTALL_DIR environment variable to override.$$escape_expand(\\n)") log("Clang was found in $${clangInstallDir}. Set the LLVM_INSTALL_DIR environment variable to override.$$escape_expand(\\n)")
break() return(false)
} }
cache(CLANG_LIBS) $${1}.libs = $$CLANG_LIBS
cache(CLANG_INCLUDEPATH) export($${1}.libs)
cache(CLANG_LIBDIR) $${1}.cache += libs
cache(CLANG_DEFINES)
cache(CLANG_VERSION) $${1}.includepath = $$CLANG_INCLUDEPATH
cache(CONFIG, add, $$list(config_clang)) export($${1}.includepath)
$${1}.cache += includepath
$${1}.libdir = $$CLANG_LIBDIR
export($${1}.libdir)
$${1}.cache += libdir
$${1}.defines = $$CLANG_DEFINES
export($${1}.defines)
$${1}.cache += defines
$${1}.version = $$CLANG_VERSION
export($${1}.version)
$${1}.cache += version
export($${1}.cache)
return(true)
} }
cache(CONFIG, add, $$list(config_clang_done))
...@@ -11,6 +11,8 @@ qtHaveModule(qmldevtools-private) { ...@@ -11,6 +11,8 @@ qtHaveModule(qmldevtools-private) {
DEFINES += QT_NO_DECLARATIVE DEFINES += QT_NO_DECLARATIVE
} }
include($$OUT_PWD/qtqdoc-config.pri)
LIBS += $$CLANG_LIBS LIBS += $$CLANG_LIBS
!contains(QMAKE_DEFAULT_INCDIRS, $$CLANG_INCLUDEPATH): INCLUDEPATH += $$CLANG_INCLUDEPATH !contains(QMAKE_DEFAULT_INCDIRS, $$CLANG_INCLUDEPATH): INCLUDEPATH += $$CLANG_INCLUDEPATH
DEFINES += $$CLANG_DEFINES DEFINES += $$CLANG_DEFINES
......
...@@ -23,7 +23,9 @@ qtConfig(library) { ...@@ -23,7 +23,9 @@ qtConfig(library) {
!android|android_app: SUBDIRS += qtplugininfo !android|android_app: SUBDIRS += qtplugininfo
} }
config_clang: qtConfig(thread): SUBDIRS += qdoc include($$OUT_PWD/qdoc/qtqdoc-config.pri)
QT_FOR_CONFIG += qdoc-private
qtConfig(qdoc): qtConfig(thread): SUBDIRS += qdoc
!android|android_app: SUBDIRS += qtpaths !android|android_app: SUBDIRS += qtpaths
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment