From f1b688bc7c33d93993945e25b9d3aa4cc7215c5f Mon Sep 17 00:00:00 2001 From: Simon Hausmann Date: Mon, 11 Feb 2019 13:13:43 +0100 Subject: [PATCH] Fix qt_config_compile_test when cross-compiling When we do qt_config_compile_test(egl_x11 LABEL "EGL on X11" LIBRARIES X11::X11 ... ) then check_cxx_source_compiles() aborts if the provided targets do not exist (we map LIBRARIES to CMAKE_REQUIRED_LIBRARIES). However we just want the test to fail. Therefore this patch verifies the presence of the targets. Change-Id: Ibd7c1b50d585339af0ca0de58bc5c9cd64d65d6d Reviewed-by: Kevin Funk --- cmake/QtFeature.cmake | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index 79663c17a38..4a8449405e7 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -387,10 +387,24 @@ endfunction() function(qt_config_compile_test name) cmake_parse_arguments(arg "" "LABEL" "LIBRARIES;CODE" ${ARGN}) - set(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") - set(CMAKE_REQUIRED_LIBRARIES "${arg_LIBRARIES}") - check_cxx_source_compiles("${arg_UNPARSED_ARGUMENTS} ${arg_CODE}" HAVE_${name}) - set(CMAKE_REQUIRED_LIBRARIES "${_save_CMAKE_REQUIRED_LIBRARIES}") + foreach(library IN ITEMS ${arg_LIBRARIES}) + if(NOT TARGET "${library}") + # If the dependency looks like a cmake target, then make this compile test + # fail instead of cmake abort later via CMAKE_REQUIRED_LIBRARIES. + string(FIND "${library}" "::" cmake_target_namespace_separator) + if(NOT cmake_target_namespace_separator EQUAL -1) + set(HAVE_${name} FALSE) + break() + endif() + endif() + endforeach() + + if(NOT DEFINED HAVE_${name}) + set(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") + set(CMAKE_REQUIRED_LIBRARIES "${arg_LIBRARIES}") + check_cxx_source_compiles("${arg_UNPARSED_ARGUMENTS} ${arg_CODE}" HAVE_${name}) + set(CMAKE_REQUIRED_LIBRARIES "${_save_CMAKE_REQUIRED_LIBRARIES}") + endif() set(TEST_${name} "${HAVE_${name}}" CACHE INTERNAL "${arg_LABEL}") endfunction()