This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
100 lines (86 loc) · 3.06 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
cmake_minimum_required(VERSION 3.10.2)
project(transformer)
set(CMAKE_FIND_PACKAGE_SORT_ORDER NATURAL)
set(CMAKE_FIND_PACKAGE_SORT_DIRECTION DEC)
set(SOURCE_DIR "transformer")
include_directories(${SOURCE_DIR})
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(MACOSX TRUE)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
find_package(
Python3
COMPONENTS Development
REQUIRED)
include_directories(${Python3_INCLUDE_DIRS})
link_directories(${Python3_LIBRARY_DIRS})
add_link_options(${Python3_LINK_OPTIONS})
find_package(LLVM REQUIRED CONFIG HINTS "${LLVM_DIR}" ENV LLVM_DIR)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
if(("${LLVM_PACKAGE_VERSION}" VERSION_LESS 9.0.0)
OR ("${LLVM_PACKAGE_VERSION}" VERSION_GREATER_EQUAL 12))
message(FATAL_ERROR "Unsupported LLVM version: ${LLVM_PACKAGE_VERSION}")
endif()
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
add_definitions(${LLVM_DEFINITIONS})
find_package(Clang REQUIRED CONFIG HINTS "${Clang_DIR}" ENV Clang_DIR)
message(STATUS "Using ClangConfig.cmake in: ${Clang_DIR}")
include_directories(${CLANG_INCLUDE_DIRS})
add_definitions(${CLANG_DEFINITIONS})
set(LIBRARY_LIST
clangAST
clangASTMatchers
clangAnalysis
clangBasic
clangDriver
clangEdit
clangFrontend
clangFrontendTool
clangLex
clangParse
clangSema
clangEdit
clangRewrite
clangRewriteFrontend
clangStaticAnalyzerFrontend
clangStaticAnalyzerCheckers
clangStaticAnalyzerCore
clangCrossTU
clangIndex
clangSerialization
clangToolingCore
clangToolingInclusions
clangTooling
clangFormat)
if("${LLVM_PACKAGE_VERSION}" VERSION_LESS 10.0.0)
list(APPEND LIBRARY_LIST clangToolingRefactoring)
elseif("${LLVM_PACKAGE_VERSION}" VERSION_GREATER_EQUAL 10.0.0)
list(APPEND LIBRARY_LIST clangTransformer)
endif()
if(NOT MACOSX)
# NOTE(ww): For reasons that are unclear to me, macOS does *not* want Python
# extensions to link to the Python development libraries directly. Instead, it
# expects to resolve them dynamically via dynamic_lookup. See
# target_link_options below.
set(LIBRARY_LIST ${LIBRARY_LIST} ${Python3_LIBRARIES})
endif()
add_definitions(-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS)
add_library(${PROJECT_NAME} SHARED ${SOURCE_DIR}/ASTExporter.cpp
${SOURCE_DIR}/extractor.cpp)
set_target_properties(${PROJECT_NAME}
PROPERTIES PREFIX "" OUTPUT_NAME ${PYTHON_MODULE_NAME})
if(MACOSX)
target_link_libraries(${PROJECT_NAME} ${LIBRARY_LIST})
# NOTE(ww): See the conditional inclusion above.
target_link_options(${PROJECT_NAME} PUBLIC -undefined dynamic_lookup)
# NOTE(ww): Python extensions on macOS don't use .dylib.
set_target_properties(${PROJECT_NAME} PROPERTIES SUFFIX ".so")
else()
target_link_libraries(${PROJECT_NAME} -Wl,--start-group ${LIBRARY_LIST}
-Wl,--end-group)
endif()
target_link_libraries(${PROJECT_NAME} LLVM pthread m)