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)
16 find_program(OPENMP_LLVM_LIT_EXECUTABLE
17 NAMES llvm-lit.py llvm-lit lit.py lit
18 PATHS ${OPENMP_LLVM_TOOLS_DIR})
19 if (NOT OPENMP_LLVM_LIT_EXECUTABLE)
20 message(STATUS "Cannot find llvm-lit.")
21 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.")
22 message(WARNING "The check targets will not be available!")
23 set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
27 find_program(OPENMP_FILECHECK_EXECUTABLE
29 PATHS ${OPENMP_LLVM_TOOLS_DIR})
30 if (NOT OPENMP_FILECHECK_EXECUTABLE)
31 message(STATUS "Cannot find FileCheck.")
32 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.")
33 message(WARNING "The check targets will not be available!")
34 set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
38 find_program(OPENMP_NOT_EXECUTABLE
40 PATHS ${OPENMP_LLVM_TOOLS_DIR})
41 if (NOT OPENMP_NOT_EXECUTABLE)
42 message(STATUS "Cannot find 'not'.")
43 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.")
44 message(WARNING "The check targets will not be available!")
45 set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
50 if (${OPENMP_STANDALONE_BUILD})
51 find_standalone_test_dependencies()
54 set(DEFAULT_LIT_ARGS "-sv --show-unsupported --show-xfail")
56 set(DEFAULT_LIT_ARGS "${DEFAULT_LIT_ARGS} --no-progress-bar")
58 set(OPENMP_LIT_ARGS "${DEFAULT_LIT_ARGS}" CACHE STRING "Options for lit.")
59 separate_arguments(OPENMP_LIT_ARGS)
61 if (NOT TARGET "FileCheck")
62 message(STATUS "Cannot find 'FileCheck'.")
63 message(WARNING "The check targets will not be available!")
64 set(ENABLE_CHECK_TARGETS FALSE)
66 set(OPENMP_FILECHECK_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/FileCheck)
68 set(OPENMP_NOT_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/not)
71 # Macro to extract information about compiler from file. (no own scope)
72 macro(extract_test_compiler_information lang file)
73 file(READ ${file} information)
74 list(GET information 0 path)
75 list(GET information 1 id)
76 list(GET information 2 version)
77 list(GET information 3 openmp_flags)
78 list(GET information 4 has_tsan_flags)
79 list(GET information 5 has_omit_frame_pointer_flags)
80 list(GET information 6 has_omp_h)
82 set(OPENMP_TEST_${lang}_COMPILER_PATH ${path})
83 set(OPENMP_TEST_${lang}_COMPILER_ID ${id})
84 set(OPENMP_TEST_${lang}_COMPILER_VERSION ${version})
85 set(OPENMP_TEST_${lang}_COMPILER_OPENMP_FLAGS ${openmp_flags})
86 set(OPENMP_TEST_${lang}_COMPILER_HAS_TSAN_FLAGS ${has_tsan_flags})
87 set(OPENMP_TEST_${lang}_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS ${has_omit_frame_pointer_flags})
88 set(OPENMP_TEST_${lang}_COMPILER_HAS_OMP_H ${has_omp_h})
91 # Function to set variables with information about the test compiler.
92 function(set_test_compiler_information dir)
93 extract_test_compiler_information(C ${dir}/CCompilerInformation.txt)
94 extract_test_compiler_information(CXX ${dir}/CXXCompilerInformation.txt)
95 if (NOT("${OPENMP_TEST_C_COMPILER_ID}" STREQUAL "${OPENMP_TEST_CXX_COMPILER_ID}" AND
96 "${OPENMP_TEST_C_COMPILER_VERSION}" STREQUAL "${OPENMP_TEST_CXX_COMPILER_VERSION}"))
97 message(STATUS "Test compilers for C and C++ don't match.")
98 message(WARNING "The check targets will not be available!")
99 set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE)
101 set(OPENMP_TEST_COMPILER_ID "${OPENMP_TEST_C_COMPILER_ID}" PARENT_SCOPE)
102 set(OPENMP_TEST_COMPILER_VERSION "${OPENMP_TEST_C_COMPILER_VERSION}" PARENT_SCOPE)
103 set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "${OPENMP_TEST_C_COMPILER_OPENMP_FLAGS}" PARENT_SCOPE)
104 set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS "${OPENMP_TEST_C_COMPILER_HAS_TSAN_FLAGS}" PARENT_SCOPE)
105 set(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS "${OPENMP_TEST_C_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS}" PARENT_SCOPE)
106 set(OPENMP_TEST_COMPILER_HAS_OMP_H "${OPENMP_TEST_C_COMPILER_HAS_OMP_H}" PARENT_SCOPE)
108 # Determine major version.
109 string(REGEX MATCH "[0-9]+" major "${OPENMP_TEST_C_COMPILER_VERSION}")
110 string(REGEX MATCH "[0-9]+\\.[0-9]+" majorminor "${OPENMP_TEST_C_COMPILER_VERSION}")
111 set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${major}" PARENT_SCOPE)
112 set(OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR "${majorminor}" PARENT_SCOPE)
116 if (${OPENMP_STANDALONE_BUILD})
117 # Detect compiler that should be used for testing.
118 # We cannot use ExternalProject_Add() because its configuration runs when this
119 # project is built which is too late for detecting the compiler...
120 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler)
122 COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} ${CMAKE_CURRENT_LIST_DIR}/DetectTestCompiler
123 -DCMAKE_C_COMPILER=${OPENMP_TEST_C_COMPILER}
124 -DCMAKE_CXX_COMPILER=${OPENMP_TEST_CXX_COMPILER}
125 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler
126 OUTPUT_VARIABLE DETECT_COMPILER_OUT
127 ERROR_VARIABLE DETECT_COMPILER_ERR
128 RESULT_VARIABLE DETECT_COMPILER_RESULT)
129 if (DETECT_COMPILER_RESULT)
130 message(STATUS "Could not detect test compilers.")
131 message(WARNING "The check targets will not be available!")
132 set(ENABLE_CHECK_TARGETS FALSE)
134 set_test_compiler_information(${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler)
137 # Set the information that we know.
138 set(OPENMP_TEST_COMPILER_ID "Clang")
139 # Cannot use CLANG_VERSION because we are not guaranteed that this is already set.
140 set(OPENMP_TEST_COMPILER_VERSION "${LLVM_VERSION}")
141 set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${LLVM_VERSION_MAJOR}")
142 set(OPENMP_TEST_COMPILER_VERSION_MAJOR_MINOR "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}")
143 # Unfortunately the top-level cmake/config-ix.cmake file mangles CMake's
144 # CMAKE_THREAD_LIBS_INIT variable from the FindThreads package, so work
145 # around that, until it is fixed there.
146 if("${CMAKE_THREAD_LIBS_INIT}" STREQUAL "-lpthread")
147 set(OPENMP_TEST_COMPILER_THREAD_FLAGS "-pthread")
149 set(OPENMP_TEST_COMPILER_THREAD_FLAGS "${CMAKE_THREAD_LIBS_INIT}")
152 set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 1)
154 set(OPENMP_TEST_COMPILER_HAS_TSAN_FLAGS 0)
156 set(OPENMP_TEST_COMPILER_HAS_OMP_H 1)
157 set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "-fopenmp ${OPENMP_TEST_COMPILER_THREAD_FLAGS}")
158 set(OPENMP_TEST_COMPILER_HAS_OMIT_FRAME_POINTER_FLAGS 1)
161 # Function to set compiler features for use in lit.
162 function(update_test_compiler_features)
165 foreach(feat IN LISTS OPENMP_TEST_COMPILER_FEATURE_LIST)
167 string(APPEND FEATURES ", ")
170 string(APPEND FEATURES "'${feat}'")
172 string(APPEND FEATURES "]")
173 set(OPENMP_TEST_COMPILER_FEATURES ${FEATURES} PARENT_SCOPE)
176 function(set_test_compiler_features)
177 if ("${OPENMP_TEST_COMPILER_ID}" STREQUAL "GNU")
179 elseif ("${OPENMP_TEST_COMPILER_ID}" STREQUAL "Intel")
182 # Just use the lowercase of the compiler ID as fallback.
183 string(TOLOWER "${OPENMP_TEST_COMPILER_ID}" comp)
185 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)
187 set_test_compiler_features()
188 update_test_compiler_features()
190 # Function to add a testsuite for an OpenMP runtime library.
191 function(add_openmp_testsuite target comment)
192 if (NOT ENABLE_CHECK_TARGETS)
193 add_custom_target(${target}
194 COMMAND ${CMAKE_COMMAND} -E echo "${target} does nothing, dependencies not found.")
195 message(STATUS "${target} does nothing.")
199 cmake_parse_arguments(ARG "EXCLUDE_FROM_CHECK_ALL" "" "DEPENDS;ARGS" ${ARGN})
200 # EXCLUDE_FROM_CHECK_ALL excludes the test ${target} out of check-openmp.
201 if (NOT ARG_EXCLUDE_FROM_CHECK_ALL)
202 # Register the testsuites and depends for the check-openmp rule.
203 set_property(GLOBAL APPEND PROPERTY OPENMP_LIT_TESTSUITES ${ARG_UNPARSED_ARGUMENTS})
204 set_property(GLOBAL APPEND PROPERTY OPENMP_LIT_DEPENDS ${ARG_DEPENDS})
207 if (${OPENMP_STANDALONE_BUILD})
208 set(LIT_ARGS ${OPENMP_LIT_ARGS} ${ARG_ARGS})
209 add_custom_target(${target}
210 COMMAND ${Python3_EXECUTABLE} ${OPENMP_LLVM_LIT_EXECUTABLE} ${LIT_ARGS} ${ARG_UNPARSED_ARGUMENTS}
212 DEPENDS ${ARG_DEPENDS}
216 if (ARG_EXCLUDE_FROM_CHECK_ALL)
217 add_lit_testsuite(${target}
219 ${ARG_UNPARSED_ARGUMENTS}
220 EXCLUDE_FROM_CHECK_ALL
221 DEPENDS clang FileCheck not ${ARG_DEPENDS}
225 add_lit_testsuite(${target}
227 ${ARG_UNPARSED_ARGUMENTS}
228 DEPENDS clang FileCheck not ${ARG_DEPENDS}
235 function(construct_check_openmp_target)
236 get_property(OPENMP_LIT_TESTSUITES GLOBAL PROPERTY OPENMP_LIT_TESTSUITES)
237 get_property(OPENMP_LIT_DEPENDS GLOBAL PROPERTY OPENMP_LIT_DEPENDS)
239 # We already added the testsuites themselves, no need to do that again.
240 add_openmp_testsuite(check-openmp "Running OpenMP tests" ${OPENMP_LIT_TESTSUITES} EXCLUDE_FROM_CHECK_ALL DEPENDS ${OPENMP_LIT_DEPENDS})