1 # Keep track if we have all dependencies.
2 set(ENABLE_CHECK_TARGETS TRUE)
4 # Function to find required dependencies for testing.
5 function(find_standalone_test_dependencies)
6 find_package (Python3 COMPONENTS Interpreter)
8 if (NOT Python3_Interpreter_FOUND)
9 message(STATUS "Could not find Python.")
10 message(WARNING "The check targets will not be available!")
11 set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
14 set(Python3_EXECUTABLE ${Python3_EXECUTABLE} PARENT_SCOPE)
18 find_program(OPENMP_LLVM_LIT_EXECUTABLE
19 NAMES llvm-lit.py llvm-lit lit.py lit
20 PATHS ${OPENMP_LLVM_TOOLS_DIR})
21 if (NOT OPENMP_LLVM_LIT_EXECUTABLE)
22 message(STATUS "Cannot find llvm-lit.")
23 message(STATUS "Please put llvm-lit in your PATH, set OPENMP_LLVM_LIT_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.")
24 message(WARNING "The check targets will not be available!")
25 set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
29 find_program(OPENMP_FILECHECK_EXECUTABLE
31 PATHS ${OPENMP_LLVM_TOOLS_DIR})
32 if (NOT OPENMP_FILECHECK_EXECUTABLE)
33 message(STATUS "Cannot find FileCheck.")
34 message(STATUS "Please put FileCheck in your PATH, set OPENMP_FILECHECK_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.")
35 message(WARNING "The check targets will not be available!")
36 set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
40 find_program(OFFLOAD_DEVICE_INFO_EXECUTABLE
41 NAMES llvm-offload-device-info
42 PATHS ${OPENMP_LLVM_TOOLS_DIR})
43 if (NOT OFFLOAD_DEVICE_INFO_EXECUTABLE)
44 message(STATUS "Cannot find 'llvm-offload-device-info'.")
45 message(STATUS "Please put 'not' in your PATH, set OFFLOAD_DEVICE_INFO_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.")
46 message(WARNING "The check targets will not be available!")
47 set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
51 find_program(OPENMP_NOT_EXECUTABLE
53 PATHS ${OPENMP_LLVM_TOOLS_DIR})
54 if (NOT OPENMP_NOT_EXECUTABLE)
55 message(STATUS "Cannot find 'not'.")
56 message(STATUS "Please put 'not' in your PATH, set OPENMP_NOT_EXECUTABLE to its full path, or point OPENMP_LLVM_TOOLS_DIR to its directory.")
57 message(WARNING "The check targets will not be available!")
58 set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
63 if (${OPENMP_STANDALONE_BUILD})
64 find_standalone_test_dependencies()
67 set(DEFAULT_LIT_ARGS "-sv --show-unsupported --show-xfail")
69 set(DEFAULT_LIT_ARGS "${DEFAULT_LIT_ARGS} --no-progress-bar")
71 if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
72 set(DEFAULT_LIT_ARGS "${DEFAULT_LIT_ARGS} --time-tests --timeout=1800")
74 set(OPENMP_LIT_ARGS "${DEFAULT_LIT_ARGS}" CACHE STRING "Options for lit.")
75 separate_arguments(OPENMP_LIT_ARGS)
77 if (NOT TARGET "FileCheck")
78 message(STATUS "Cannot find 'FileCheck'.")
79 message(WARNING "The check targets will not be available!")
80 set(ENABLE_CHECK_TARGETS FALSE)
82 set(OPENMP_FILECHECK_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/FileCheck)
84 set(OPENMP_NOT_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/not)
85 set(OFFLOAD_DEVICE_INFO_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/llvm-offload-device-info)
88 # Macro to extract information about compiler from file. (no own scope)
89 macro(extract_test_compiler_information lang file)
90 file(READ ${file} information)
91 list(GET information 0 path)
92 list(GET information 1 id)
93 list(GET information 2 version)
94 list(GET information 3 openmp_flags)
95 list(GET information 4 has_tsan_flags)
96 list(GET information 5 has_omit_frame_pointer_flags)
97 list(GET information 6 has_omp_h)
99 set(OPENMP_TEST_${lang}_COMPILER_PATH ${path})
100 set(OPENMP_TEST_${lang}_COMPILER_ID ${id})
101 set(OPENMP_TEST_${lang}_COMPILER_VERSION ${version})
102 set(OPENMP_TEST_${lang}_COMPILER_OPENMP_FLAGS ${openmp_flags})
103 set(OPENMP_TEST_${lang}_COMPILER_HAS_TSAN_FLAGS ${has_tsan_flags})
104 set(OPENMP_TEST_${lang}_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS ${has_omit_frame_pointer_flags})
105 set(OPENMP_TEST_${lang}_COMPILER_HAS_OMP_H ${has_omp_h})
108 # Function to set variables with information about the test compiler.
109 function(set_test_compiler_information dir)
110 extract_test_compiler_information(C ${dir}/CCompilerInformation.txt)
111 extract_test_compiler_information(CXX ${dir}/CXXCompilerInformation.txt)
112 if (NOT("${OPENMP_TEST_C_COMPILER_ID}" STREQUAL "${OPENMP_TEST_CXX_COMPILER_ID}" AND
113 "${OPENMP_TEST_C_COMPILER_VERSION}" STREQUAL "${OPENMP_TEST_CXX_COMPILER_VERSION}"))
114 message(STATUS "Test compilers for C and C++ don't match.")
115 message(WARNING "The check targets will not be available!")
116 set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
118 set(OPENMP_TEST_COMPILER_ID "${OPENMP_TEST_C_COMPILER_ID}" PARENT_SCOPE)
119 set(OPENMP_TEST_COMPILER_VERSION "${OPENMP_TEST_C_COMPILER_VERSION}" PARENT_SCOPE)
120 set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "${OPENMP_TEST_C_COMPILER_OPENMP_FLAGS}" PARENT_SCOPE)
121 set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS "${OPENMP_TEST_C_COMPILER_HAS_TSAN_FLAGS}" PARENT_SCOPE)
122 set(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS "${OPENMP_TEST_C_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS}" PARENT_SCOPE)
123 set(OPENMP_TEST_COMPILER_HAS_OMP_H "${OPENMP_TEST_C_COMPILER_HAS_OMP_H}" PARENT_SCOPE)
125 # Determine major version.
126 string(REGEX MATCH "[0-9]+" major "${OPENMP_TEST_C_COMPILER_VERSION}")
127 string(REGEX MATCH "[0-9]+\\.[0-9]+" majorminor "${OPENMP_TEST_C_COMPILER_VERSION}")
128 set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${major}" PARENT_SCOPE)
129 set(OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR "${majorminor}" PARENT_SCOPE)
133 if (${OPENMP_STANDALONE_BUILD})
134 # Detect compiler that should be used for testing.
135 # We cannot use ExternalProject_Add() because its configuration runs when this
136 # project is built which is too late for detecting the compiler...
137 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler)
139 COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/DetectTestCompiler
140 -DCMAKE_C_COMPILER=${OPENMP_TEST_C_COMPILER}
141 -DCMAKE_CXX_COMPILER=${OPENMP_TEST_CXX_COMPILER}
142 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler
143 OUTPUT_VARIABLE DETECT_COMPILER_OUT
144 ERROR_VARIABLE DETECT_COMPILER_ERR
145 RESULT_VARIABLE DETECT_COMPILER_RESULT)
146 if (DETECT_COMPILER_RESULT)
147 message(STATUS "Could not detect test compilers.")
148 message(WARNING "The check targets will not be available!")
149 set(ENABLE_CHECK_TARGETS FALSE)
151 set_test_compiler_information(${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler)
154 # Set the information that we know.
155 set(OPENMP_TEST_COMPILER_ID "Clang")
156 # Cannot use CLANG_VERSION because we are not guaranteed that this is already set.
157 set(OPENMP_TEST_COMPILER_VERSION "${LLVM_VERSION}")
158 set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${LLVM_VERSION_MAJOR}")
159 set(OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
160 # Unfortunately the top-level cmake/config-ix.cmake file mangles CMake's
161 # CMAKE_THREAD_LIBS_INIT variable from the FindThreads package, so work
162 # around that, until it is fixed there.
163 if("${CMAKE_THREAD_LIBS_INIT}" STREQUAL "-lpthread")
164 set(OPENMP_TEST_COMPILER_THREAD_FLAGS "-pthread")
166 set(OPENMP_TEST_COMPILER_THREAD_FLAGS "${CMAKE_THREAD_LIBS_INIT}")
169 set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 1)
171 set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 0)
173 set(OPENMP_TEST_COMPILER_HAS_OMP_H 1)
174 set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "-fopenmp ${OPENMP_TEST_COMPILER_THREAD_FLAGS}")
175 set(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS 1)
178 # Function to set compiler features for use in lit.
179 function(update_test_compiler_features)
182 foreach(feat IN LISTS OPENMP_TEST_COMPILER_FEATURE_LIST)
184 string(APPEND FEATURES ", ")
187 string(APPEND FEATURES "'${feat}'")
189 string(APPEND FEATURES "]")
190 set(OPENMP_TEST_COMPILER_FEATURES ${FEATURES} PARENT_SCOPE)
193 function(set_test_compiler_features)
194 if ("${OPENMP_TEST_COMPILER_ID}" STREQUAL "GNU")
196 elseif ("${OPENMP_TEST_COMPILER_ID}" STREQUAL "Intel")
199 # Just use the lowercase of the compiler ID as fallback.
200 string(TOLOWER "${OPENMP_TEST_COMPILER_ID}" comp)
202 set(OPENMP_TEST_COMPILER_FEATURE_LIST ${comp} ${comp}-${OPENMP_TEST_COMPILER_VERSION_MAJOR} ${comp}-${OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR} ${comp}-${OPENMP_TEST_COMPILER_VERSION} PARENT_SCOPE)
204 set_test_compiler_features()
205 update_test_compiler_features()
207 # Function to add a testsuite for an OpenMP runtime library.
208 function(add_offload_testsuite target comment)
209 if (NOT ENABLE_CHECK_TARGETS)
210 add_custom_target(${target}
211 COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, dependencies not found.")
212 message(STATUS "${target} does nothing.")
216 cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "" "DEPENDS;ARGS" ${ARGN})
217 # EXCLUDE_FROM_CHECK_ALL excludes the test ${target} out of check-offload.
218 if (NOT ARG_EXCLUDE_FROM_CHECK_ALL)
219 # Register the testsuites and depends for the check-offload rule.
220 set_property(GLOBAL APPEND PROPERTY OPENMP_LIT_TESTSUITES ${ARG_UNPARSED_ARGUMENTS})
221 set_property(GLOBAL APPEND PROPERTY OPENMP_LIT_DEPENDS ${ARG_DEPENDS})
224 if (${OPENMP_STANDALONE_BUILD})
225 set(LIT_ARGS ${OPENMP_LIT_ARGS} ${ARG_ARGS})
226 add_custom_target(${target}
227 COMMAND ${Python3_EXECUTABLE} ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS}
229 DEPENDS ${ARG_DEPENDS}
233 if (ARG_EXCLUDE_FROM_CHECK_ALL)
234 add_lit_testsuite(${target}
236 ${ARG_UNPARSED_ARGUMENTS}
237 EXCLUDE_FROM_CHECK_ALL
238 DEPENDS clang FileCheck not ${ARG_DEPENDS}
242 add_lit_testsuite(${target}
244 ${ARG_UNPARSED_ARGUMENTS}
245 DEPENDS clang FileCheck not ${ARG_DEPENDS}