CMake: Make qt5_use_modules a macro, not a function.
Because qt5_use_modules is a function that does a find package which
finds imported targets, things like this:
qt5_use_modules(foo Sql)
if (TARGET Qt5::Sql)
message("Qt5Sql_FOUND: ${Qt5Sql_FOUND}")
endif()
will show Qt5Sql as being not found, even though the target is in scope.
Fix that by making it a macro instead.
Change-Id: If314bd5b4d3f769c6c7df5ff2c924eabd16dcc0e
Reviewed-by: Alexander Neundorf <neundorf@kde.org>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
bb10
parent
4dbf60d672
commit
6fe8a3d5a1
|
|
@ -217,29 +217,29 @@ endfunction()
|
|||
|
||||
|
||||
if (NOT CMAKE_VERSION VERSION_LESS 2.8.9)
|
||||
function(qt5_use_modules _target _link_type)
|
||||
macro(qt5_use_modules _target _link_type)
|
||||
if (NOT TARGET ${_target})
|
||||
message(FATAL_ERROR "The first argument to qt5_use_modules must be an existing target.")
|
||||
endif()
|
||||
if ("${_link_type}" STREQUAL "LINK_PUBLIC" OR "${_link_type}" STREQUAL "LINK_PRIVATE" )
|
||||
set(modules ${ARGN})
|
||||
set(link_type ${_link_type})
|
||||
set(_qt5_modules ${ARGN})
|
||||
set(_qt5_link_type ${_link_type})
|
||||
else()
|
||||
set(modules ${_link_type} ${ARGN})
|
||||
set(_qt5_modules ${_link_type} ${ARGN})
|
||||
endif()
|
||||
|
||||
if ("${modules}" STREQUAL "")
|
||||
if ("${_qt5_modules}" STREQUAL "")
|
||||
message(FATAL_ERROR "qt5_use_modules requires at least one Qt module to use.")
|
||||
endif()
|
||||
|
||||
foreach(_module ${modules})
|
||||
foreach(_module ${_qt5_modules})
|
||||
if (NOT Qt5${_module}_FOUND)
|
||||
find_package(Qt5${_module} PATHS ${_qt5_corelib_install_prefix} NO_DEFAULT_PATH)
|
||||
if (NOT Qt5${_module}_FOUND)
|
||||
message(FATAL_ERROR "Can not use \"${_module}\" module which has not yet been found.")
|
||||
endif()
|
||||
endif()
|
||||
target_link_libraries(${_target} ${link_type} ${Qt5${_module}_LIBRARIES})
|
||||
target_link_libraries(${_target} ${_qt5_link_type} ${Qt5${_module}_LIBRARIES})
|
||||
set_property(TARGET ${_target} APPEND PROPERTY INCLUDE_DIRECTORIES ${Qt5${_module}_INCLUDE_DIRS})
|
||||
set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS ${Qt5${_module}_COMPILE_DEFINITIONS})
|
||||
set_property(TARGET ${_target} APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG)
|
||||
|
|
@ -248,5 +248,5 @@ if (NOT CMAKE_VERSION VERSION_LESS 2.8.9)
|
|||
set_property(TARGET ${_target} PROPERTY POSITION_INDEPENDENT_CODE ${Qt5_POSITION_INDEPENDENT_CODE})
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
endmacro()
|
||||
endif()
|
||||
|
|
|
|||
Loading…
Reference in New Issue