forked from skeru/libVersioningCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
277 lines (218 loc) · 9.8 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
# Copyright 2017 Politecnico di Milano.
# Developed by : Stefano Cherubin, Davide Gadioli
# PhD student, Politecnico di Milano
# <first_name>.<family_name>@polimi.it
#
# This file is part of libVersioningCompiler
#
# libVersioningCompiler is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, either version 3
# of the License, or (at your option) any later version.
#
# libVersioningCompiler is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with libVersioningCompiler. If not, see <http://www.gnu.org/licenses/>
cmake_minimum_required(VERSION 3.0.2)
#----- Set the name of the Version Compiler library
set (VC_LIB_NAME "VersioningCompiler")
###############################################
## Set the library directory ##
###############################################
link_directories( ${CMAKE_CURRENT_BINARY_DIR} )
###############################################
## EXTERNAL LIB ##
###############################################
# Load additional CMake modules
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# DL library
find_package(DL REQUIRED)
include_directories(${DL_INCLUDE_DIR})
link_directories(${DL_LIBRARY})
# The uuuid library
find_package(UUID REQUIRED)
include_directories(${UUID_INCLUDE_DIR})
link_directories(${UUID_LIBRARY})
# LibClang library
find_package(LibClang)
if (HAVE_LIBCLANG)
include_directories(${LIBCLANG_INCLUDES})
link_directories(${LIBCLANG_LIBRARY_DIR})
endif (HAVE_LIBCLANG)
# LLVM library
find_package(LLVM)
if (HAVE_LLVM)
include_directories(${LLVM_INCLUDE_DIR})
link_directories(${LLVM_LIBRARY_DIR})
endif (HAVE_LLVM)
set (LLVM_VERSION_MIN_REQUIRED "6.0.0")
if ( HAVE_LLVM AND
(NOT ( LLVM_VERSION VERSION_LESS LLVM_VERSION_MIN_REQUIRED )) AND
HAVE_LIBCLANG )
set ( ENABLE_CLANG_AS_LIB true )
else()
if (NOT HAVE_LLVM)
message( WARNING "LLVM not detected" )
else(NOT HAVE_LLVM)
if (LLVM_VERSION VERSION_LESS LLVM_VERSION_MIN_REQUIRED)
message( WARNING "You are using an obsolete version of LLVM:\
\n\t${LLVM_VERSION} detected.\t\
Minimum required is ${LLVM_VERSION_MIN_REQUIRED}" )
else(LLVM_VERSION VERSION_LESS LLVM_VERSION_MIN_REQUIRED)
message( WARNING "LibClang not detected" )
endif (LLVM_VERSION VERSION_LESS LLVM_VERSION_MIN_REQUIRED)
endif (NOT HAVE_LLVM)
message( WARNING "Clang-as-a-library will be disabled" )
endif()
set (VC_LIB_DEPS ${DL_LIBRARY}
${UUID_LIBRARY}
)
if (ENABLE_CLANG_AS_LIB)
set (VC_LIB_DEPS ${VC_LIB_DEPS}
${LIBCLANG_LIBRARIES}
${LLVM_MODULE_LIBS}
${LLVM_SYSTEM}
)
set ( VC_DEPS_EXTRA_LINK_FLAGS "${LLVM_LFLAGS}" )
endif (ENABLE_CLANG_AS_LIB)
list ( REMOVE_DUPLICATES VC_LIB_DEPS )
###############################################
## LIBRARY ##
###############################################
if (NOT CMAKE_BUILD_TYPE)
message ("No build type detected. Build type set to Release by default")
set ( CMAKE_BUILD_TYPE Release )
endif()
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -ldl -fno-use-cxa-atexit" )
set ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DVC_DEBUG -fno-rtti -fno-use-cxa-atexit" )
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -fPIC -fno-rtti -fno-use-cxa-atexit" )
#----- Sources
set ( SRC_PREFIX "lib" )
set ( VC_LIB_SRC
${SRC_PREFIX}/Version.cpp
${SRC_PREFIX}/Option.cpp
${SRC_PREFIX}/Compiler.cpp
${SRC_PREFIX}/CompilerImpl/SystemCompiler.cpp
${SRC_PREFIX}/CompilerImpl/SystemCompilerOptimizer.cpp
)
#----- Headers
set ( VC_LIB_HDR_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/include/versioningCompiler )
set ( VC_LIB_HDR1
${VC_LIB_HDR_PREFIX}/Version.hpp
${VC_LIB_HDR_PREFIX}/Option.hpp
${VC_LIB_HDR_PREFIX}/Compiler.hpp
${VC_LIB_HDR_PREFIX}/Utils.hpp
${VC_LIB_HDR_PREFIX}/DebugUtils.hpp
${VC_LIB_HDR_PREFIX}/JITUtils.hpp
)
set ( VC_LIB_HDR_PREFIX2 ${CMAKE_CURRENT_SOURCE_DIR}/include/versioningCompiler/CompilerImpl )
set ( VC_LIB_HDR2
${VC_LIB_HDR_PREFIX2}/SystemCompiler.hpp
${VC_LIB_HDR_PREFIX2}/SystemCompilerOptimizer.hpp
)
#----- Additionl files to enable Clang-as-a-library
if (ENABLE_CLANG_AS_LIB)
set_source_files_properties(${VC_LIB_HDR_PREFIX}/Features.hpp PROPERTIES
COMPILE_FLAGS "-DENABLE_CLANG_AS_LIB=true"
)
set (VC_LIB_SRC ${VC_LIB_SRC}
${SRC_PREFIX}/CompilerImpl/JITCompiler.cpp
${SRC_PREFIX}/CompilerImpl/ClangLibCompiler.cpp
${SRC_PREFIX}/CompilerImpl/ClangLLVM/FileLogDiagnosticConsumer.cpp
${SRC_PREFIX}/CompilerImpl/ClangLLVM/LLVMInstanceManager.cpp
)
set ( VC_LIB_HDR2 ${VC_LIB_HDR2}
${VC_LIB_HDR_PREFIX2}/JITCompiler.hpp
${VC_LIB_HDR_PREFIX2}/ClangLibCompiler.hpp
)
set ( VC_LIB_HDR_PREFIX3 ${CMAKE_CURRENT_SOURCE_DIR}/include/versioningCompiler/CompilerImpl/ClangLLVM )
set ( VC_LIB_HDR3
${VC_LIB_HDR_PREFIX3}/OptUtils.hpp
${VC_LIB_HDR_PREFIX3}/FileLogDiagnosticConsumer.hpp
${VC_LIB_HDR_PREFIX3}/LLVMInstanceManager.hpp
)
endif(ENABLE_CLANG_AS_LIB)
set (VC_LIB_HDR ${VC_LIB_HDR1} ${VC_LIB_HDR2} ${VC_LIB_HDR3} )
#----- setup library
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/include )
add_library( ${VC_LIB_NAME} STATIC ${VC_LIB_SRC} ${VC_LIB_HDR} )
target_link_libraries( ${VC_LIB_NAME} ${VC_LIB_DEPS} z pthread tinfo)
###############################################
## CONFIGURE ##
###############################################
set (FIND_LIBVC_OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/config/FindLibVersioningCompiler.cmake")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/config/FindLibVersioningCompiler.cmake.in"
"${FIND_LIBVC_OUTPUT}"
@ONLY
)
###############################################
## INSTALL LIBRARY VC ##
###############################################
install( TARGETS ${VC_LIB_NAME} DESTINATION lib )
install( FILES ${VC_LIB_HDR1} DESTINATION include/versioningCompiler )
install( FILES ${VC_LIB_HDR2} DESTINATION include/versioningCompiler/CompilerImpl )
install( FILES ${FIND_LIBVC_OUTPUT} DESTINATION lib/cmake )
if (ENABLE_CLANG_AS_LIB)
install( FILES ${VC_LIB_HDR3} DESTINATION include/versioningCompiler/CompilerImpl/ClangLLVM )
endif (ENABLE_CLANG_AS_LIB)
###############################################
## TEST APP ##
###############################################
## TestJit.cpp
#----- Sources
set (VC_TESTJIT_APP_SRC TestJit.cpp)
set (VC_EXE_NAME libVC_testJit)
if (ENABLE_CLANG_AS_LIB)
set_source_files_properties(${VC_TESTJIT_APP_SRC} PROPERTIES
COMPILE_FLAGS "-fno-use-cxa-atexit -flto -DHAVE_CLANG_AS_LIB -DFORCED_PATH_TO_TEST=\\\"${CMAKE_CURRENT_SOURCE_DIR}/test_code\\\""
)
else (ENABLE_CLANG_AS_LIB)
set_source_files_properties(${VC_TESTJIT_APP_SRC} PROPERTIES
COMPILE_FLAGS "-fno-use-cxa-atexit -flto -DFORCED_PATH_TO_TEST=\\\"${CMAKE_CURRENT_SOURCE_DIR}/test_code\\\""
)
endif (ENABLE_CLANG_AS_LIB)
add_executable(${VC_EXE_NAME} ${VC_TESTJIT_APP_SRC})
link_directories(${LLVM_LIBRARY_DIR} ${LIBCLANG_LIBRARY_DIR} "${CMAKE_INSTALL_PREFIX}/lib")
target_link_libraries(${VC_EXE_NAME} ${VC_LIB_NAME} ${VC_LIB_DEPS})
## Test.cpp
#----- Sources
set ( VC_TEST_APP_SRC Test.cpp )
set ( VC_EXE_NAME libVC_test )
if (ENABLE_CLANG_AS_LIB)
set_source_files_properties(${VC_TEST_APP_SRC} PROPERTIES
COMPILE_FLAGS "-flto -DHAVE_CLANG_AS_LIB -DFORCED_PATH_TO_TEST=\\\"${CMAKE_CURRENT_SOURCE_DIR}/test_code\\\""
)
else (ENABLE_CLANG_AS_LIB)
set_source_files_properties(${VC_TEST_APP_SRC} PROPERTIES
COMPILE_FLAGS "-flto -DFORCED_PATH_TO_TEST=\\\"${CMAKE_CURRENT_SOURCE_DIR}/test_code\\\""
)
endif (ENABLE_CLANG_AS_LIB)
add_executable(${VC_EXE_NAME} ${VC_TEST_APP_SRC})
link_directories(${LLVM_LIBRARY_DIR} ${LIBCLANG_LIBRARY_DIR} "${CMAKE_INSTALL_PREFIX}/lib")
target_link_libraries(${VC_EXE_NAME} ${VC_LIB_NAME} ${VC_LIB_DEPS})
## testUtils.cpp
#----- Sources
set ( VC_TEST2_APP_SRC TestUtils.cpp )
set ( VC_EXE2_NAME libVC_testUtils )
if (ENABLE_CLANG_AS_LIB)
set_source_files_properties(${VC_TEST2_APP_SRC} PROPERTIES
COMPILE_FLAGS "-flto -DHAVE_CLANG_AS_LIB -DFORCED_PATH_TO_TEST=\\\"${CMAKE_CURRENT_SOURCE_DIR}/test_code\\\""
)
else (ENABLE_CLANG_AS_LIB)
set_source_files_properties(${VC_TEST2_APP_SRC} PROPERTIES
COMPILE_FLAGS "-flto -DFORCED_PATH_TO_TEST=\\\"${CMAKE_CURRENT_SOURCE_DIR}/test_code\\\""
)
endif (ENABLE_CLANG_AS_LIB)
add_executable(${VC_EXE2_NAME} ${VC_TEST2_APP_SRC})
link_directories(${LLVM_LIBRARY_DIR} ${LIBCLANG_LIBRARY_DIR} "${CMAKE_INSTALL_PREFIX}/lib")
target_link_libraries(${VC_EXE2_NAME} ${VC_LIB_NAME} ${VC_LIB_DEPS})
###############################################
## INSTALL TEST BIN ##
###############################################
install( TARGETS ${VC_EXE_NAME} DESTINATION bin/test )
install( TARGETS ${VC_EXE2_NAME} DESTINATION bin/test )