forked from prajna-lang/prajna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
105 lines (86 loc) · 4.11 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
cmake_minimum_required(VERSION 3.14)
project(prajna CXX C)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # 用于智能提示
set(CMAKE_CXX_STANDARD 17) # c++20目前系统库还不支持, 没有必要
set(CXX_STANDARD_REQUIRED ON) # 若不支持c++17选项则报错,而不是使用c++14
set(CMAKE_CXX_EXTENSIONS OFF) # 使用 -std=c++17而不是 -std=gnu++17
# 在mac平台下, 因为llvm设置为hidden,所以避免编译warning这里全局设置为hidden
# 之所以不用target_link_options设置,是因为其不能设置第三方项目
if (NOT BUILD_SHARED_LIBS)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
else()
# 没有找到动态库的warning消除方法
endif()
set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
if (UNIX AND NOT APPLE)
# llvm compiler-rt不支持"Linux", 所以需要改为"linxu-gnu"
set(CMAKE_SYSTEM_NAME "linux-gnu")
# llvm compiler-rt需要, 交叉编译需要重新设置
set(CMAKE_C_COMPILER_TARGET "${CMAKE_SYSTEM_PROCESSOR}-unknown-${CMAKE_SYSTEM_NAME}")
# 不可设置C++的, 会导致头文件找不到
# set(CMAKE_CXX_COMPILER_TARGET "${CMAKE_SYSTEM_PROCESSOR}-unknown-${CMAKE_SYSTEM_NAME}")
message("prajna build target triple: ${CMAKE_C_COMPILER_TARGET}")
set(COMPILER_RT_DEFAULT_TARGET_ONLY ON)
set(COMPILER_RT_BUILD_BUILTINS ON)
set(COMPILER_RT_BUILTINS_HIDE_SYMBOLS Off)
endif()
find_package(OpenSSL REQUIRED)
add_subdirectory(third_party/llvm-project/llvm EXCLUDE_FROM_ALL)
# 需要手动添加llvm的头文件路径
add_library(llvm_include_dir INTERFACE)
target_include_directories(llvm_include_dir
INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/third_party/llvm-project/llvm/include>
$<INSTALL_INTERFACE:include>
INTERFACE
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/third_party/llvm-project/llvm/include>
$<INSTALL_INTERFACE:include>
)
add_dependencies(llvm_include_dir intrinsics_gen)
add_subdirectory(third_party/boost EXCLUDE_FROM_ALL)
add_subdirectory(third_party/cxxopts EXCLUDE_FROM_ALL)
add_subdirectory(third_party/fmt EXCLUDE_FROM_ALL)
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
add_subdirectory(third_party/googletest EXCLUDE_FROM_ALL)
add_subdirectory(third_party/cpp-terminal EXCLUDE_FROM_ALL)
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)
option(BUILD_SHARED_LIBS "Build shared libs" OFF) # 需要加入, 否则其并不是一个option
option(PRAJNA_BUILD_TOOLS "Build Prajna tools" ON)
option(PRAJNA_BUILD_EXAMPLES "Build Prajna examples" ON)
option(PRAJNA_BUILD_TESTS "Build Prajna tests" ON)
option(PRAJNA_WITH_JUPYTER "Build Jupyter Xeus Prajna" ON)
option(PRAJNA_ENABLE_SANITIZE "Enable Prajna address sanitize" OFF)
option(PRAJNA_ENABLE_LLVM_DUMP "Enable Prajna LLVM dump" OFF)
option(PRAJNA_ENABLE_LLVM_VERIFY "Enable Prajna LLVM verify" OFF)
option(PRAJNA_DISABLE_ASSERTS "Disable Prajna ASSERTS" OFF)
add_subdirectory(prajna)
if (PRAJNA_WITH_JUPYTER)
add_subdirectory(xeus_prajna)
endif()
if (PRAJNA_BUILD_TESTS)
add_subdirectory(tests)
endif()
if (PRAJNA_BUILD_TOOLS)
# nlohmann_json会在xeus_prajna里被加入, 所以需要判断
if (NOT TARGET nlohmann_json)
add_subdirectory(xeus_prajna/third_party/json EXCLUDE_FROM_ALL)
endif()
add_subdirectory(tools)
endif()
add_subdirectory(examples_in_cpp)
include(CMakePackageConfigHelpers)
install(TARGETS prajna EXPORT ${PROJECT_NAME}-targets)
install(TARGETS llc EXPORT ${PROJECT_NAME}-targets)
install(TARGETS llc RUNTIME DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
# install(TARGETS prajna_shared EXPORT ${PROJECT_NAME}-targets)
# xeus_prajna依赖
install(TARGETS nlohmann_json EXPORT ${PROJECT_NAME}-targets)
install(DIRECTORY builtin_packages DESTINATION ${CMAKE_INSTALL_PREFIX})
install(DIRECTORY dockerfiles DESTINATION ${CMAKE_INSTALL_PREFIX})
install(DIRECTORY docs DESTINATION ${CMAKE_INSTALL_PREFIX})
install(DIRECTORY examples DESTINATION ${CMAKE_INSTALL_PREFIX})
install(FILES prajna/compiler/compiler.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include)