diff options
author | Jonas Hahnfeld <hahnjo@hahnjo.de> | 2017-11-30 17:08:31 +0000 |
---|---|---|
committer | Jonas Hahnfeld <hahnjo@hahnjo.de> | 2017-11-30 17:08:31 +0000 |
commit | fc473dee98fd8d2756983b9d039cd439e5a78f24 (patch) | |
tree | 24668270a601fa1c704f3b33a4895fec4c08f3ff /openmp/cmake | |
parent | c7832045d5e8508713cd3353ea75ff8486add49f (diff) | |
download | llvm-fc473dee98fd8d2756983b9d039cd439e5a78f24.tar.gz |
[CMake] Detect information about test compiler
Perform a nested CMake invocation to avoid writing our own parser
for compiler versions when we are not testing the in-tree compiler.
Use the extracted information to mark a test as unsupported that
hangs with Clang prior to version 4.0.1 and restrict tests for
libomptarget to Clang version 6.0.0 and later.
Differential Revision: https://reviews.llvm.org/D40083
llvm-svn: 319448
Diffstat (limited to 'openmp/cmake')
-rw-r--r-- | openmp/cmake/DetectTestCompiler/CMakeLists.txt | 19 | ||||
-rw-r--r-- | openmp/cmake/OpenMPTesting.cmake | 75 |
2 files changed, 94 insertions, 0 deletions
diff --git a/openmp/cmake/DetectTestCompiler/CMakeLists.txt b/openmp/cmake/DetectTestCompiler/CMakeLists.txt new file mode 100644 index 000000000000..82d287b8e006 --- /dev/null +++ b/openmp/cmake/DetectTestCompiler/CMakeLists.txt @@ -0,0 +1,19 @@ +cmake_minimum_required(VERSION 2.8) +project(DetectTestCompiler C CXX) + +function(write_compiler_information lang) + set(information "${CMAKE_${lang}_COMPILER}") + set(information "${information}\\;${CMAKE_${lang}_COMPILER_ID}") + set(information "${information}\\;${CMAKE_${lang}_COMPILER_VERSION}") + set(information "${information}\\;${OpenMP_${lang}_FLAGS}") + file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${lang}CompilerInformation.txt ${information}) +endfunction(write_compiler_information) + +find_package(OpenMP) +if (NOT OpenMP_Found) + set(OpenMP_C_FLAGS "-fopenmp") + set(OpenMP_CXX_FLAGS "-fopenmp") +endif() + +write_compiler_information(C) +write_compiler_information(CXX) diff --git a/openmp/cmake/OpenMPTesting.cmake b/openmp/cmake/OpenMPTesting.cmake index 3204e3e7e2df..fa6ba20a54c0 100644 --- a/openmp/cmake/OpenMPTesting.cmake +++ b/openmp/cmake/OpenMPTesting.cmake @@ -61,6 +61,81 @@ else() set(OPENMP_FILECHECK_EXECUTABLE ${LLVM_RUNTIME_OUTPUT_INTDIR}/FileCheck) endif() +# Macro to extract information about compiler from file. (no own scope) +macro(extract_test_compiler_information lang file) + file(READ ${file} information) + list(GET information 0 path) + list(GET information 1 id) + list(GET information 2 version) + list(GET information 3 openmp_flags) + + set(OPENMP_TEST_${lang}_COMPILER_PATH ${path}) + set(OPENMP_TEST_${lang}_COMPILER_ID ${id}) + set(OPENMP_TEST_${lang}_COMPILER_VERSION ${version}) + set(OPENMP_TEST_${lang}_COMPILER_OPENMP_FLAGS ${openmp_flags}) +endmacro() + +# Function to set variables with information about the test compiler. +function(set_test_compiler_information dir) + extract_test_compiler_information(C ${dir}/CCompilerInformation.txt) + extract_test_compiler_information(CXX ${dir}/CXXCompilerInformation.txt) + if (NOT("${OPENMP_TEST_C_COMPILER_ID}" STREQUAL "${OPENMP_TEST_CXX_COMPILER_ID}" AND + "${OPENMP_TEST_C_COMPILER_VERSION}" STREQUAL "${OPENMP_TEST_CXX_COMPILER_VERSION}")) + message(STATUS "Test compilers for C and C++ don't match.") + message(WARNING "The check targets will not be available!") + set(ENABLE_CHECK_TARGETS FALSE PARENT_SCOPE) + else() + set(OPENMP_TEST_COMPILER_ID "${OPENMP_TEST_C_COMPILER_ID}" PARENT_SCOPE) + set(OPENMP_TEST_COMPILER_VERSION "${OPENMP_TEST_C_COMPILER_VERSION}" PARENT_SCOPE) + set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "${OPENMP_TEST_C_COMPILER_OPENMP_FLAGS}" PARENT_SCOPE) + + # Determine major version. + string(REGEX MATCH "[0-9]+" major "${OPENMP_TEST_C_COMPILER_VERSION}") + set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${major}" PARENT_SCOPE) + endif() +endfunction() + +if (${OPENMP_STANDALONE_BUILD}) + # Detect compiler that should be used for testing. + # We cannot use ExternalProject_Add() because its configuration runs when this + # project is built which is too late for detecting the compiler... + file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler) + execute_process( + COMMAND ${CMAKE_COMMAND} ${CMAKE_CURRENT_LIST_DIR}/DetectTestCompiler + -DCMAKE_C_COMPILER=${OPENMP_TEST_C_COMPILER} + -DCMAKE_CXX_COMPILER=${OPENMP_TEST_CXX_COMPILER} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler + OUTPUT_VARIABLE DETECT_COMPILER_OUT + ERROR_VARIABLE DETECT_COMPILER_ERR + RESULT_VARIABLE DETECT_COMPILER_RESULT) + if (DETECT_COMPILER_RESULT) + message(STATUS "Could not detect test compilers.") + message(WARNING "The check targets will not be available!") + set(ENABLE_CHECK_TARGETS FALSE) + else() + set_test_compiler_information(${CMAKE_CURRENT_BINARY_DIR}/DetectTestCompiler) + endif() +else() + # Set the information that we know. + set(OPENMP_TEST_COMPILER_ID "Clang") + # Cannot use CLANG_VERSION because we are not guaranteed that this is already set. + set(OPENMP_TEST_COMPILER_VERSION "${LLVM_VERSION}") + set(OPENMP_TEST_COMPILER_VERSION_MAJOR "${LLVM_MAJOR_VERSION}") + set(OPENMP_TEST_COMPILER_OPENMP_FLAGS "-fopenmp") +endif() + +# Function to set compiler features for use in lit. +function(set_test_compiler_features) + if ("${OPENMP_TEST_COMPILER_ID}" STREQUAL "GNU") + set(comp "gcc") + else() + # Just use the lowercase of the compiler ID as fallback. + string(TOLOWER "${OPENMP_TEST_COMPILER_ID}" comp) + endif() + set(OPENMP_TEST_COMPILER_FEATURES "['${comp}', '${comp}-${OPENMP_TEST_COMPILER_VERSION_MAJOR}', '${comp}-${OPENMP_TEST_COMPILER_VERSION}']" PARENT_SCOPE) +endfunction() +set_test_compiler_features() + # Function to add a testsuite for an OpenMP runtime library. function(add_openmp_testsuite target comment) if (NOT ENABLE_CHECK_TARGETS) |