# Finding and integrating Qt 5. # Qt 5 has a very good CMake integration, but the targets are # imported, so they are not visible across the whole build tree if used # in sub-CMakeLists. # As an optimization, we find all modules once here, so they can # be used anywhere without being reinitialized. cmake_minimum_required(VERSION 2.8.11) if(POLICY CMP0020) cmake_policy(SET CMP0020 NEW) endif() message(STATUS "Qt5:") find_package(Qt5Core) if(NOT Qt5Core_FOUND) message(STATUS " Problems finding the Qt 5 libraries!") message(STATUS " Try setting the env var CMAKE_PREFIX_PATH to /path/to/my/qt5/lib/cmake.") message(STATUS "") cbuild_error_msg("Failed to find Qt 5!") endif() # Find qt5's installation root dir. get_target_property(_qt5_root_dir Qt5::Core LOCATION) if(NOT _qt5_root_dir) get_target_property(_qt5_root_dir Qt5::Core IMPORTED_LOCATION_RELEASE) endif() if(NOT _qt5_root_dir) get_target_property(_qt5_root_dir Qt5::Core IMPORTED_LOCATION_DEBUG) endif() if(NOT _qt5_root_dir) message(STATUS " Unable to determine the Qt5 installation path.") message(STATUS " This script requires fixing!") message(STATUS "") cbuild_error_msg("Failed to find Qt 5 installation path!") endif() get_filename_component(_qt5_root_dir "${_qt5_root_dir}" PATH) get_filename_component(_qt5_root_dir "${_qt5_root_dir}" PATH) message(STATUS " Found version ${Qt5Core_VERSION} at \"${_qt5_root_dir}\".") # Find all module names. file(GLOB _all_mod_names RELATIVE "${_qt5_root_dir}/lib/cmake" "${_qt5_root_dir}/lib/cmake/*") #set(_qt5_modules) set(_mod_count 1) foreach (_mod_name IN LISTS _all_mod_names) if (NOT _mod_name STREQUAL "Qt5") if (NOT _mod_name STREQUAL "Qt5Core") if (NOT _mod_name STREQUAL "Qt5Enginio") # apparently a bug in the official 5.3 package. find_package(${_mod_name}) math(EXPR _mod_count "${_mod_count} + 1") #list(APPEND _qt5_modules ${_mod_name}) endif() endif() endif() endforeach() message(STATUS " Configured ${_mod_count} modules.") # Replace QT5_CREATE_TRANSLATION with a patched version. # See http://qt-project.org/forums/viewthread/28929 for why the original is broken. get_filename_component(_curr_dir "${CMAKE_CURRENT_LIST_FILE}" PATH) include("${_curr_dir}/Qt5LinguistToolsMacros.cmake") set(__QT_MOC_EXECUTABLE_qt5 "${QT_MOC_EXECUTABLE}") if(DEFINED __QT_MOC_EXECUTABLE_qt4) # Reset to Qt4 settings. set(QT_MOC_EXECUTABLE "${__QT_MOC_EXECUTABLE_qt4}") else() # Without this, we will mess up a subsequent FindQt4. unset(QT_MOC_EXECUTABLE CACHE) unset(QT_MOC_EXECUTABLE) endif() function(cbuild_use_Qt5) #message(STATUS "Now using Qt5's moc.") set(QT_MOC_EXECUTABLE "${__QT_MOC_EXECUTABLE_qt5}" PARENT_SCOPE) set(CMAKE_AUTOMOC ON PARENT_SCOPE) set(CMAKE_INCLUDE_CURRENT_DIR ON PARENT_SCOPE) endfunction() function(cbuild_add_qtest _target_name) get_target_property(_test_location ${_target_name} LOCATION) STRING(REPLACE "$(Configuration)" "$" _test_location "${_test_location}") # We're using the alternative form of add_test that allows for generator expressions. add_test(NAME ${_target_name} COMMAND ${_test_location} "-o" "-,txt" "-o" "${_target_name}_qtestresults.txt,txt" "-o" "${_target_name}_qtestresults.xml,xml" "-o" "${_target_name}_qtestresults.csv,csv" ${ARGN}) if (NOT TARGET BUILD_TESTS) add_custom_target(BUILD_TESTS) set_target_properties(BUILD_TESTS PROPERTIES FOLDER CMakePredefinedTargets) endif() add_dependencies(BUILD_TESTS ${_target_name}) target_link_libraries(${_target_name} Qt5::Test) set_target_properties(${_target_name} PROPERTIES FOLDER Tests) endfunction() cbuild_set_global_var(qt5_root_dir "${_qt5_root_dir}") # wej: # This would be the safe choice, but it results in just too many errors (>500 in a gen4 build at # the time of this writing) to be practical right now. #if (COMMAND target_compile_definitions) # set_property(TARGET Qt5::Core PROPERTY INTERFACE_COMPILE_DEFINITIONS QT_NO_CAST_FROM_ASCII) #endif() ############################################################################## # Define installer package. # if (CMAKE_BUILD_TYPE STREQUAL "Debug") # set(libs_property "IMPORTED_LOCATION_DEBUG") # else() # set(libs_property "IMPORTED_LOCATION_RELEASE") # endif() # foreach(_qt5_module IN LISTS _qt5_modules) # message("module: ${_qt5_module}") # foreach(target_name IN LISTS ${_qt5_module}_LIBRARIES) # get_target_property(src_libs ${target_name} ${libs_property}) # foreach(src_lib IN LISTS src_libs) # message(" ${src_lib}") # endforeach() # endforeach() # endforeach()