clang_installation.pri 4.4 KB
Newer Older
1
isEmpty(LLVM_INSTALL_DIR):LLVM_INSTALL_DIR=$$(LLVM_INSTALL_DIR)
2
LLVM_INSTALL_DIR = $$clean_path($$LLVM_INSTALL_DIR)
3
4
isEmpty(LLVM_INSTALL_DIR): error("No LLVM_INSTALL_DIR provided")
!exists($$LLVM_INSTALL_DIR): error("LLVM_INSTALL_DIR does not exist: $$LLVM_INSTALL_DIR")
5

6
7
8
defineReplace(extractVersion)      { return($$replace(1, ^(\\d+\\.\\d+\\.\\d+)$, \\1)) }
defineReplace(extractMajorVersion) { return($$replace(1, ^(\\d+)\\.\\d+\\.\\d+$, \\1)) }
defineReplace(extractMinorVersion) { return($$replace(1, ^\\d+\\.(\\d+)\\.\\d+$, \\1)) }
9
defineReplace(extractPatchVersion) { return($$replace(1, ^\\d+\\.\\d+\\.(\\d+)$, \\1)) }
10
11
12
13

defineTest(versionIsAtLeast) {
    actual_major_version = $$extractMajorVersion($$1)
    actual_minor_version = $$extractMinorVersion($$1)
14
    actual_patch_version = $$extractPatchVersion($$1)
15
16
    required_min_major_version = $$2
    required_min_minor_version = $$3
17
    required_min_patch_version = $$4
18
19

    isEqual(actual_major_version, $$required_min_major_version) {
20
21
22
23
        isEqual(actual_minor_version, $$required_min_minor_version) {
            isEqual(actual_patch_version, $$required_min_patch_version): return(true)
            greaterThan(actual_patch_version, $$required_min_patch_version): return(true)
        }
24
25
26
27
28
29
30
        greaterThan(actual_minor_version, $$required_min_minor_version): return(true)
    }
    greaterThan(actual_major_version, $$required_min_major_version): return(true)

    return(false)
}

31
32
33
34
35
36
37
defineReplace(findLLVMVersionFromLibDir) {
    libdir = $$1
    version_dirs = $$files($$libdir/clang/*)
    for (version_dir, version_dirs) {
        fileName = $$basename(version_dir)
        version = $$find(fileName, ^(\\d+\\.\\d+\\.\\d+)$)
        !isEmpty(version): return($$version)
38
    }
39
}
40

41
42
defineReplace(findClangLibInLibDir) {
    libdir = $$1
43
    exists($${libdir}/libclang.so*)|exists($${libdir}/libclang.dylib) {
Marco Bubke's avatar
Marco Bubke committed
44
        return("-lclang")
45
    } else {
46
        exists ($${libdir}/libclang.*) {
Marco Bubke's avatar
Marco Bubke committed
47
            return("-llibclang")
48
49
50
51
        }
    }
}

52
53
defineReplace(findClangOnWindows) {
    FILE_EXTS = a dll
54
    msvc: FILE_EXTS = lib dll
55
56
57
    for (suffix, $$list(lib bin)) {
        for (libname, $$list(clang libclang)) {
            for (ext, FILE_EXTS) {
58
                exists("$${LLVM_INSTALL_DIR}/$${suffix}/$${libname}.$${ext}") {
59
                    return($${LLVM_INSTALL_DIR}/$${suffix}/)
60
                }
61
            }
62
63
        }
    }
64
65
}

Marco Bubke's avatar
Marco Bubke committed
66
67
CLANGTOOLING_LIBS=-lclangTooling -lclangIndex -lclangFrontend -lclangParse -lclangSerialization \
                  -lclangSema -lclangEdit -lclangAnalysis -lclangDriver -lclangASTMatchers \
Marco Bubke's avatar
Marco Bubke committed
68
                  -lclangToolingCore -lclangAST -lclangLex -lclangBasic
69

Marco Bubke's avatar
Marco Bubke committed
70
71
BIN_EXTENSION =
win32: BIN_EXTENSION = .exe
72

Marco Bubke's avatar
Marco Bubke committed
73
74
75
llvm_config = $$system_quote($$LLVM_INSTALL_DIR/bin/llvm-config)
requires(exists($$llvm_config$$BIN_EXTENSION))
#message("llvm-config found, querying it for paths and version")
76
LLVM_LIBDIR = $$quote($$system($$llvm_config --libdir, lines))
Marco Bubke's avatar
Marco Bubke committed
77
78
79
LLVM_INCLUDEPATH = $$system($$llvm_config --includedir, lines)
output = $$system($$llvm_config --version, lines)
LLVM_VERSION = $$extractVersion($$output)
80
81
unix:LLVM_STATIC_LIBS_STRING += $$system($$llvm_config --libs, lines)
win32:LLVM_STATIC_LIBS_STRING += $$system($$llvm_config --libnames, lines)
Marco Bubke's avatar
Marco Bubke committed
82
LLVM_STATIC_LIBS_STRING += $$system($$llvm_config --system-libs, lines)
83

Marco Bubke's avatar
Marco Bubke committed
84
LLVM_STATIC_LIBS = $$split(LLVM_STATIC_LIBS_STRING, " ")
85

Marco Bubke's avatar
Marco Bubke committed
86
87
88
89
90
LIBCLANG_MAIN_HEADER = $$LLVM_INCLUDEPATH/clang-c/Index.h
!exists($$LIBCLANG_MAIN_HEADER): error("Cannot find libclang's main header file, candidate: $$LIBCLANG_MAIN_HEADER")
!exists($$LLVM_LIBDIR): error("Cannot detect lib dir for clang, candidate: $$LLVM_LIBDIR")
CLANG_LIB = $$findClangLibInLibDir($$LLVM_LIBDIR)
isEmpty(CLANG_LIB): error("Cannot find Clang shared library in $$LLVM_LIBDIR")
91

Marco Bubke's avatar
Marco Bubke committed
92
93
94
95
96
!contains(QMAKE_DEFAULT_LIBDIRS, $$LLVM_LIBDIR): LIBCLANG_LIBS = -L$${LLVM_LIBDIR}
LIBCLANG_LIBS += $${CLANG_LIB}
!contains(QMAKE_DEFAULT_LIBDIRS, $$LLVM_LIBDIR): LIBTOOLING_LIBS = -L$${LLVM_LIBDIR}
LIBTOOLING_LIBS += $$CLANGTOOLING_LIBS $$LLVM_STATIC_LIBS
contains(QMAKE_DEFAULT_INCDIRS, $$LLVM_INCLUDEPATH): LLVM_INCLUDEPATH =
97
98

isEmpty(LLVM_VERSION): error("Cannot determine clang version at $$LLVM_INSTALL_DIR")
Nikolai Kosjar's avatar
Nikolai Kosjar committed
99
100
!versionIsAtLeast($$LLVM_VERSION, 3, 9, 0): {
    error("LLVM/Clang version >= 3.9.0 required, version provided: $$LLVM_VERSION")
101
}
Marco Bubke's avatar
Marco Bubke committed
102

103
unix:LLVM_CXXFLAGS = -fno-rtti -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
104
105

LLVM_IS_COMPILED_WITH_RTTI = $$system($$llvm_config --has-rtti, lines)