CMake: Fix FindWrapRt module when it's found multiple times

On Windows, when WrapRt is qt_find_pacakge()'d the first time, the
result is "not found", whereas a second time it would claim that the
package is found.

This is due to the WrapRt target being always created even if it has
no transitive dependencies, and thus a second search would check only
for the existence of the target.

Fix the module to only create the target if the relevant library
is found.

Change-Id: I5c838cbfbafb4029f96da815a0f72e4a8e6716b0
Reviewed-by: Leander Beernaert <leander.beernaert@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
Alexandru Croitor 2020-02-24 14:34:15 +01:00
parent 160184d6a5
commit 331b153be5

View File

@ -5,6 +5,8 @@ if(TARGET WrapRt)
return()
endif()
set(WrapRt_FOUND OFF)
include(CheckCXXSourceCompiles)
include(CMakePushCheckState)
@ -25,10 +27,11 @@ int main(int argc, char *argv[]) {
cmake_pop_check_state()
add_library(WrapRt INTERFACE IMPORTED)
if (LIBRT_FOUND)
target_link_libraries(WrapRt INTERFACE "${LIBRT}")
if(HAVE_GETTIME)
set(WrapRt_FOUND ON)
add_library(WrapRt INTERFACE IMPORTED)
if (LIBRT_FOUND)
target_link_libraries(WrapRt INTERFACE "${LIBRT}")
endif()
endif()
set(WrapRt_FOUND "${HAVE_GETTIME}")