-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
216 lines (190 loc) · 6.75 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
project(dachs)
set(DACHS_VERSION_MAJOR 0)
set(DACHS_VERSION_MINOR 0)
set(DACHS_VERSION_TEENY 1)
set(PACKAGE_VERSION "${DACHS_VERSION_MAJOR}.${DACHS_VERSION_MINOR}.${DACHS_VERSION_TEENY}")
cmake_minimum_required(VERSION 2.8.8)
enable_testing()
# Detect commands {{{
if (DACHS_CXX_COMPILER)
if (NOT DACHS_LLVM_CONFIG)
message(FATAL_ERROR "Set -DDACHS_LLVM_CONFIG to specify the path to your llvm-config command.")
endif ()
set(CMAKE_CXX_COMPILER "${DACHS_CXX_COMPILER}")
message(STATUS "${CMAKE_CXX_COMPILER} is specified.")
else ()
message(STATUS "Detecting a compiler for Dachs...")
if (EXISTS "/usr/local/bin/clang++-3.5")
set(CMAKE_CXX_COMPILER "/usr/local/bin/clang++-3.5")
set(DACHS_CLANG_SUFFIX "-3.5")
elseif (EXISTS "/usr/local/bin/clang++-3.4")
set(CMAKE_CXX_COMPILER "/usr/local/bin/clang++-3.4")
set(DACHS_CLANG_SUFFIX "-3.4")
elseif (EXISTS "/usr/bin/clang++-3.5")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++-3.5")
set(DACHS_CLANG_SUFFIX "-3.5")
elseif (EXISTS "/usr/bin/clang++-3.4")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++-3.4")
set(DACHS_CLANG_SUFFIX "-3.4")
elseif (EXISTS "/usr/bin/clang++")
set(CMAKE_CXX_COMPILER "/usr/bin/clang++")
set(DACHS_CLANG_SUFFIX "")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
set(DACHS_CLANG_SUFFIX "")
else ()
message(FATAL_ERROR "Clang is not found. Set -DCMAKE_CXX_COMPILER option.")
endif ()
message(STATUS "${CMAKE_CXX_COMPILER} is detected.")
endif ()
if (NOT DACHS_LLVM_CONFIG)
set(DACHS_LLVM_CONFIG "llvm-config${DACHS_CLANG_SUFFIX}")
if (EXISTS "/usr/bin/${DACHS_LLVM_CONFIG}")
set(DACHS_LLVM_CONFIG "/usr/bin/${DACHS_LLVM_CONFIG}")
elseif (EXISTS "/usr/local/bin/${DACHS_LLVM_CONFIG}")
set(DACHS_LLVM_CONFIG "/usr/local/bin/${DACHS_LLVM_CONFIG}")
else ()
message(FATAL_ERROR "'${DACHS_LLVM_CONFIG}' command is not found. Set -DDACHS_LLVM_CONFIG option.")
endif ()
message(STATUS "${DACHS_LLVM_CONFIG} is detected.")
else ()
if (NOT EXISTS "${DACHS_LLVM_CONFIG}")
message(FATAL_ERROR "'${DACHS_LLVM_CONFIG}' command is not found. Set -DDACHS_LLVM_CONFIG option properly.")
endif ()
endif ()
# }}}
# Detect libgc {{{
if (NOT DACHS_LIBGC_PATH)
find_path(LIBGC_INCLUDE_DIR gc.h)
if (NOT IS_DIRECTORY "${LIBGC_INCLUDE_DIR}/../lib")
message(FATAL_ERROR "The path to libgc can't be detected. Set -DDACHS_LIBGC_PATH option properly.")
endif()
set(DACHS_LIBGC_PATH "${LIBGC_INCLUDE_DIR}/../lib")
message(STATUS "Detected libgc: ${DACHS_LIBGC_PATH}")
else ()
if (NOT IS_DIRECTORY ${DACHS_LIBGC_PATH})
message(FATAL_ERROR "'${DACHS_LIBGC_PATH}' directory is not found. Set -DDACHS_LIBGC_PATH option properly.")
endif()
endif ()
# }}}
# LLVM configurations {{{
execute_process(
COMMAND
${DACHS_LLVM_CONFIG} --version
OUTPUT_VARIABLE
LLVM_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND
${DACHS_LLVM_CONFIG} --includedir
OUTPUT_VARIABLE
LLVM_INCLUDE_DIRS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND
${DACHS_LLVM_CONFIG} --libdir
OUTPUT_VARIABLE
LLVM_LIBRARY_DIRS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND
${DACHS_LLVM_CONFIG} --libnames
OUTPUT_VARIABLE
LLVM_LIBRARY_NAMES_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX REPLACE " +" ";" LLVM_LIBRARY_NAMES ${LLVM_LIBRARY_NAMES_STRING})
string(REGEX REPLACE "lib([^.]*)\\.a" "\\1" LLVM_LIBRARY_NAMES ${LLVM_LIBRARY_NAMES})
execute_process(
COMMAND
${DACHS_LLVM_CONFIG} --components
OUTPUT_VARIABLE
LLVM_COMPONENTS_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX MATCHALL "([^ ]+)" LLVM_COMPONENTS ${LLVM_COMPONENTS_STRING})
set(DACHS_LLVM_COMPONENTS
core
support
native
asmparser
asmprinter
ipo
)
foreach (c ${DACHS_LLVM_COMPONENTS})
list(FIND LLVM_COMPONENTS ${c} found)
if (found EQUAL -1)
message(FATAL_ERROR "LLVM component '${c}' is not supported.")
endif ()
endforeach (c)
execute_process(
COMMAND
${DACHS_LLVM_CONFIG} --ldflags
OUTPUT_VARIABLE
LLVM_SYS_LIBS_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX MATCHALL "-l([^ ]+)" LLVM_SYS_LIBS ${LLVM_SYS_LIBS_STRING})
# In Ubuntu, somehow references to LLVM objects are not found in static link libraries.
# Because of workaround for this, use shared library if DACHS_USE_LLVM_SHARED_LIB is specified
if(DACHS_USE_LLVM_SHARED_LIB)
foreach(l "LLVM" "LLVM-3.4" "LLVM-3.5")
if (EXISTS "${LLVM_LIBRARY_DIRS}/lib${l}.so")
set(LLVM_LIBS ${l})
break()
endif ()
endforeach(l)
else()
execute_process(
COMMAND
${DACHS_LLVM_CONFIG} --libs ${DACHS_LLVM_COMPONENTS}
OUTPUT_VARIABLE
LLVM_LIBS_STRING
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX MATCHALL "-l([^ ]+)" LLVM_LIBS ${LLVM_LIBS_STRING})
endif()
set(REQUIRED_LLVM_LIBRARIES)
foreach (l ${LLVM_LIBS} ${LLVM_SYS_LIBS})
string(REGEX REPLACE "-l([^ ]+)" "\\1" lib_name ${l})
list(APPEND REQUIRED_LLVM_LIBRARIES ${lib_name})
endforeach (l)
# Check libraries which LLVM depends on
if (CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin")
list(APPEND REQUIRED_LLVM_LIBRARIES "z" "pthread" "dl" "curses")
else ()
# FIXME
message(FATAL_ERROR "Currently, your platform ${CMAKE_SYSTEM_NAME} is not supported...")
endif ()
include_directories(${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
message(STATUS "LLVM version : ${LLVM_VERSION}")
message(STATUS "LLVM includedir : ${LLVM_INCLUDE_DIRS}")
message(STATUS "LLVM libdir : ${LLVM_LIBRARY_DIRS}")
set(LLVM_DEFINITIONS
-D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS
)
set(DACHS_DEFINITIONS
-DDACHS_CXX_COMPILER="${CMAKE_CXX_COMPILER}" -DDACHS_INSTALL_PREFIX="${CMAKE_INSTALL_PREFIX}" -DDACHS_LIBGC_PATH="${DACHS_LIBGC_PATH}"
)
add_definitions(${LLVM_DEFINITIONS})
add_definitions(${DACHS_DEFINITIONS})
# }}}
include_directories("${PROJECT_SOURCE_DIR}/src")
include_directories("${PROJECT_SOURCE_DIR}/runtime/src")
find_package(Boost 1.55.0)
include_directories(${Boost_INCLUDE_DIRS})
add_definitions(-std=c++1y -Wall -Wextra)
set(CMAKE_CXX_FLAGS_RELEASE "-DNDEBUG -O3")
set(CMAKE_CXX_FLAGS_DEBUG "-g")
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." FORCE)
message(STATUS "Dachs is under development. 'Debug' is set to $CMAKE_BUILD_TYPE as default.")
add_definitions("${CMAKE_CXX_FLAGS_DEBUG}")
endif ()
add_subdirectory(src)
add_subdirectory(runtime)
add_subdirectory(lib)
add_subdirectory(test)