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 <kevin.funk@kdab.com>
This commit is contained in:
Simon Hausmann 2019-02-11 13:13:43 +01:00
parent 988162eaf8
commit f1b688bc7c

View File

@ -387,10 +387,24 @@ endfunction()
function(qt_config_compile_test name)
cmake_parse_arguments(arg "" "LABEL" "LIBRARIES;CODE" ${ARGN})
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()