CMakeLists.txt
2.71 KB
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
set(LLVM_OPTIONAL_SOURCES
mlir-vulkan-runner.cpp
vulkan-runtime-wrappers.cpp
VulkanRuntime.cpp
VulkanRuntime.h
)
if (MLIR_VULKAN_RUNNER_ENABLED)
message(STATUS "Building the Vulkan runner")
# At first try "FindVulkan" from:
# https://cmake.org/cmake/help/v3.7/module/FindVulkan.html
if (NOT CMAKE_VERSION VERSION_LESS 3.7.0)
find_package(Vulkan)
endif()
# If Vulkan is not found try a path specified by VULKAN_SDK.
if (NOT Vulkan_FOUND)
if ("$ENV{VULKAN_SDK}" STREQUAL "")
message(FATAL_ERROR "Please use at least CMAKE 3.7.0 or provide "
"VULKAN_SDK path as an environment variable")
endif()
find_library(Vulkan_LIBRARY vulkan HINTS "$ENV{VULKAN_SDK}/lib" REQUIRED)
if (Vulkan_LIBRARY)
set(Vulkan_FOUND ON)
set(Vulkan_INCLUDE_DIR "$ENV{VULKAN_SDK}/include")
message(STATUS "Found Vulkan: " ${Vulkan_LIBRARY})
endif()
endif()
if (NOT Vulkan_FOUND)
message(FATAL_ERROR "Cannot find Vulkan library")
endif()
add_llvm_library(vulkan-runtime-wrappers SHARED
vulkan-runtime-wrappers.cpp
VulkanRuntime.cpp
)
target_include_directories(vulkan-runtime-wrappers
PUBLIC
${Vulkan_INCLUDE_DIR}
)
# *IMPORTANT*: This library cannot depend on LLVM libraries. Otherwise,
# it may cause LLVM version conflict when used together with other shared
# libraries depending on LLVM. Notably, Mesa, who implemnents Vulkan
# drivers on Linux, depends on the system libLLVM.so.
target_link_libraries(vulkan-runtime-wrappers
PUBLIC
${Vulkan_LIBRARY}
)
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
set(LIBS
${dialect_libs}
${conversion_libs}
LLVMCore
LLVMSupport
MLIRAnalysis
MLIREDSC
MLIRExecutionEngine
MLIRIR
MLIRJitRunner
MLIRLLVMIR
MLIRParser
MLIRSPIRVTransforms
MLIRSupport
MLIRTargetLLVMIR
MLIRTransforms
MLIRTranslation
${Vulkan_LIBRARY}
)
# Manually expand the target library, since our MLIR libraries
# aren't plugged into the LLVM dependency tracking. If we don't
# do this then we can't insert the CodeGen library after ourselves
llvm_expand_pseudo_components(TARGET_LIBS AllTargetsCodeGens)
# Prepend LLVM in front of every target, this is how the library
# are named with CMake
SET(targets_to_link)
FOREACH(t ${TARGET_LIBS})
LIST(APPEND targets_to_link "LLVM${t}")
ENDFOREACH(t)
add_llvm_tool(mlir-vulkan-runner
mlir-vulkan-runner.cpp
)
add_dependencies(mlir-vulkan-runner vulkan-runtime-wrappers)
llvm_update_compile_flags(mlir-vulkan-runner)
target_link_libraries(mlir-vulkan-runner PRIVATE ${FULL_LINK_LIBS} ${LIBS})
endif()