forked from petrv7/llvm2c
-
Notifications
You must be signed in to change notification settings - Fork 9
/
CMakeLists.txt
136 lines (118 loc) · 3.9 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
cmake_minimum_required(VERSION 3.1)
# FIXME: Unfortunately, C is (at least temporarily) required due to a bug
# in LLVM 14. See https://github.com/llvm/llvm-project/issues/53950.
project(llvm2c LANGUAGES C CXX)
# --------------------------------------------------
# Build type
# --------------------------------------------------
if(NOT CMAKE_BUILD_TYPE)
message(STATUS "Build type not set. Setting default.")
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "" FORCE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "RelWithDebInfo"
"MinSizeRel" "Release")
# --------------------------------------------------
# Compilation flags
# --------------------------------------------------
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -pedantic -fno-rtti")
# --------------------------------------------------
# LLVM
# --------------------------------------------------
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
if(${LLVM_PACKAGE_VERSION} VERSION_LESS "5.0")
message(FATAL_ERROR "LLVM 5.0 or newer is required!")
endif()
message(STATUS "LLVM include dir: ${LLVM_INCLUDE_DIRS}")
message(STATUS "LLVM libraries dir: ${LLVM_LIBRARY_DIRS}")
message(STATUS "LLVM definitions: ${LLVM_DEFINITIONS}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}")
include(AddLLVM)
add_definitions(${LLVM_DEFINITIONS})
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
option(LLVM_LINK_DYLIB "Link with LLVM dynamically" ON)
if(LLVM_LINK_DYLIB)
message(STATUS "LLVM linking: dynamic")
set(llvm_libs LLVM)
else()
message(STATUS "LLVM linking: static")
# Find the libraries that correspond to the LLVM components
# that we wish to use
llvm_map_components_to_libnames(llvm_libs bitwriter core irreader linker
support)
endif()
# --------------------------------------------------
# llvm2c
# --------------------------------------------------
set(llvm2c_sources
main.cpp
core/Block.cpp
core/Block.h
core/Func.cpp
core/Func.h
core/Program.cpp
core/Program.h
expr/BinaryExpr.cpp
expr/BinaryExpr.h
expr/Expr.cpp
expr/Expr.h
expr/UnaryExpr.cpp
expr/UnaryExpr.h
parser/ProgramParser.cpp
parser/ProgramParser.h
parser/SimplifyingExprVisitor.cpp
parser/addSignCasts.cpp
parser/arrowify.cpp
parser/cfunc.h
parser/computeGlobalVarsOrder.cpp
parser/constval.cpp
parser/createAllocas.cpp
parser/createBlocks.cpp
parser/createConstants.cpp
parser/createExpressions.cpp
parser/createFunctionParameters.cpp
parser/createFunctions.cpp
parser/deleteRedundantCasts.cpp
parser/deleteUnusedVariables.cpp
parser/determineIncludes.cpp
parser/extractVars.cpp
parser/findDeclaredFunctions.cpp
parser/findMetadataFunctionNames.cpp
parser/findMetadataVariableNames.cpp
parser/fixMainParameters.cpp
parser/identifyInlinableBlocks.cpp
parser/initializeGlobalVars.cpp
parser/inlineBlocks.cpp
parser/memcpyToAssign.cpp
parser/nameFunctions.cpp
parser/parseBreaks.cpp
parser/parseMetadataTypes.cpp
parser/parseStructDeclarations.cpp
parser/parseStructItems.cpp
parser/passes.h
parser/prepareBitcastUnion.cpp
parser/refDeref.cpp
parser/toinst.cpp
parser/toinst.h
type/Type.cpp
type/Type.h
type/TypeHandler.cpp
type/TypeHandler.h
writer/CWriter.cpp
writer/ExprWriter.cpp
writer/Writer.cpp
)
add_executable(llvm2c ${llvm2c_sources})
target_link_libraries(llvm2c ${llvm_libs})
include(GNUInstallDirs)
install(TARGETS llvm2c
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
# --------------------------------------------------
# Subdirectories
# --------------------------------------------------
add_subdirectory(test)