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(OPENMP_NOT_EXECUTABLE
42 PATHS ${OPENMP_LLVM_TOOLS_DIR})
43 if (NOT OPENMP_NOT_EXECUTABLE)
44 message(STATUS "Cannot find 'not'.")
45 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.")
46 message(WARNING "The check targets will not be available!")
47 set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
52 if (${OPENMP_STANDALONE_BUILD})
53 find_standalone_test_dependencies()
56 set(DEFAULT_LIT_ARGS "-sv --show-unsupported --show-xfail")
58 set(DEFAULT_LIT_ARGS "${DEFAULT_LIT_ARGS} --no-progress-bar")
60 if (${CMAKE_SYSTEM_NAME} MATCHES "AIX")
61 set(DEFAULT_LIT_ARGS "${DEFAULT_LIT_ARGS} --time-tests --timeout=3000")
63 set(OPENMP_LIT_ARGS "${DEFAULT_LIT_ARGS}" CACHE STRING "Options for lit.")
64 separate_arguments(OPENMP_LIT_ARGS)
66 if (NOT TARGET "FileCheck")
67 message(STATUS "Cannot find 'FileCheck'.")
68 message(WARNING "The check targets will not be available!")
69 set(ENABLE_CHECK_TARGETS FALSE)
71 set(OPENMP_FILECHECK_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/FileCheck)
73 set(OPENMP_NOT_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/not)
76 # Macro to extract information about compiler from file. (no own scope)
77 macro(extract_test_compiler_information lang file)
78 file(READ ${file} information)
79 list(GET information 0 path)
80 list(GET information 1 id)
81 list(GET information 2 version)
82 list(GET information 3 openmp_flags)
83 list(GET information 4 has_tsan_flags)
84 list(GET information 5 has_omit_frame_pointer_flags)
85 list(GET information 6 has_omp_h)
87 set(OPENMP_TEST_${lang}_COMPILER_PATH ${path})
88 set(OPENMP_TEST_${lang}_COMPILER_ID ${id})
89 set(OPENMP_TEST_${lang}_COMPILER_VERSION ${version})
90 set(OPENMP_TEST_${lang}_COMPILER_OPENMP_FLAGS ${openmp_flags})
91 set(OPENMP_TEST_${lang}_COMPILER_HAS_TSAN_FLAGS ${has_tsan_flags})
92 set(OPENMP_TEST_${lang}_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS ${has_omit_frame_pointer_flags})
93 set(OPENMP_TEST_${lang}_COMPILER_HAS_OMP_H ${has_omp_h})
96 # Function to set variables with information about the test compiler.
97 function(set_test_compiler_information dir)
98 extract_test_compiler_information(C ${dir}/CCompilerInformation.txt)
99 extract_test_compiler_information(CXX ${dir}/CXXCompilerInformation.txt)
100 if (NOT("${OPENMP_TEST_C_COMPILER_ID}" STREQUAL "${OPENMP_TEST_CXX_COMPILER_ID}" AND
101 "${OPENMP_TEST_C_COMPILER_VERSION}" STREQUAL "${OPENMP_TEST_CXX_COMPILER_VERSION}"))
102 message(STATUS "Test compilers for C and C++ don't match.")
103 message(WARNING "The check targets will not be available!")
104 set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
106 set(OPENMP_TEST_COMPILER_ID "${OPENMP_TEST_C_COMPILER_ID}" PARENT_SCOPE)
107 set(OPENMP_TEST_COMPILER_VERSION "${OPENMP_TEST_C_COMPILER_VERSION}" PARENT_SCOPE)
108 set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "${OPENMP_TEST_C_COMPILER_OPENMP_FLAGS}" PARENT_SCOPE)
109 set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS "${OPENMP_TEST_C_COMPILER_HAS_TSAN_FLAGS}" PARENT_SCOPE)
110 set(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS "${OPENMP_TEST_C_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS}" PARENT_SCOPE)
111 set(OPENMP_TEST_COMPILER_HAS_OMP_H "${OPENMP_TEST_C_COMPILER_HAS_OMP_H}" PARENT_SCOPE)
113 # Determine major version.
114 string(REGEX MATCH "[0-9]+" major "${OPENMP_TEST_C_COMPILER_VERSION}")
115 string(REGEX MATCH "[0-9]+\\.[0-9]+" majorminor "${OPENMP_TEST_C_COMPILER_VERSION}")
116 set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${major}" PARENT_SCOPE)
117 set(OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR "${majorminor}" PARENT_SCOPE)
121 if (${OPENMP_STANDALONE_BUILD})
122 # Detect compiler that should be used for testing.
123 # We cannot use ExternalProject_Add() because its configuration runs when this
124 # project is built which is too late for detecting the compiler...
125 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler)
127 COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/DetectTestCompiler
128 -DCMAKE_C_COMPILER=${OPENMP_TEST_C_COMPILER}
129 -DCMAKE_CXX_COMPILER=${OPENMP_TEST_CXX_COMPILER}
130 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler
131 OUTPUT_VARIABLE DETECT_COMPILER_OUT
132 ERROR_VARIABLE DETECT_COMPILER_ERR
133 RESULT_VARIABLE DETECT_COMPILER_RESULT)
134 if (DETECT_COMPILER_RESULT)
135 message(STATUS "Could not detect test compilers.")
136 message(WARNING "The check targets will not be available!")
137 set(ENABLE_CHECK_TARGETS FALSE)
139 set_test_compiler_information(${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler)
142 # Set the information that we know.
143 set(OPENMP_TEST_COMPILER_ID "Clang")
144 # Cannot use CLANG_VERSION because we are not guaranteed that this is already set.
145 set(OPENMP_TEST_COMPILER_VERSION "${LLVM_VERSION}")
146 set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${LLVM_VERSION_MAJOR}")
147 set(OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
148 # Unfortunately the top-level cmake/config-ix.cmake file mangles CMake's
149 # CMAKE_THREAD_LIBS_INIT variable from the FindThreads package, so work
150 # around that, until it is fixed there.
151 if("${CMAKE_THREAD_LIBS_INIT}" STREQUAL "-lpthread")
152 set(OPENMP_TEST_COMPILER_THREAD_FLAGS "-pthread")
154 set(OPENMP_TEST_COMPILER_THREAD_FLAGS "${CMAKE_THREAD_LIBS_INIT}")
157 set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 1)
159 set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 0)
161 set(OPENMP_TEST_COMPILER_HAS_OMP_H 1)
162 set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "-fopenmp ${OPENMP_TEST_COMPILER_THREAD_FLAGS}")
163 set(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS 1)
166 set(OPENMP_TEST_ENABLE_TSAN "${OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS}" CACHE BOOL
167 "Whether to enable tests using tsan")
169 # Function to set compiler features for use in lit.
170 function(update_test_compiler_features)
173 foreach(feat IN LISTS OPENMP_TEST_COMPILER_FEATURE_LIST)
175 string(APPEND FEATURES ", ")
178 string(APPEND FEATURES "'${feat}'")
180 string(APPEND FEATURES "]")
181 set(OPENMP_TEST_COMPILER_FEATURES ${FEATURES} PARENT_SCOPE)
184 function(set_test_compiler_features)
185 if ("${OPENMP_TEST_COMPILER_ID}" STREQUAL "GNU")
187 elseif ("${OPENMP_TEST_COMPILER_ID}" STREQUAL "Intel")
190 # Just use the lowercase of the compiler ID as fallback.
191 string(TOLOWER "${OPENMP_TEST_COMPILER_ID}" comp)
193 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)
195 set_test_compiler_features()
196 update_test_compiler_features()
198 # Function to add a testsuite for an OpenMP runtime library.
199 function(add_openmp_testsuite target comment)
200 if (NOT ENABLE_CHECK_TARGETS)
201 add_custom_target(${target}
202 COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, dependencies not found.")
203 message(STATUS "${target} does nothing.")
207 cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "" "DEPENDS;ARGS" ${ARGN})
208 # EXCLUDE_FROM_CHECK_ALL excludes the test ${target} out of check-openmp.
209 if (NOT ARG_EXCLUDE_FROM_CHECK_ALL)
210 # Register the testsuites and depends for the check-openmp rule.
211 set_property(GLOBAL APPEND PROPERTY OPENMP_LIT_TESTSUITES ${ARG_UNPARSED_ARGUMENTS})
212 set_property(GLOBAL APPEND PROPERTY OPENMP_LIT_DEPENDS ${ARG_DEPENDS})
215 if (${OPENMP_STANDALONE_BUILD})
216 set(LIT_ARGS ${OPENMP_LIT_ARGS} ${ARG_ARGS})
217 add_custom_target(${target}
218 COMMAND ${Python3_EXECUTABLE} ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS}
220 DEPENDS ${ARG_DEPENDS}
224 if (ARG_EXCLUDE_FROM_CHECK_ALL)
225 add_lit_testsuite(${target}
227 ${ARG_UNPARSED_ARGUMENTS}
228 EXCLUDE_FROM_CHECK_ALL
229 DEPENDS clang FileCheck not ${ARG_DEPENDS}
233 add_lit_testsuite(${target}
235 ${ARG_UNPARSED_ARGUMENTS}
236 DEPENDS clang FileCheck not ${ARG_DEPENDS}
243 function(construct_check_openmp_target)
244 get_property(OPENMP_LIT_TESTSUITES GLOBAL PROPERTY OPENMP_LIT_TESTSUITES)
245 get_property(OPENMP_LIT_DEPENDS GLOBAL PROPERTY OPENMP_LIT_DEPENDS)
247 # We already added the testsuites themselves, no need to do that again.
248 add_openmp_testsuite(check-openmp "Running OpenMP tests" ${OPENMP_LIT_TESTSUITES} EXCLUDE_FROM_CHECK_ALL DEPENDS ${OPENMP_LIT_DEPENDS})