-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
113 lines (88 loc) · 3.89 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
cmake_minimum_required(VERSION 3.13.4)
project(GrayC)
#===============================================================================
# 0. GET CLANG INSTALLATION DIR
#===============================================================================
# In GrayC, `CT_Clang_INSTALL_DIR` is the key CMake variable - it points
# to a Clang installation directory. We, however, use `LLVM_CONFIG_BINARY` as
# our primary source of truth.
set(LLVM_CONFIG_BINARY "llvm-config" CACHE STRING
"The path to a llvm-config binary which is used to find llvm tooling to duplicate libraries"
)
execute_process(
COMMAND ${LLVM_CONFIG_BINARY} --prefix
OUTPUT_VARIABLE LLVM_DIR
)
string(REGEX REPLACE "\n+$" "" LLVM_DIR "${LLVM_DIR}")
mark_as_advanced(LLVM_DIR)
set(CT_Clang_INSTALL_DIR "${LLVM_DIR}" CACHE PATH
"Clang installation directory"
)
#===============================================================================
# 1. VERIFY CLANG INSTALLATION DIR
#===============================================================================
set(CT_LLVM_INCLUDE_DIR "${CT_Clang_INSTALL_DIR}/include/llvm")
if(NOT EXISTS "${CT_LLVM_INCLUDE_DIR}")
message(FATAL_ERROR
" CT_Clang_INSTALL_DIR (${CT_LLVM_INCLUDE_DIR}) is invalid.")
endif()
set(CT_LLVM_CMAKE_FILE
"${CT_Clang_INSTALL_DIR}/lib/cmake/clang/ClangConfig.cmake")
if(NOT EXISTS "${CT_LLVM_CMAKE_FILE}")
message(FATAL_ERROR
" CT_LLVM_CMAKE_FILE (${CT_LLVM_CMAKE_FILE}) is invalid.")
endif()
#===============================================================================
# 2. LOAD CLANG CONFIGURATION
# Extracted from:
# http://llvm.org/docs/CMake.html#embedding-llvm-in-your-project
#===============================================================================
list(APPEND CMAKE_PREFIX_PATH "${CT_Clang_INSTALL_DIR}/lib/cmake/clang/")
find_package(Clang REQUIRED CONFIG)
# Sanity check. As Clang does not expose e.g. `CLANG_VERSION_MAJOR` through
# AddClang.cmake, we have to use LLVM_VERSION_MAJOR instead.
# TODO: Revisit when next version is released.
if(NOT "12" VERSION_EQUAL "${LLVM_VERSION_MAJOR}")
message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 12")
endif()
message(STATUS "Found Clang ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using ClangConfig.cmake in: ${CT_Clang_INSTALL_DIR}")
message("CLANG STATUS:
Includes (clang) ${CLANG_INCLUDE_DIRS}
Includes (llvm) ${LLVM_INCLUDE_DIRS}"
)
# Set the LLVM and Clang header and library paths
include_directories(SYSTEM "${LLVM_INCLUDE_DIRS};${CLANG_INCLUDE_DIRS}")
#===============================================================================
# 3. GrayC BUILD CONFIGURATION
#===============================================================================
# Use the same C++ standard as LLVM does
set(CMAKE_CXX_STANDARD 17 CACHE STRING "")
# Build type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE
STRING "Build type (default Debug):" FORCE)
endif()
# Compiler flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3 -DDEBUG \
-fdiagnostics-color=always")
# LLVM/Clang is normally built without RTTI. Be consistent with that.
if(NOT LLVM_ENABLE_RTTI)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif()
# -fvisibility-inlines-hidden is set when building LLVM and on Darwin warnings
# are triggered if GrayC is built without this flag (though otherwise it
# builds fine). For consistency, add it here too.
include(CheckCXXCompilerFlag)
link_libraries(stdc++fs)
# Set the build directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
#===============================================================================
# 4. ADD SUB-TARGETS
# Doing this at the end so that all definitions and link/include paths are
# available for the sub-projects.
#===============================================================================
# add_subdirectory(Utils)
add_subdirectory(clang-diff)
add_subdirectory(grayc)