-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathCMakeLists.txt
528 lines (455 loc) · 22.1 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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# Do not depend on CMake scripts from the rest of the ROOT build
set(CMAKE_MODULE_PATH "")
#--- Check if we need to build llvm and clang ------------------------------------------------------
if (builtin_llvm AND NOT builtin_clang)
message(FATAL_ERROR "Cannot enable builtin LLVM, but provide external Clang")
endif()
if (NOT builtin_clang)
message(WARNING "Due to ROOT-specific patches you need a special version of clang. You cannot use vanilla clang.")
endif()
#--Set the LLVM version required for ROOT-----------------------------------------------------------
set(ROOT_LLVM_VERSION_REQUIRED_MAJOR 18)
#---Define the way we want to build and what of llvm/clang/cling------------------------------------
set(LLVM_ENABLE_RTTI ON CACHE BOOL "")
set(LLVM_APPEND_VC_REV OFF CACHE BOOL "")
set(LLVM_ENABLE_BINDINGS OFF CACHE BOOL "")
set(LLVM_ENABLE_FFI OFF CACHE BOOL "")
set(LLVM_ENABLE_OCAMLDOC OFF CACHE BOOL "")
set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "")
set(LLVM_ENABLE_WARNINGS OFF CACHE BOOL "")
set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "")
set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "")
set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "")
set(LLVM_INCLUDE_BENCHMARKS OFF CACHE BOOL "")
set(CLANG_INCLUDE_TESTS OFF CACHE BOOL "")
set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "")
set(CLANG_BUILD_TOOLS OFF CACHE BOOL "")
# It looks like that turning off CLANG_BUILD_TOOLS is not enough.
set(CLANG_TOOL_ARCMT_TEST_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_CLANG_CHECK_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_CLANG_FORMAT_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_CLANG_FORMAT_VS_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_CLANG_FUZZER_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_CLANG_IMPORT_TEST_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_CLANG_OFFLOAD_BUNDLER_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_CLANG_RENAME_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_C_ARCMT_TEST_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_C_INDEX_TEST_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_DIAGTOOL_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_LIBCLANG_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_SCAN_BUILD_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_SCAN_VIEW_BUILD OFF CACHE BOOL "")
set(LLVM_BUILD_TOOLS OFF CACHE BOOL "")
set(LLVM_TOOL_LLVM_AR_BUILD OFF CACHE BOOL "")
set(CLANG_TOOL_CLANG_OFFLOAD_BUNDLER_BUILD OFF CACHE BOOL "")
set(LLVM_FORCE_USE_OLD_TOOLCHAIN ON CACHE BOOL "")
# Prevent Clang from finding CUDA just to determine the architecture for OpenMP
# offloading, which we are not interested in. If the CUDA package was already
# found before (because the user turned on cuda or tmva-gpu), this will not have
# an effect, which is fine.
# (Note that the option is very counter-intuitive: We turn *on* disabling it...)
set(CMAKE_DISABLE_FIND_PACKAGE_CUDA ON)
# will be set again in case NOT builtin_llvm
set(LLVM_DIR "${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm")
if (clad)
set(CLING_BUILD_PLUGINS ON)
endif()
# We only use llvm/clang through TCling which is (with the help of core/meta) already taking a lock
# to serialize access to llvm. We can later review how to make this finer grained by using llvm's own locking
# mechanism.
set(LLVM_ENABLE_THREADS OFF CACHE BOOL "")
set(CMAKE_REQUIRED_QUIET 1) # Make the configuration of LLVM quiet
if(ROOT_ARCHITECTURE MATCHES arm64)
set(ROOT_CLING_TARGET "AArch64")
elseif(ROOT_ARCHITECTURE MATCHES arm)
set(ROOT_CLING_TARGET "ARM")
elseif(ROOT_ARCHITECTURE MATCHES ppc64)
set(ROOT_CLING_TARGET "PowerPC")
elseif(ROOT_ARCHITECTURE MATCHES s390)
set(ROOT_CLING_TARGET "SystemZ")
elseif(ROOT_ARCHITECTURE MATCHES riscv64)
set(ROOT_CLING_TARGET "RISCV")
elseif(ROOT_ARCHITECTURE MATCHES loong64)
set(ROOT_CLING_TARGET "LoongArch")
elseif(ROOT_ARCHITECTURE MATCHES freebsd OR ROOT_ARCHITECTURE MATCHES linux OR ROOT_ARCHITECTURE MATCHES macosx)
set(ROOT_CLING_TARGET "X86")
elseif(ROOT_ARCHITECTURE MATCHES win32 OR ROOT_ARCHITECTURE MATCHES win64)
set(ROOT_CLING_TARGET "X86")
else()
set(ROOT_CLING_TARGET "all")
endif()
if(NOT "${ROOT_CLING_TARGET}" STREQUAL "all")
string(APPEND ROOT_CLING_TARGET ";NVPTX")
endif()
if(MSVC)
# FIXME: since Visual Studio v16.4.0 the /O2 optimization flag make many (25%) of the tests failing
# Try to re-enable /O2 after the upgrade of llvm & clang
if (MSVC_VERSION GREATER_EQUAL 1924 AND MSVC_VERSION LESS 1929)
string(REPLACE "-O2" "-O1 -Oi" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
string(REPLACE "-O2" "-O1 -Oi" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
endif()
# replace dashes in the -EH* and -GR* flags with slashes (/EH* /GR*)
string(REPLACE " -EH" " /EH" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE " -GR" " /GR" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4049,4206,4217,4221")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /ignore:4049,4206,4217,4221")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /ignore:4049,4206,4217,4221")
endif()
set(LLVM_TARGETS_TO_BUILD ${ROOT_CLING_TARGET} CACHE STRING "Semicolon-separated list of targets to build, or \"all\".")
if(clingtest)
message("-- cling test suite enabled: llvm / clang symbols in libCling will be visible!")
set(CLING_INCLUDE_TESTS ON CACHE BOOL "" FORCE)
# The path to cling passed through environment variable only relevant when building
# against external llvm. In that case, cling's testsuite cannot deduce the binary
# of cling relatively to the llvm tools folder.
if (NOT builtin_llvm)
set(CLINGTEST_EXECUTABLE CLING=${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm/${CMAKE_CFG_INTDIR}/bin/cling)
endif()
ROOT_ADD_TEST(clingtest-check-cling COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target check-cling
ENVIRONMENT ${CLINGTEST_EXECUTABLE})
else()
#---Build LLVM/Clang with symbol visibility=hidden--------------------------------------------------
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_C_VISIBILITY_PRESET hidden)
endif()
if (NOT MSVC AND NOT APPLE)
# Requires the linker to resolve the symbol internally and prevents
# conflicts when linked with another software using also LLVM like in
# the problem reported for Julia in
# https://github.com/JuliaHEP/ROOT.jl/issues/17#issuecomment-882719292
# Only needed for Linux: Mac uses linker namespaces and Windows explicit export/import
string(APPEND CMAKE_SHARED_LINKER_FLAGS " -Wl,-Bsymbolic")
ROOT_ADD_CXX_FLAG(CMAKE_CXX_FLAGS "-fno-semantic-interposition")
endif()
set(CMAKE_VISIBILITY_INLINES_HIDDEN "ON")
if(gcctoolchain)
ROOT_ADD_CXX_FLAG(CMAKE_CXX_FLAGS --gcc-toolchain=${gcctoolchain})
endif()
# We will not fix llvm or clang.
string(REPLACE "-Werror " "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ")
# Turn off coverage - we don't need this for llvm.
string(REPLACE "${GCC_COVERAGE_COMPILE_FLAGS}" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
if(LLVM_SHARED_LINKER_FLAGS)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LLVM_SHARED_LINKER_FLAGS}")
endif()
if(LLVM_EXE_LINKER_FLAGS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${LLVM_EXE_LINKER_FLAGS}")
endif()
# Explicitly disable -Wmisleading-indentation for GCC: Some LLVM source files
# are too large.
set(cxx_flags_prev ${CMAKE_CXX_FLAGS})
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-misleading-indentation")
endif()
if(builtin_llvm)
# Since debug builds of LLVM are quite large, we want to be able
# to control the build types of ROOT and LLVM independently. The
# logic below is to make that possible. LLVM is built in Release
# mode unless a different build type is chosen via LLVM_BUILD_TYPE.
if(NOT DEFINED LLVM_BUILD_TYPE)
set(LLVM_BUILD_TYPE Release CACHE STRING "Build type used for LLVM")
endif()
message(STATUS "Building LLVM in '${LLVM_BUILD_TYPE}' mode.")
if(NOT DEFINED LLVM_ENABLE_ASSERTIONS)
if(CMAKE_BUILD_TYPE MATCHES "Debug"
OR LLVM_BUILD_TYPE MATCHES "(Debug|RelWithDebInfo)")
set(LLVM_ENABLE_ASSERTIONS TRUE)
else()
set(LLVM_ENABLE_ASSERTIONS FALSE)
endif()
endif()
# Multi-configuration generators ignore CMAKE_BUILD_TYPE, so
# in that case we set the flags for all configurations to the
# flags of the build type assigned to LLVM_BUILD_TYPE.
if(MSVC OR XCODE)
string(TOUPPER ${LLVM_BUILD_TYPE} LLVM_BUILD_TYPE)
set(LLVM_C_FLAGS ${CMAKE_C_FLAGS_${LLVM_BUILD_TYPE}})
set(LLVM_CXX_FLAGS ${CMAKE_CXX_FLAGS_${LLVM_BUILD_TYPE}})
# On Windows, use the same compiler flags than ROOT and not
# the other way around
if(NOT MSVC)
foreach(CONFIG ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${CONFIG} CONFIG)
set(CMAKE_C_FLAGS_${CONFIG} ${LLVM_C_FLAGS})
set(CMAKE_CXX_FLAGS_${CONFIG} ${LLVM_CXX_FLAGS})
endforeach()
endif()
elseif(NOT LLVM_BUILD_TYPE STREQUAL CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${LLVM_BUILD_TYPE})
endif()
set(BUILD_SHARED_LIBS FALSE)
#---Remove the inherited include_directories()
set_directory_properties(PROPERTIES INCLUDE_DIRECTORIES "")
set(LLVM_ENABLE_PROJECTS "clang" CACHE STRING "")
#---Reduce log level to suppress STATUS messages from LLVM
if(NOT DEFINED CMAKE_MESSAGE_LOG_LEVEL)
set(CMAKE_MESSAGE_LOG_LEVEL "NOTICE")
set(_unset_log_level TRUE)
endif()
#---Add the sub-directory excluding all the targets from all-----------------------------------------
if(CMAKE_GENERATOR MATCHES "Xcode")
add_subdirectory(llvm-project/llvm)
else()
add_subdirectory(llvm-project/llvm EXCLUDE_FROM_ALL)
endif()
if(DEFINED _unset_log_level)
unset(CMAKE_MESSAGE_LOG_LEVEL)
endif()
set(LLVM_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/llvm-project/llvm/include
${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm/include
CACHE STRING "LLVM include directories."
)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/llvm-project/llvm/cmake/modules")
#---Set into parent scope LLVM_VERSION_MAJOR --------------------------------------------------------
get_directory_property(_llvm_version_major DIRECTORY llvm-project/llvm DEFINITION LLVM_VERSION_MAJOR)
set(LLVM_VERSION_MAJOR "${_llvm_version_major}" PARENT_SCOPE)
#---Forward LLVM_TARGET_TRIPLE for check-cling-------------------------------------------------------
get_directory_property(LLVM_TARGET_TRIPLE DIRECTORY llvm-project/llvm DEFINITION LLVM_TARGET_TRIPLE)
#---Get back the potentially updated LLVM_TARGETS_TO_BUILD (expanding all/host/Native)---------------
get_directory_property(LLVM_TARGETS_TO_BUILD DIRECTORY llvm-project/llvm DEFINITION LLVM_TARGETS_TO_BUILD)
if(MSVC)
if(CMAKE_GENERATOR MATCHES Ninja)
set(LLVM_TABLEGEN_EXE "${LLVM_BINARY_DIR}/bin/llvm-tblgen.exe")
else()
set(LLVM_TABLEGEN_EXE "${LLVM_BINARY_DIR}/$<CONFIG>/bin/llvm-tblgen.exe")
endif()
else()
set(LLVM_TABLEGEN_EXE "${LLVM_BINARY_DIR}/bin/llvm-tblgen")
endif()
else()
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION} in ${LLVM_CMAKE_DIR}")
separate_arguments(LLVM_DEFINITIONS_LIST NATIVE_COMMAND ${LLVM_DEFINITIONS})
add_definitions(${LLVM_DEFINITIONS_LIST})
include_directories(${LLVM_INCLUDE_DIRS})
# Make some LLVM variables globally available.
set(LLVM_INCLUDE_DIRS ${LLVM_INCLUDE_DIRS} CACHE PATH "Path to llvm/include")
set(LLVM_LIBRARY_DIR ${LLVM_LIBRARY_DIR} CACHE PATH "Path to llvm/lib")
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR}
NO_DEFAULT_PATH)
# We already FORCE-d the CACHE value to OFF, but LLVMConfig.cmake might have
# set the variable to ON again...
set(LLVM_ENABLE_WARNINGS OFF)
# They are used as destination of target generators.
# We try to keep these locations consistent with the builtin_llvm. This is important
# for the LLVMRES target.
# FIXME: In longer term, we do not really need this and may want to adjust LLVMRES.
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm/${CMAKE_CFG_INTDIR}/bin)
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_CURRENT_BINARY_DIR}/llvm-project/llvm/${CMAKE_CFG_INTDIR}/lib)
if(WIN32 OR CYGWIN)
# DLL platform -- put DLLs into bin.
set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_RUNTIME_OUTPUT_INTDIR})
else()
set(LLVM_SHLIB_OUTPUT_INTDIR ${LLVM_LIBRARY_OUTPUT_INTDIR})
endif()
option(LLVM_INSTALL_TOOLCHAIN_ONLY
"Only include toolchain files in the 'install' target." OFF)
option(LLVM_FORCE_USE_OLD_HOST_TOOLCHAIN
"Set to ON to force using an old, unsupported host toolchain." OFF)
option(CLANG_ENABLE_BOOTSTRAP "Generate the clang bootstrap target" OFF)
include(AddLLVM)
include(TableGen)
include(HandleLLVMOptions)
include(VersionFromVCS)
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
if (${PACKAGE_VERSION} MATCHES "${ROOT_LLVM_VERSION_REQUIRED_MAJOR}\\.1(|\\.[0-9]+)")
message(STATUS "Using LLVM external library - ${PACKAGE_VERSION}")
else()
message(FATAL_ERROR "LLVM version ${LLVM_PACKAGE_VERSION} different from ROOT supported, please try ${ROOT_LLVM_VERSION_REQUIRED_MAJOR}.1.x")
endif()
if (NOT DEFINED LLVM_INCLUDE_TESTS)
set(LLVM_INCLUDE_TESTS ON)
endif()
if(LLVM_INCLUDE_TESTS OR clingtest)
find_package(Python3 3.8 REQUIRED COMPONENTS Interpreter)
# Check prebuilt llvm/utils.
if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/count${CMAKE_EXECUTABLE_SUFFIX}
AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
set(LLVM_UTILS_PROVIDED ON)
endif()
set(ROOT_LLVM_MAIN_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}/llvm-project/llvm/")
if(EXISTS ${ROOT_LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
# Note: path not really used, except for checking if lit was found
set(LLVM_LIT ${ROOT_LLVM_MAIN_SRC_DIR}/utils/lit/lit.py CACHE PATH "The location of the lit test runner.")
if(NOT LLVM_UTILS_PROVIDED)
add_subdirectory(${ROOT_LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
add_subdirectory(${ROOT_LLVM_MAIN_SRC_DIR}/utils/count utils/count)
add_subdirectory(${ROOT_LLVM_MAIN_SRC_DIR}/utils/not utils/not)
set(LLVM_UTILS_PROVIDED ON)
set(CLANG_TEST_DEPS FileCheck count not)
endif()
# We do not run llvm tests in ROOT.
#set(UNITTEST_DIR ${ROOT_LLVM_MAIN_SRC_DIR}/utils/unittest)
#if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
# AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
# AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
# add_subdirectory(${UNITTEST_DIR} utils/unittest)
#endif()
else()
# Seek installed Lit.
find_program(LLVM_LIT
NAMES llvm-lit lit.py lit
PATHS "${ROOT_LLVM_MAIN_SRC_DIR}/utils/lit"
DOC "Path to lit.py")
endif()
if(LLVM_LIT)
# Define the default arguments to use with 'lit', and an option for the user
# to override.
set(LIT_ARGS_DEFAULT "-sv")
if (MSVC OR XCODE)
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
endif()
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
set(LIT_COMMAND "${LLVM_LIT}" CACHE STRING "Path to the LLVM LIT.")
# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
if( WIN32 AND NOT CYGWIN )
set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
endif()
else()
set(LLVM_INCLUDE_TESTS OFF)
endif()
endif()
# We checked above that LLVM_VERSION is what we require in ROOT_LLVM_VERSION_REQUIRED_MAJOR.
# To simplify code, just forward that requirement to the rest of ROOT, for example to
# construct the resource directory in core/clingutils.
set(LLVM_VERSION_MAJOR ${ROOT_LLVM_VERSION_REQUIRED_MAJOR} PARENT_SCOPE)
# We are in the case of NOT builtin_llvm
if (builtin_clang)
# remove clang-cpp from CLANG_LINKS_TO_CREATE to avoid clashes with
# install-clang-cpp target defined by LLVM's cmake module
set(CLANG_LINKS_TO_CREATE clang++ clang-cl)
# Disable linking against shared LLVM
set(LLVM_LINK_LLVM_DYLIB OFF)
add_subdirectory(llvm-project/clang EXCLUDE_FROM_ALL)
endif(builtin_clang)
set( CLANG_BUILT_STANDALONE 1 )
set(BACKEND_PACKAGE_STRING "LLVM ${LLVM_PACKAGE_VERSION}")
endif(builtin_llvm)
if (builtin_clang)
if (builtin_llvm)
set(CLANG_BINARY_DIR "${LLVM_BINARY_DIR}/tools/clang/")
else()
set(CLANG_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/llvm-project/clang/")
endif()
set(CLANG_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/llvm-project/clang/include
${CLANG_BINARY_DIR}/include
CACHE STRING "Clang include directories.")
set(CLANG_CMAKE_DIR "${CMAKE_BINARY_DIR}/lib/cmake/clang/")
else()
find_package(Clang REQUIRED CONFIG)
message(STATUS "Found Clang ${CLANG_PACKAGE_VERSION} in ${CLANG_CMAKE_DIR}")
endif()
# Reset the compiler flags after compiling LLVM and Clang
set(CMAKE_CXX_FLAGS ${cxx_flags_prev})
unset(cxx_flags_prev)
add_custom_target(CLING)
set(CLING_LIBRARIES clingInterpreter;clingMetaProcessor;clingUtils CACHE STRING "")
if (builtin_cling)
# Extract the compilation flags from LLVM and make them public to the
# rest of ROOT so that we can compile against LLVM with matching flags.
# LLVM doesn't really give us a API to get this with an in-source build
# so we just use the normal way of doing this and read the llvm directory
# compilation properties.
if (builtin_llvm)
get_directory_property(LLVM_DEFS DIRECTORY llvm-project/llvm COMPILE_DEFINITIONS)
# Turns DEFINE1;DEFINE2 to -DDEFINE1 -DDEFINE2
string (REPLACE ";" " -D" LLVM_DEFS ";${LLVM_DEFS}")
endif()
# FIXME: Reduce the usage of CLING_CXXFLAGS by adding a cmake routine in
# RootMacros.cmake for all cling-dependent libraries
if(MSVC)
set(CLING_CXXFLAGS " ${LLVM_DEFS} -DNOMINMAX -D_XKEYCHECK_H")
else()
# FIXME: Work hard to remove -Wno-shadow and -Wno-unused-parameter
set(CLING_CXXFLAGS " ${LLVM_DEFS} -fno-strict-aliasing -Wwrite-strings -Wno-shadow -Wno-unused-parameter")
endif()
# Set the flags in the parent scope for the rest of the cling-based libraries in ROOT.
set(CLING_CXXFLAGS ${CLING_CXXFLAGS} PARENT_SCOPE)
string(APPEND CMAKE_CXX_FLAGS ${CLING_CXXFLAGS})
if (LLVM_ENABLE_PIC AND NOT MSVC)
# FIXME: LLVM_ENABLE_PIC is ON by default, however not propagated to cling.
# FIXME: fPIC is required by the linker for libCling. Can we do that using
# cmake: set_property(TARGET clingInterpreter PROPERTY POSITION_INDEPENDENT_CODE ON)?
string(APPEND CMAKE_CXX_FLAGS " -fPIC")
string(APPEND CMAKE_C_FLAGS " -fPIC")
endif(LLVM_ENABLE_PIC AND NOT MSVC)
# Avoid cling being installed under ROOTSYS/include.
set(CLING_ROOT_BUILD ON)
add_subdirectory(cling EXCLUDE_FROM_ALL)
add_dependencies(CLING ${CLING_LIBRARIES})
set(CLING_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/cling/include CACHE STRING "")
#---These are the libraries that we link ROOT with CLING---------------------------
if (builtin_llvm)
add_dependencies(CLING intrinsics_gen)
endif()
if (builtin_clang)
add_dependencies(CLING clang-headers clang-resource-headers)
# Windows (and some other LLVM setups) do not have that target available.
if (TARGET clang-cmake-exports)
add_dependencies(CLING clang-cmake-exports)
endif()
endif()
else()
set(Cling_DIR ${LLVM_BINARY_DIR}/lib/cmake/cling/)
find_package(Cling REQUIRED CONFIG PATHS ${Cling_DIR} "${Cling_DIR}/lib/cmake/cling" "${Cling_DIR}/cmake" NO_DEFAULT_PATH)
find_package(Clang REQUIRED CONFIG PATHS ${Cling_DIR} "${Cling_DIR}/lib/cmake/clang" "${Cling_DIR}/cmake" NO_DEFAULT_PATH)
# We need to consider not just the direct link dependencies, but also the
# transitive link dependencies. Do this by starting with the set of direct
# dependencies, then the dependencies of those dependencies, and so on.
set(new_libs "clingMetaProcessor")
set(link_libs ${new_libs})
while(NOT "${new_libs}" STREQUAL "")
foreach(lib ${new_libs})
if(TARGET ${lib})
get_target_property(lib_type ${lib} TYPE)
if("${lib_type}" STREQUAL "STATIC_LIBRARY")
list(APPEND static_libs ${lib})
else()
list(APPEND other_libs ${lib})
endif()
get_target_property(transitive_libs ${lib} INTERFACE_LINK_LIBRARIES)
if (NOT transitive_libs)
continue()
endif()
foreach(transitive_lib ${transitive_libs})
list(FIND link_libs ${transitive_lib} idx)
#if(TARGET ${transitive_lib} AND idx EQUAL -1)
if(idx EQUAL -1)
list(APPEND newer_libs ${transitive_lib})
list(APPEND link_libs ${transitive_lib})
endif()
endforeach(transitive_lib)
endif()
endforeach(lib)
set(new_libs ${newer_libs})
set(newer_libs "")
endwhile()
set(CLING_DEPEND_LIBS ${link_libs} CACHE STRING "")
endif(builtin_cling)
#---Avoid to dependencies to system (e.g. atomic) libraries without modifying the LLVM code----------
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
get_target_property(__libs LLVMSupport INTERFACE_LINK_LIBRARIES)
list(REMOVE_ITEM __libs atomic)
set_target_properties(LLVMSupport PROPERTIES INTERFACE_LINK_LIBRARIES "${__libs}")
endif()
#---Mark the LLVM/CLANG variables as advanced--------------------------------------------------------
get_cmake_property(variables CACHE_VARIABLES)
foreach(var ${variables})
if(var MATCHES "^(CLANG|LLVM|CLING)_")
mark_as_advanced(FORCE ${var})
endif()
endforeach()
mark_as_advanced(FORCE BUG_REPORT_URL BUILD_CLANG_FORMAT_VS_PLUGIN BUILD_SHARED_LIBS BUILD_TESTING
C_INCLUDE_DIRS DEFAULT_SYSROOT FFI_INCLUDE_DIR FFI_LIBRARY_DIR
GCC_INSTALL_PREFIX LIBCLANG_BUILD_STATIC TOOL_INFO_PLIST)
mark_as_advanced(CLEAR LLVM_ENABLE_ASSERTIONS LLVM_BUILD_TYPE)
##################### LIBINTEROP ###########################
#---Set InterOp include directories, for any ROOT component that requires the headers--------------------------------------------------------
set(CPPINTEROP_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/CppInterOp/include
CACHE STRING "CppInterOp include directories.")
#---Set InterOp to build on Cling, this can be toggled to use Clang-REPL-------------------------------------------------------
set(CPPINTEROP_USE_CLING ON BOOL "Use Cling as backend")
add_subdirectory(CppInterOp)