-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
154 lines (141 loc) · 3.94 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
cmake_minimum_required(VERSION 3.20)
project(toy-mlir LANGUAGES CXX C)
include(FetchContent)
find_package(MLIR REQUIRED CONFIG)
message(STATUS "Found MLIR ${MLIR_PACKAGE_VERSION}")
message(STATUS "Using MLIRConfig.cmake in: ${MLIR_DIR}")
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS})
llvm_map_components_to_libnames(llvm_libs core nativecodegen orcjit support)
list(APPEND CMAKE_MODULE_PATH "${MLIR_CMAKE_DIR}")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
FetchContent_Declare(ctl
GIT_REPOSITORY https://github.com/red1bluelost/ctl.git
GIT_TAG main)
FetchContent_MakeAvailable(ctl)
FetchContent_Declare(fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG master)
FetchContent_MakeAvailable(fmt)
FetchContent_Declare(range-v3
GIT_REPOSITORY https://github.com/ericniebler/range-v3.git
GIT_TAG master)
FetchContent_MakeAvailable(range-v3)
set(KUMI_BUILD_TEST OFF CACHE INTERNAL "OFF")
FetchContent_Declare(kumi
GIT_REPOSITORY https://github.com/jfalcou/kumi.git
GIT_TAG main)
FetchContent_MakeAvailable(kumi)
set(OPTIONAL_BUILD_TESTS OFF CACHE INTERNAL "OFF")
FetchContent_Declare(tl-optional
GIT_REPOSITORY https://github.com/TartanLlama/optional.git
GIT_TAG master)
FetchContent_MakeAvailable(tl-optional)
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if (CMAKE_BUILD_TYPE STREQUAL Release)
set_property(GLOBAL PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang)")
add_compile_options(
-Wall
-Wextra
-Wpedantic
-Wconversion
-march=native
-fno-rtti
$<$<CONFIG:DEBUG>:-fsanitize=address>
$<$<CONFIG:DEBUG>:-g3>
$<$<CONFIG:RELEASE>:-g0>
)
add_link_options(
-rdynamic
$<$<CONFIG:DEBUG>:-fsanitize=address>
)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(
/W4
/GR-
)
else ()
message(FATAL_ERROR "Unknown compiler '${CMAKE_CXX_COMPILER_ID}'")
endif ()
set(TOY_MLIR_SOURCES
lib/ast/ast.cpp
lib/dialect/dialect.cpp
lib/dialect/lower_to_affine_loops_pass.cpp
lib/dialect/lower_to_llvm_pass.cpp
lib/dialect/mlir_gen.cpp
lib/dialect/shape_interface_pass.cpp
lib/lexer/lexer.cpp
lib/parser/parser.cpp
lib/transforms/simplify.cpp)
set(TOY_MLIR_HEADERS
include/toy/ast/ast.hpp
include/toy/dialect/dialect.hpp
include/toy/dialect/mlir_gen.hpp
include/toy/dialect/passes.hpp
include/toy/dialect/shape_inference_interface.hpp
include/toy/core/types.hpp
include/toy/lexer/lexer.hpp
include/toy/lexer/location.hpp
include/toy/parser/parser.hpp
include/toy/util/line_reader.hpp
include/toy/util/string_view_line_reader.hpp)
include_directories(${PROJECT_SOURCE_DIR}/include/)
include_directories(SYSTEM ${LLVM_INCLUDE_DIRS} ${MLIR_INCLUDE_DIRS})
add_subdirectory(include/toy/dialect)
add_subdirectory(lib/transforms)
add_library(
toy_mlir_library
${TOY_MLIR_SOURCES}
${TOY_MLIR_HEADERS}
)
target_include_directories(
toy_mlir_library
PUBLIC
${PROJECT_SOURCE_DIR}/include/
${CMAKE_CURRENT_BINARY_DIR}/include/
${CMAKE_CURRENT_BINARY_DIR}/lib_include/
)
target_link_libraries(
toy_mlir_library
fmt::fmt
range-v3
ctl::core
ctl::object
kumi::kumi
tl::optional
${llvm_libs}
MLIRAffineToStandard
MLIRAnalysis
MLIRBuiltinToLLVMIRTranslation
MLIRCallInterfaces
MLIRCastInterfaces
MLIRFuncToLLVM
MLIRIR
MLIRLLVMCommonConversion
MLIRLLVMToLLVMIRTranslation
MLIRMemRefDialect
MLIRMemRefToLLVM
MLIRParser
MLIRPass
MLIRSCFDialect
MLIRSCFToControlFlow
MLIRSideEffectInterfaces
MLIRTargetLLVMIRExport
MLIRTransforms
)
add_dependencies(
toy_mlir_library
toy_shape_interface_interface_inc_gen
toy_simplify_inc_gen
toy_ops_inc_gen
)
add_subdirectory(tools)
enable_testing()
add_subdirectory(unittests)