forked from KhronosGroup/SPIRV-LLVM-Translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
142 lines (125 loc) · 4.34 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
cmake_minimum_required(VERSION 3.13.4)
if(NOT DEFINED BASE_LLVM_VERSION)
set (BASE_LLVM_VERSION 16.0.0)
endif(NOT DEFINED BASE_LLVM_VERSION)
set(LLVM_SPIRV_VERSION ${BASE_LLVM_VERSION}.0)
include(FetchContent)
include(FindPkgConfig)
option(LLVM_SPIRV_INCLUDE_TESTS
"Generate build targets for the llvm-spirv lit tests."
${LLVM_INCLUDE_TESTS})
if (NOT DEFINED LLVM_SPIRV_BUILD_EXTERNAL)
# check if we build inside llvm or not
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(LLVM_SPIRV_BUILD_EXTERNAL YES)
endif(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
endif (NOT DEFINED LLVM_SPIRV_BUILD_EXTERNAL)
if(LLVM_SPIRV_BUILD_EXTERNAL)
# Make sure llvm-spirv gets built when building outside the llvm tree.
set(LLVM_BUILD_TOOLS ON)
endif(LLVM_SPIRV_BUILD_EXTERNAL)
# Download spirv.hpp from the official SPIRV-Headers repository.
# One can skip this step by manually setting
# LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR path.
if(NOT DEFINED LLVM_TOOL_SPIRV_HEADERS_BUILD AND
NOT DEFINED LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR)
set(LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR
"${CMAKE_CURRENT_BINARY_DIR}/SPIRV-Headers")
message(STATUS "SPIR-V Headers location is not specified. Will try to download
spirv.hpp from https://github.com/KhronosGroup/SPIRV-Headers into
${LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR}")
file(READ spirv-headers-tag.conf SPIRV_HEADERS_TAG)
# Strip the potential trailing newline from tag
string(STRIP "${SPIRV_HEADERS_TAG}" SPIRV_HEADERS_TAG)
FetchContent_Declare(spirv-headers
GIT_REPOSITORY https://github.com/KhronosGroup/SPIRV-Headers.git
GIT_TAG ${SPIRV_HEADERS_TAG}
SOURCE_DIR ${LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR}
)
FetchContent_MakeAvailable(spirv-headers)
else()
if(NOT DEFINED LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR)
# This means LLVM_TOOL_SPIRV_HEADERS_BUILD is defined, therefore
# SPIRV-Headers exist as a subproject.
set(LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR
"${CMAKE_SOURCE_DIR}/projects/SPIRV-Headers")
if(NOT EXISTS ${LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR})
message(FATAL_ERROR "No location specified for SPIRV-Headers.
Try setting the LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR
path or put the project into the llvm/projects folder
under the name 'SPIRV-Headers'")
endif()
endif()
message(STATUS "Using SPIR-V Headers from
${LLVM_EXTERNAL_SPIRV_HEADERS_SOURCE_DIR}")
endif()
if(LLVM_SPIRV_BUILD_EXTERNAL)
project(LLVM_SPIRV
VERSION
${LLVM_SPIRV_VERSION}
LANGUAGES
CXX
C
)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(LLVM_SPIRV_INCLUDE_TESTS)
set(LLVM_TEST_COMPONENTS
llvm-as
llvm-dis
)
endif(LLVM_SPIRV_INCLUDE_TESTS)
find_package(LLVM ${BASE_LLVM_VERSION} REQUIRED
COMPONENTS
Analysis
BitReader
BitWriter
CodeGen
Core
Passes
Support
TargetParser
TransformUtils
${LLVM_TEST_COMPONENTS}
)
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${LLVM_CMAKE_DIR}
)
include(AddLLVM)
include(HandleLLVMOptions)
message(STATUS "Found LLVM: ${LLVM_VERSION}")
option(CCACHE_ALLOWED "allow use of ccache" TRUE)
find_program(CCACHE_EXE_FOUND ccache)
if(CCACHE_EXE_FOUND AND CCACHE_ALLOWED)
message(STATUS "Found ccache: ${CCACHE_EXE_FOUND}")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache)
endif()
endif()
set(LLVM_SPIRV_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)
pkg_search_module(SPIRV_TOOLS SPIRV-Tools)
if(NOT SPIRV_TOOLS_FOUND)
message(STATUS "SPIRV-Tools not found; project will be built without "
"--spirv-tools-dis support.")
endif(NOT SPIRV_TOOLS_FOUND)
add_subdirectory(lib/SPIRV)
add_subdirectory(tools/llvm-spirv)
if(LLVM_SPIRV_INCLUDE_TESTS)
add_subdirectory(test)
endif(LLVM_SPIRV_INCLUDE_TESTS)
install(
FILES
${LLVM_SPIRV_INCLUDE_DIRS}/LLVMSPIRVLib.h
${LLVM_SPIRV_INCLUDE_DIRS}/LLVMSPIRVOpts.h
${LLVM_SPIRV_INCLUDE_DIRS}/LLVMSPIRVExtensions.inc
DESTINATION
${CMAKE_INSTALL_PREFIX}/include/LLVMSPIRVLib
)
configure_file(LLVMSPIRVLib.pc.in ${CMAKE_BINARY_DIR}/LLVMSPIRVLib.pc @ONLY)
install(
FILES
${CMAKE_BINARY_DIR}/LLVMSPIRVLib.pc
DESTINATION
${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}/pkgconfig
)