-
Notifications
You must be signed in to change notification settings - Fork 15
/
CMakeLists.txt
62 lines (49 loc) · 2.19 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
cmake_minimum_required(VERSION 3.10.0)
project(canary C CXX)
option(LLVM_CONFIG_PATH "Path to llvm-config executable" "")
unset(LLVMCONFIG CACHE)
if (LLVM_CONFIG_PATH)
set(LLVMCONFIG "${LLVM_CONFIG_PATH}")
else()
find_program(LLVMCONFIG llvm-config)
if (NOT LLVMCONFIG)
message(FATAL_ERROR "llvm-config not found!")
endif()
endif()
execute_process(
COMMAND ${LLVMCONFIG} --version
OUTPUT_VARIABLE LLVM_VERSION_OUTPUT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (LLVM_VERSION_OUTPUT MATCHES "^([0-9]+)")
set(LLVM_MAJOR_VERSION "${CMAKE_MATCH_1}")
else()
message(FATAL_ERROR "Failed to parse LLVM version from: ${LLVM_VERSION_OUTPUT}")
endif()
if (LLVM_MAJOR_VERSION STREQUAL "12")
message(STATUS "Using LLVM version 12")
add_definitions(-DLLVM12)
elseif (LLVM_MAJOR_VERSION STREQUAL "14")
message(STATUS "Using LLVM version 14")
add_definitions(-DLLVM14)
else()
message(FATAL_ERROR "Unsupported or unknown LLVM version: ${LLVM_VERSION_OUTPUT}")
endif()
execute_process(COMMAND ${LLVMCONFIG} --cxxflags OUTPUT_VARIABLE CMAKE_CXX_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVMCONFIG} --cflags OUTPUT_VARIABLE CMAKE_C_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVMCONFIG} --cppflags OUTPUT_VARIABLE CMAKE_CPP_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVMCONFIG} --ldflags OUTPUT_VARIABLE CMAKE_EXE_LINKER_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVMCONFIG} --system-libs OUTPUT_VARIABLE LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${LLVMCONFIG} --includedir OUTPUT_VARIABLE LLVM_INCLUDE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LIBS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
include_directories(${LLVM_INCLUDE_DIRS})
include_directories(AFTER ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_subdirectory(lib)
add_subdirectory(tools)
add_subdirectory(benchmarks)