-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
79 lines (60 loc) · 2.09 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
cmake_minimum_required(VERSION 3.4.3)
project(OutOfTreeLLVMPass
VERSION 1.0.0
LANGUAGES C CXX
)
set(CMAKE_CXX_STANDARD 17)
if (NOT PATH_TO_LLVM)
message(FATAL_ERROR "
The cmake is supposed to be called with PATH_TO_LLVM pointing to
a precompiled version of LLVM or to to the source code of LLVM
Examples:
cmake -G \"${CMAKE_GENERATOR}\" -DPATH_TO_LLVM=/opt/llvm-9.0.1 ${CMAKE_SOURCE_DIR}
cmake -G \"${CMAKE_GENERATOR}\" -DPATH_TO_LLVM=/llvm-project/llvm ${CMAKE_SOURCE_DIR}
")
endif()
if (NOT IS_ABSOLUTE ${PATH_TO_LLVM})
# Convert relative path to absolute path
get_filename_component(PATH_TO_LLVM
"${PATH_TO_LLVM}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}")
endif()
set (BUILD_AGAINST_PRECOMPILED_LLVM TRUE)
if (EXISTS ${PATH_TO_LLVM}/CMakeLists.txt)
set (BUILD_AGAINST_PRECOMPILED_LLVM FALSE)
endif()
# This enables assertions for Release builds.
# https://stackoverflow.com/questions/22140520/how-to-enable-assert-in-cmake-release-mode
string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
if (${BUILD_AGAINST_PRECOMPILED_LLVM})
set (search_paths
${PATH_TO_LLVM}
${PATH_TO_LLVM}/lib/cmake
${PATH_TO_LLVM}/lib/cmake/llvm
${PATH_TO_LLVM}/share/llvm/cmake/
)
find_package(LLVM REQUIRED CONFIG PATHS ${search_paths} NO_DEFAULT_PATH)
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
else()
set (LLVM_TARGETS_TO_BUILD "host" CACHE STRING "Only build targets for host architecture" FORCE)
add_subdirectory(${PATH_TO_LLVM} llvm-build)
# Normally, include paths provided by LLVMConfig.cmake
# In this case we can 'steal' them from real targets
get_target_property(LLVM_INCLUDE_DIRS LLVMSupport INCLUDE_DIRECTORIES)
# Manually add the llvm CMake module path
list(APPEND CMAKE_MODULE_PATH
"${PATH_TO_LLVM}/cmake/modules"
)
set(LLVM_MAIN_SRC_DIR ${PATH_TO_LLVM})
endif()
# CMake Modules used for llvm specific macros
include(LLVM-Config)
include(HandleLLVMOptions)
include(AddLLVM)
include_directories(${LLVM_INCLUDE_DIRS})
add_llvm_library(OutOfTreeLLVMPass MODULE
Hello.cpp
DEPENDS
intrinsics_gen
PLUGIN_TOOL
opt
)