]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tools/libclang/CMakeLists.txt
Vendor import of clang trunk r351319 (just before the release_80 branch
[FreeBSD/FreeBSD.git] / tools / libclang / CMakeLists.txt
1 set(SOURCES
2   ARCMigrate.cpp
3   BuildSystem.cpp
4   CIndex.cpp
5   CIndexCXX.cpp
6   CIndexCodeCompletion.cpp
7   CIndexDiagnostic.cpp
8   CIndexHigh.cpp
9   CIndexInclusionStack.cpp
10   CIndexUSRs.cpp
11   CIndexer.cpp
12   CXComment.cpp
13   CXCursor.cpp
14   CXIndexDataConsumer.cpp
15   CXCompilationDatabase.cpp
16   CXLoadedDiagnostic.cpp
17   CXSourceLocation.cpp
18   CXStoredDiagnostic.cpp
19   CXString.cpp
20   CXType.cpp
21   Indexing.cpp
22
23   ADDITIONAL_HEADERS
24   CIndexDiagnostic.h
25   CIndexer.h
26   CXCursor.h
27   CXLoadedDiagnostic.h
28   CXSourceLocation.h
29   CXString.h
30   CXTranslationUnit.h
31   CXType.h
32   Index_Internal.h
33   ../../include/clang-c/Index.h
34   )
35
36 set(LIBS
37   clangAST
38   clangBasic
39   clangFrontend
40   clangIndex
41   clangLex
42   clangSema
43   clangSerialization
44   clangTooling
45 )
46
47 if (CLANG_ENABLE_ARCMT)
48   list(APPEND LIBS clangARCMigrate)
49 endif ()
50
51 if (TARGET clangTidyPlugin)
52   add_definitions(-DCLANG_TOOL_EXTRA_BUILD)
53   list(APPEND LIBS clangTidyPlugin)
54   list(APPEND LIBS clangIncludeFixerPlugin)
55   if(LLVM_ENABLE_MODULES)
56     list(APPEND LLVM_COMPILE_FLAGS "-fmodules-ignore-macro=CLANG_TOOL_EXTRA_BUILD")
57   endif()
58 endif ()
59
60 find_library(DL_LIBRARY_PATH dl)
61 if (DL_LIBRARY_PATH)
62   list(APPEND LIBS dl)
63 endif()
64
65 option(LIBCLANG_BUILD_STATIC
66   "Build libclang as a static library (in addition to a shared one)" OFF)
67
68 set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/libclang.exports)
69
70 if(MSVC)
71   # Avoid LNK4197 by not specifying libclang.exports here.
72   # Each functions is exported as "dllexport" in include/clang-c.
73   # KB835326
74   set(LLVM_EXPORTED_SYMBOL_FILE)
75 endif()
76
77 if( LLVM_ENABLE_PIC )
78   set(ENABLE_SHARED SHARED)
79 endif()
80
81 if((NOT LLVM_ENABLE_PIC OR LIBCLANG_BUILD_STATIC) AND NOT WIN32)
82   set(ENABLE_STATIC STATIC)
83 endif()
84
85 if(WIN32)
86   set(output_name "libclang")
87 else()
88   set(output_name "clang")
89 endif()
90
91 add_clang_library(libclang ${ENABLE_SHARED} ${ENABLE_STATIC}
92   OUTPUT_NAME ${output_name}
93   ${SOURCES}
94   DEPENDS clang-headers
95
96   LINK_LIBS
97   ${LIBS}
98
99   LINK_COMPONENTS
100   ${LLVM_TARGETS_TO_BUILD}
101   Core
102   Support
103   )
104
105 if(ENABLE_SHARED)
106   if(WIN32)
107     set_target_properties(libclang
108       PROPERTIES
109       VERSION ${LIBCLANG_LIBRARY_VERSION}
110       DEFINE_SYMBOL _CINDEX_LIB_)
111   elseif(APPLE)
112     set(LIBCLANG_LINK_FLAGS " -Wl,-compatibility_version -Wl,1")
113     set(LIBCLANG_LINK_FLAGS "${LIBCLANG_LINK_FLAGS} -Wl,-current_version -Wl,${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
114
115     set_property(TARGET libclang APPEND_STRING PROPERTY
116                  LINK_FLAGS ${LIBCLANG_LINK_FLAGS})
117   else()
118     set_target_properties(libclang
119       PROPERTIES
120       VERSION ${LIBCLANG_LIBRARY_VERSION}
121       DEFINE_SYMBOL _CINDEX_LIB_)
122     # FIXME: _CINDEX_LIB_ affects dllexport/dllimport on Win32.
123     if(LLVM_ENABLE_MODULES AND NOT WIN32)
124       target_compile_options(libclang PRIVATE
125         "-fmodules-ignore-macro=_CINDEX_LIB_"
126         )
127     endif()
128   endif()
129 endif()
130
131 if(INTERNAL_INSTALL_PREFIX)
132   set(LIBCLANG_HEADERS_INSTALL_DESTINATION "${INTERNAL_INSTALL_PREFIX}/include")
133 else()
134   set(LIBCLANG_HEADERS_INSTALL_DESTINATION include)
135 endif()
136
137 install(DIRECTORY ../../include/clang-c
138   COMPONENT libclang-headers
139   DESTINATION "${LIBCLANG_HEADERS_INSTALL_DESTINATION}"
140   FILES_MATCHING
141   PATTERN "*.h"
142   PATTERN ".svn" EXCLUDE
143   )
144
145 # LLVM_DISTRIBUTION_COMPONENTS requires that each component have both a
146 # component and an install-component target, so add a dummy libclang-headers
147 # target to allow using it in LLVM_DISTRIBUTION_COMPONENTS.
148 add_custom_target(libclang-headers)
149 set_target_properties(libclang-headers PROPERTIES FOLDER "Misc")
150
151 if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDE's.
152   add_llvm_install_targets(install-libclang-headers
153                            COMPONENT libclang-headers)
154 endif()
155
156 # Create a target to install the python bindings to make them easier to
157 # distribute.  Since the bindings are over libclang, which is installed
158 # unbundled to the clang version, follow suit.
159 foreach(PythonVersion ${CLANG_PYTHON_BINDINGS_VERSIONS})
160   install(DIRECTORY
161             ${CMAKE_CURRENT_SOURCE_DIR}/../../bindings/python/clang
162           COMPONENT
163             libclang-python-bindings
164           DESTINATION
165             "lib${LLVM_LIBDIR_SUFFIX}/python${PythonVersion}/site-packages")
166 endforeach()
167 if(NOT CMAKE_CONFIGURATION_TYPES)
168   add_custom_target(libclang-python-bindings)
169   add_llvm_install_targets(install-libclang-python-bindings
170                            COMPONENT
171                              libclang-python-bindings)
172 endif()
173