-
Notifications
You must be signed in to change notification settings - Fork 326
/
CMakeLists.txt
422 lines (364 loc) · 15.3 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
cmake_minimum_required(VERSION 3.13.4)
include(CheckSymbolExists)
project(test-suite C CXX)
if("Fortran" IN_LIST TEST_SUITE_SUBDIRS)
set(TEST_SUITE_FORTRAN_default ON)
else()
set(TEST_SUITE_FORTRAN_default OFF)
endif()
option(TEST_SUITE_FORTRAN "Enable Fortran test suite" ${TEST_SUITE_FORTRAN_default})
if(TEST_SUITE_FORTRAN)
enable_language(Fortran)
endif()
function(append value)
foreach(variable ${ARGN})
set(${variable} "${${variable}} ${value}" PARENT_SCOPE)
endforeach(variable)
endfunction()
# The test-suite is designed to be built in release mode anyway and
# falls over unless -DNDEBUG is set.
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "No build type selected, defaulting to Release")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "" FORCE)
endif()
# Selecting installation directories or build types is untypical.
mark_as_advanced(CMAKE_INSTALL_PREFIX CMAKE_BUILD_TYPE)
# On the other hand we often want to switch compiler or cflags
mark_as_advanced(CLEAR CMAKE_C_COMPILER CMAKE_CXX_COMPILER CMAKE_LINKER
CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS)
if(TEST_SUITE_FORTRAN)
mark_as_advanced(CLEAR CMAKE_Fortran_COMPILER)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND CMAKE_C_SIMULATE_ID MATCHES "MSVC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /FIstdio.h")
endif()
# The files in cmake/caches often want to pass along additional flags to select
# the target architecture. Note that you should still use
# CMAKE_OSX_ARCHITECTURES and CMAKE_C_COMPILER_TARGET where possible.
set(TEST_SUITE_ARCH_FLAGS CACHE STRING
"Extra flags to select target architecture.")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_SUITE_ARCH_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TEST_SUITE_ARCH_FLAGS}")
if(TEST_SUITE_FORTRAN)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${TEST_SUITE_ARCH_FLAGS}")
endif()
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TEST_SUITE_ARCH_FLAGS}")
set(LLVM_CODESIGNING_IDENTITY "" CACHE STRING
"Sign executables and dylibs with the given identity or skip if empty (Darwin Only)")
add_definitions(-DNDEBUG)
option(TEST_SUITE_SUPPRESS_WARNINGS "Suppress all warnings" ON)
if(${TEST_SUITE_SUPPRESS_WARNINGS})
if(NOT CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
# NOTE: ATM (18/8/23) LLVM Flang does not support the -w flag.
# FIXME: Don't use add_definitions to add compiler flags
add_definitions(-w)
endif()
endif()
# We want reproducible builds, so using __DATE__ and __TIME__ is bad
# FIXME: Add this unconditionally when flang starts supporting it.
if(NOT CMAKE_Fortran_COMPILER_ID STREQUAL "LLVMFlang")
add_definitions(-Werror=date-time)
endif()
# Add path for custom modules
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
)
# Sanity check our source directory to make sure that we are not trying to
# generate an in-tree build (unless on MSVC_IDE, where it is ok), and to make
# sure that we don't have any stray generated files lying around in the tree
# (which would end up getting picked up by header search, instead of the correct
# versions).
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE)
message(FATAL_ERROR "In-source builds are not allowed.
CMake would overwrite the makefiles distributed with LLVM.
Please create a directory and run cmake from there, passing the path
to this source directory as the last argument.
This process created the file `CMakeCache.txt' and the directory `CMakeFiles'.
Please delete them.")
endif()
# Sanity check SIZEOF_VOID_P. This is sometimes empty when compiler detection
# failed, error out to avoid a mostly working but invalid setup.
if(NOT CMAKE_SIZEOF_VOID_P)
message(FATAL_ERROR "CMAKE_SIZEOF_VOID_P is not defined")
endif()
# Remote configuration (will be set in lit.site.cfg)
set(TEST_SUITE_REMOTE_CLIENT "ssh" CACHE STRING "Remote execution client")
set(TEST_SUITE_REMOTE_HOST "" CACHE STRING "Remote execution host")
mark_as_advanced(TEST_SUITE_REMOTE_CLIENT)
if(TEST_SUITE_REMOTE_HOST)
add_custom_target(rsync
COMMAND ${PROJECT_SOURCE_DIR}/utils/rsync.sh
${TEST_SUITE_REMOTE_CLIENT}
${TEST_SUITE_REMOTE_HOST}
${PROJECT_BINARY_DIR}
USES_TERMINAL
)
endif()
# Run Under configuration for RunSafely.sh (will be set in lit.site.cfg)
set(TEST_SUITE_RUN_UNDER "" CACHE STRING "RunSafely.sh run-under (-u) parameter")
# User mode emulation configuration (e.g. running under qemu)
# (will be set in lit.site.cfg)
set(TEST_SUITE_USER_MODE_EMULATION NO CACHE BOOL
"RUN_UNDER is used to run tests under emulation.")
# Set value to python style True/False
if (TEST_SUITE_USER_MODE_EMULATION)
set(TEST_SUITE_USER_MODE_EMULATION "True")
else()
set(TEST_SUITE_USER_MODE_EMULATION "False")
endif()
# run type/benchmark size configuration (mostly for SPEC at the moment)
set(TEST_SUITE_RUN_TYPE "train" CACHE STRING
"Type of benchmark inputs (may be test,train or ref)")
get_filename_component(CMAKE_C_COMPILER_DIRECTORY ${CMAKE_C_COMPILER} DIRECTORY)
option(TEST_SUITE_COLLECT_CODE_SIZE "Measure code size of binaries" ON)
if(TEST_SUITE_COLLECT_CODE_SIZE)
find_program(TEST_SUITE_LLVM_SIZE NAMES "llvm-size"
HINTS ${CMAKE_C_COMPILER_DIRECTORY})
mark_as_advanced(TEST_SUITE_LLVM_SIZE)
if(TEST_SUITE_LLVM_SIZE STREQUAL "TEST_SUITE_LLVM_SIZE-NOTFOUND")
message(FATAL_ERROR "llvm-size not found.
Make sure it is in your path or set TEST_SUITE_COLLECT_CODE_SIZE to OFF")
endif()
endif()
option(TEST_SUITE_USE_IR_PGO
"Use IR PGO instrumentation (requires TEST_SUITE_PROFILE_GENERATE)" OFF)
# Enable profile generate mode in lit. Note that this does not automatically
# add something like -fprofile-instr-generate to the compiler flags.
option(TEST_SUITE_PROFILE_GENERATE "Enable lit profile generate mode" OFF)
# Set value to python style True/False
if(TEST_SUITE_PROFILE_GENERATE)
find_program(TEST_SUITE_LLVM_PROFDATA NAMES "llvm-profdata"
HINTS ${CMAKE_C_COMPILER_DIRECTORY})
mark_as_advanced(TEST_SUITE_LLVM_PROFDATA)
if(TEST_SUITE_LLVM_PROFDATA STREQUAL "TEST_SUITE_LLVM_PROFDATA-NOTFOUND")
message(FATAL_ERROR "llvm-profdata not found.
Make sure it is in your path or set TEST_SUITE_PROFILE_GENERATE to OFF")
endif()
set(TEST_SUITE_PROFILE_GENERATE "True")
set(profile_instrumentation_flags -fprofile-instr-generate)
if(TEST_SUITE_USE_IR_PGO)
set(profile_instrumentation_flags -fprofile-generate)
endif()
list(APPEND CFLAGS ${profile_instrumentation_flags})
list(APPEND CXXFLAGS ${profile_instrumentation_flags})
list(APPEND LDFLAGS ${profile_instrumentation_flags})
else()
set(TEST_SUITE_PROFILE_GENERATE "False")
endif()
option(TEST_SUITE_PROFILE_USE
"Add apropriate -fprofile-instr-use to CFLAGS/CXXFLAGS for each benchmark"
OFF)
# When running the test-suite in diagnosis mode, use these flags passed by
# LNT to gather data, for examples -ftime-report, or -mllvm -stats. This way
# the user specified CMAKE_C_FLAGS etc. need not be changed.
set(TEST_SUITE_DIAGNOSE_FLAGS CACHE STRING
"Extra flags appended to CMAKE_C_FLAGS + CMAKE_CXX_FLAGS + CMAKE_Fortran_FLAGS")
set(TEST_SUITE_DIAGNOSE_LINKER_FLAGS CACHE STRING
"Extra flags appended to CMAKE_EXE_LINKER_FLAGS")
mark_as_advanced(TEST_SUITE_DIAGNOSE_FLAGS TEST_SUITE_DIAGNOSE_LINKER_FLAGS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_SUITE_DIAGNOSE_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TEST_SUITE_DIAGNOSE_FLAGS}")
if(TEST_SUITE_FORTRAN)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${TEST_SUITE_DIAGNOSE_FLAGS}")
endif()
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} ${TEST_SUITE_DIAGNOSE_LINKER_FLAGS}")
if (TESTSUITE_USE_LINKER)
append("-fuse-ld=${TESTSUITE_USE_LINKER}"
CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAG)
endif()
# Append extra flags. These extra flags are mainly meant for cache files that
# want to apply flags that get not override even when the user manually
# specifies CMAKE_C_FLAGS and similar.
set(TEST_SUITE_EXTRA_C_FLAGS CACHE STRING "Extra flags for CMAKE_C_FLAGS")
set(TEST_SUITE_EXTRA_CXX_FLAGS CACHE STRING "Extra flags for CMAKE_CXX_FLAGS")
if(TEST_SUITE_FORTRAN)
set(TEST_SUITE_EXTRA_Fortran_FLAGS CACHE STRING "Extra flags for CMAKE_Fortran_FLAGS")
endif()
set(TEST_SUITE_EXTRA_EXE_LINKER_FLAGS CACHE STRING
"Extra flags for CMAKE_EXE_LINKER_FLAGS")
mark_as_advanced(TEST_SUITE_EXTRA_C_FLAGS, TEST_SUITE_EXTRA_CXX_FLAGS,
TEST_SUITE_EXTRA_EXE_LINKER_FLAGS)
if(TEST_SUITE_FORTRAN)
mark_as_advanced(TEST_SUITE_EXTRA_Fortran_FLAGS TEST_SUITE_EXTRA_EXE_LINKER_FLAGS)
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TEST_SUITE_EXTRA_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TEST_SUITE_EXTRA_CXX_FLAGS}")
if(TEST_SUITE_FORTRAN)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${TEST_SUITE_EXTRA_Fortran_FLAGS}")
endif()
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} ${TEST_SUITE_EXTRA_EXE_LINKER_FLAGS}")
if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
# Use X/OPEN compatibility flag on AIX for C tests to avoid problems
# with some versions of the system headers.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_XOPEN_SOURCE=700")
# On AIX, the environment variable 'OBJECT_MODE' specifies the bit
# mode for compilation.
if(DEFINED ENV{OBJECT_MODE})
# Specify maximum data heap size on AIX for 32-bit programs.
if($ENV{OBJECT_MODE} STREQUAL "32")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-bmaxdata:0x80000000")
endif()
endif()
endif()
include(HandleCompilerRT)
include(TestSuite)
include(SingleMultiSource)
# Needs by External/sollve_vv.
find_package(OpenMP)
# Fortran Helper Modules
if(TEST_SUITE_FORTRAN)
include(Fortran)
endif()
if(NOT DEFINED TARGET_OS)
message(STATUS "Check target operating system - ${CMAKE_SYSTEM_NAME}")
set(TARGET_OS ${CMAKE_SYSTEM_NAME})
endif()
if(NOT DEFINED ARCH)
include(DetectArchitecture)
detect_architecture(ARCH)
endif()
if(NOT DEFINED X86CPU_ARCH AND ARCH STREQUAL "x86")
include(DetectArchitecture)
detect_x86_cpu_architecture(X86CPU_ARCH)
endif()
if(NOT DEFINED ENDIAN)
include(TestBigEndian)
test_big_endian(IS_BIGENDIAN)
if(IS_BIGENDIAN)
set(ENDIAN "big")
else()
set(ENDIAN "little")
endif()
endif()
# Disabling address space randomization makes the performance of memory/cache
# intensive benchmarks more deterministic.
option(TEST_SUITE_DISABLE_PIE
"Disable position independent executables and ASLR" ON)
mark_as_advanced(TEST_SUITE_DISABLE_PIE)
if(TEST_SUITE_DISABLE_PIE)
if(APPLE AND NOT ARCH STREQUAL "AArch64")
list(APPEND LDFLAGS -Wl,-no_pie)
endif()
# TODO: Add apropriate flags to disable PIE/ASLR on linux, bsd, ...
endif()
if(ARCH STREQUAL "Mips")
check_symbol_exists(__mips16 "" MIPS_IS_MIPS16_ENABLED)
check_symbol_exists(__mips64 "" MIPS_IS_MIPS64_ENABLED)
endif()
# PowerPC/Linux needs -ffp-contract=off so that:
# The outputs can be compared to gcc.
# The outputs match the reference outputs.
if(ARCH STREQUAL "PowerPC")
check_symbol_exists(_LP64 "" PPC_IS_PPC64_ENABLED)
add_definitions(-ffp-contract=off)
endif()
find_program(TEST_SUITE_LIT NAMES "lit" "llvm-lit")
set(TEST_SUITE_LIT_FLAGS "-sv" CACHE STRING "Flags used when running lit")
mark_as_advanced(TEST_SUITE_LIT TEST_SUITE_LIT_FLAGS)
mark_as_advanced(TEST_SUITE_LIT)
add_subdirectory(tools)
# Turn on ignore whitespacing on WIN32 to avoid line-ending mismatch
if(TARGET_OS STREQUAL "Windows")
set(FP_IGNOREWHITESPACE ON)
endif()
# Shortcut for the path to the fpcmp executable
set(FPCMP fpcmp-target)
if (TEST_SUITE_USER_MODE_EMULATION)
set(FPCMP fpcmp)
endif()
add_subdirectory(litsupport)
option(TEST_SUITE_COLLECT_COMPILE_TIME
"Measure compile time by wrapping compiler invocations in timeit" ON)
if(TEST_SUITE_COLLECT_COMPILE_TIME)
set(CMAKE_C_COMPILE_OBJECT "${CMAKE_BINARY_DIR}/tools/timeit --summary <OBJECT>.time ${CMAKE_C_COMPILE_OBJECT}")
set(CMAKE_CXX_COMPILE_OBJECT "${CMAKE_BINARY_DIR}/tools/timeit --summary <OBJECT>.time ${CMAKE_CXX_COMPILE_OBJECT}")
set(CMAKE_C_LINK_EXECUTABLE "${CMAKE_BINARY_DIR}/tools/timeit --summary <TARGET>.link.time ${CMAKE_C_LINK_EXECUTABLE}")
set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_BINARY_DIR}/tools/timeit --summary <TARGET>.link.time ${CMAKE_CXX_LINK_EXECUTABLE}")
endif()
option(TEST_SUITE_BENCHMARKING_ONLY "Only run the benchmarking only subset" OFF)
option(TEST_SUITE_COLLECT_STATS "Collect LLVM statistics" OFF)
if(TEST_SUITE_COLLECT_STATS)
list(APPEND CFLAGS -save-stats=obj)
list(APPEND CXXFLAGS -save-stats=obj)
# Collect stats for LTO step too.
if (${CMAKE_C_FLAGS} MATCHES ".*-flto.*" AND
${CMAKE_CXX_FLAGS} MATCHES ".*-flto.*")
list(APPEND LDFLAGS -save-stats=obj)
endif()
endif()
# Detect and include subdirectories
# This allows to: Place additional test-suites into the toplevel test-suite
# directory where they will be picked up automatically. Alternatively you may
# manually specify directories to include test-suites at external locations
# and to leave out some of the default ones.
if(NOT TEST_SUITE_SUBDIRS)
file(GLOB sub_cmakelists RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} */CMakeLists.txt)
set(TEST_SUITE_SUBDIRS "")
foreach(entry ${sub_cmakelists})
get_filename_component(subdir ${entry} DIRECTORY)
list(APPEND TEST_SUITE_SUBDIRS ${subdir})
endforeach()
# Drop things we do not want to be automatically added.
list(REMOVE_ITEM TEST_SUITE_SUBDIRS litsupport tools CTMark)
if(NOT TEST_SUITE_FORTRAN)
list(REMOVE_ITEM TEST_SUITE_SUBDIRS Fortran)
endif()
# Separately add tests for tools.
list(APPEND TEST_SUITE_SUBDIRS tools/test)
set(TEST_SUITE_SUBDIRS "${TEST_SUITE_SUBDIRS}")
endif()
set(TEST_SUITE_SUBDIRS "${TEST_SUITE_SUBDIRS}" CACHE STRING
"Semicolon separated list of directories with CMakeLists.txt to include")
foreach(subdir ${TEST_SUITE_SUBDIRS})
# When we add subdirs outside the toplevel source directory then we have to
# make up a directory to use for the builddir.
if(subdir MATCHES "^/" OR subdir MATCHES "\\.\\.")
if(subdir MATCHES "/$")
message(FATAL_ERROR "Subdir must not end in '/'")
endif()
get_filename_component(subdir_name ${subdir} NAME)
else()
set(subdir_name ${subdir})
endif()
message(STATUS "Adding directory ${subdir}")
add_subdirectory(${subdir} ${subdir_name})
endforeach()
option(TEST_SUITE_RUN_BENCHMARKS "Actually run the benchmarks in lit" ON)
set(TEST_SUITE_EXTRA_LIT_MODULES "" CACHE STRING
"Semicolon separated list of extra lit modules in use")
mark_as_advanced(TEST_SUITE_EXTRA_LIT_MODULES)
# Construct list testing modules (see also litsupport/modules/*.py)
set(LIT_MODULES ${TEST_SUITE_EXTRA_LIT_MODULES})
if(TEST_SUITE_RUN_BENCHMARKS)
list(APPEND LIT_MODULES run)
endif()
if(TEST_SUITE_COLLECT_CODE_SIZE)
list(APPEND LIT_MODULES codesize)
endif()
list(APPEND LIT_MODULES hash)
if(TEST_SUITE_COLLECT_COMPILE_TIME)
list(APPEND LIT_MODULES compiletime)
endif()
if(TEST_SUITE_RUN_UNDER)
list(APPEND LIT_MODULES run_under)
endif()
list(APPEND LIT_MODULES timeit)
if(TEST_SUITE_PROFILE_GENERATE)
list(APPEND LIT_MODULES profilegen)
endif()
if(TEST_SUITE_COLLECT_STATS)
list(APPEND LIT_MODULES stats)
endif()
# Produce lit.site.cfg
configure_file("${PROJECT_SOURCE_DIR}/lit.site.cfg.in" "${CMAKE_BINARY_DIR}/lit.site.cfg")
get_property(TEST_SUITE_TARGETS GLOBAL PROPERTY TEST_SUITE_TARGETS)
add_custom_target(check
COMMAND ${TEST_SUITE_LIT} ${TEST_SUITE_LIT_FLAGS} .
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${TEST_SUITE_TARGETS}
USES_TERMINAL
)