summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: f04ac1fda8e9b4e34e9d1fa6b008507818588c55 (plain)
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
cmake_minimum_required(VERSION 3.12)
project(toyc)

set(CMAKE_CXX_STANDARD 14)

find_package(LLVM CONFIG PATHS "${MLIR_INSTALL_PREFIX}" NO_DEFAULT_PATH)

if (LLVM_FOUND)
  message(STATUS "Using LLVM ${LLVM_PACKAGE_VERSION} at ${LLVM_INSTALL_PREFIX}")
else()
  message(FATAL_ERROR "LLVM not found; it is derived from MLIR_INSTALL_PREFIX which has value of ${MLIR_INSTALL_PREFIX}")
endif()

function(whole_archive_link target)
  if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
    set(link_flags "-L${CMAKE_BINARY_DIR}/lib ")
    FOREACH(LIB ${ARGN})
      string(CONCAT link_flags ${link_flags} "-Wl,-force_load ${CMAKE_BINARY_DIR}/lib/lib${LIB}.a ")
    ENDFOREACH(LIB)
  else()
    set(link_flags "-L${CMAKE_BINARY_DIR}/lib -Wl,--whole-archive,")
    FOREACH(LIB ${ARGN})
      string(CONCAT link_flags ${link_flags} "-l${LIB},")
    ENDFOREACH(LIB)
    string(CONCAT link_flags ${link_flags} "--no-whole-archive")
  endif()
  set_target_properties(${target} PROPERTIES LINK_FLAGS ${link_flags})
endfunction(whole_archive_link)

llvm_map_components_to_libnames(llvm_libs support)

if (NOT ${LLVM_ENABLE_RTTI})
  set(CMAKE_CXX_FLAGS "-fno-rtti ${CMAKE_CXX_FLAGS}")
endif()

include_directories(
  include
  ${LLVM_INCLUDE_DIR})

link_directories(${LLVM_LIBRARY_DIR})

add_definitions(${LLVM_DEFINITIONS})

add_executable(toyc
  toyc.cpp
  parser/AST.cpp
  mlir/EarlyLowering.cpp
  mlir/LateLowering.cpp
  mlir/MLIRGen.cpp
  mlir/ShapeInferencePass.cpp
  mlir/ToyDialect.cpp
  mlir/ToyCombine.cpp
  )

target_link_libraries(toyc
    PRIVATE
    ${llvm_libs}
    Linalg3DialectConstruction
    Linalg3
    Linalg2
    Linalg1
    MLIRAnalysis
    MLIREDSC
    MLIRExecutionEngine
    MLIRIR
    MLIRLLVMIR
    MLIRParser
    MLIRPass
    MLIRTargetLLVMIR
    MLIRTransforms
    MLIRSupport
    )

whole_archive_link(toyc MLIRStandardOps MLIRAffineOps)