# -------------------------------- Qt -------------------------------- set(FREECAD_QT_COMPONENTS Core Concurrent Network Xml) if(FREECAD_WEB AND NOT FREECAD_WEB_ENABLE_TECHDRAW_NATIVE) # QtConcurrent is only used by GUI code in the current Web module graph. set(FREECAD_QT_COMPONENTS Core Network Xml) endif() if(FREECAD_WEB AND FREECAD_WEB_ENABLE_TECHDRAW_NATIVE) list(APPEND FREECAD_QT_COMPONENTS Gui Widgets) endif() if (FREECAD_QT_MAJOR_VERSION EQUAL 6) set (Qt6Core_MOC_EXECUTABLE Qt6::moc) endif() if(BUILD_GUI) if (FREECAD_QT_MAJOR_VERSION EQUAL 5) if (WIN32) list (APPEND FREECAD_QT_COMPONENTS WinExtras) endif() elseif (FREECAD_QT_MAJOR_VERSION EQUAL 6) list (APPEND FREECAD_QT_COMPONENTS GuiTools) list (APPEND FREECAD_QT_COMPONENTS SvgWidgets) list (APPEND FREECAD_QT_COMPONENTS OpenGLWidgets) endif() list (APPEND FREECAD_QT_COMPONENTS OpenGL PrintSupport Svg UiTools Widgets LinguistTools) if(BUILD_DESIGNER_PLUGIN) list (APPEND FREECAD_QT_COMPONENTS Designer) endif() endif() if (ENABLE_DEVELOPER_TESTS) list (APPEND FREECAD_QT_COMPONENTS Test) endif () foreach(COMPONENT IN LISTS FREECAD_QT_COMPONENTS) find_package(Qt${FREECAD_QT_MAJOR_VERSION} REQUIRED COMPONENTS ${COMPONENT}) set(Qt${COMPONENT}_LIBRARIES ${Qt${FREECAD_QT_MAJOR_VERSION}${COMPONENT}_LIBRARIES}) set(Qt${COMPONENT}_INCLUDE_DIRS ${Qt${FREECAD_QT_MAJOR_VERSION}${COMPONENT}_INCLUDE_DIRS}) set(Qt${COMPONENT}_FOUND ${Qt${FREECAD_QT_MAJOR_VERSION}${COMPONENT}_FOUND}) set(Qt${COMPONENT}_VERSION ${Qt${FREECAD_QT_MAJOR_VERSION}${COMPONENT}_VERSION}) endforeach() # QtBase does not ship the LinguistTools CMake module. The Web dependency # prefix intentionally builds only QtBase, so provide the small part of # qt_add_translation needed by core resource generation using host lrelease. if(FREECAD_WEB AND NOT COMMAND qt_add_translation) find_program(FREECAD_WEB_LRELEASE_EXECUTABLE NAMES lrelease lrelease-qt5) if(NOT FREECAD_WEB_LRELEASE_EXECUTABLE) message(FATAL_ERROR "FREECAD_WEB requires a host lrelease executable to build translations") endif() function(qt_add_translation _qm_files) set(_generated_qm_files) foreach(_ts_file IN LISTS ARGN) get_filename_component(_ts_name "${_ts_file}" NAME_WE) get_source_file_property(_output_location "${_ts_file}" OUTPUT_LOCATION) if(NOT _output_location OR _output_location STREQUAL "NOTFOUND") set(_output_location "${CMAKE_CURRENT_BINARY_DIR}") endif() set(_qm_file "${_output_location}/${_ts_name}.qm") add_custom_command( OUTPUT "${_qm_file}" COMMAND ${CMAKE_COMMAND} -E make_directory "${_output_location}" COMMAND "${FREECAD_WEB_LRELEASE_EXECUTABLE}" "${_ts_file}" -qm "${_qm_file}" DEPENDS "${_ts_file}" VERBATIM) list(APPEND _generated_qm_files "${_qm_file}") endforeach() set(${_qm_files} "${_generated_qm_files}" PARENT_SCOPE) endfunction() endif() set(CMAKE_AUTOMOC TRUE) set(CMAKE_AUTOUIC TRUE) set(QtCore_MOC_EXECUTABLE ${Qt${FREECAD_QT_MAJOR_VERSION}Core_MOC_EXECUTABLE}) add_definitions(-DQT_NO_KEYWORDS) message(STATUS "Set up to compile with Qt ${Qt${FREECAD_QT_MAJOR_VERSION}Core_VERSION}") # In Qt 5.15 they added more generic names for these functions: "backport" those new names # so we can migrate to using the non-version-named functions in all instances. if (Qt${FREECAD_QT_MAJOR_VERSION}Core_VERSION VERSION_LESS 5.15.0) message(STATUS "Manually creating qt_wrap_cpp() and qt_add_resources() to support Qt ${Qt${FREECAD_QT_MAJOR_VERSION}Core_VERSION}") # Wrapper code adapted from Qt 6's Qt6CoreMacros.cmake file: function(qt_add_resources outfiles) qt5_add_resources("${outfiles}" ${ARGN}) if(TARGET ${outfiles}) cmake_parse_arguments(PARSE_ARGV 1 arg "" "OUTPUT_TARGETS" "") if (arg_OUTPUT_TARGETS) set(${arg_OUTPUT_TARGETS} ${${arg_OUTPUT_TARGETS}} PARENT_SCOPE) endif() else() set("${outfiles}" "${${outfiles}}" PARENT_SCOPE) endif() endfunction() function(qt_wrap_cpp outfiles) qt5_wrap_cpp("${outfiles}" ${ARGN}) set("${outfiles}" "${${outfiles}}" PARENT_SCOPE) endfunction() function(qt_add_translation _qm_files) qt5_add_translation("${_qm_files}" ${ARGN}) set("${_qm_files}" "${${_qm_files}}" PARENT_SCOPE) endfunction() # Since Qt 5.15 Q_DISABLE_COPY_MOVE is defined set (HAVE_Q_DISABLE_COPY_MOVE 0) else() # Since Qt 5.15 Q_DISABLE_COPY_MOVE is defined set (HAVE_Q_DISABLE_COPY_MOVE 1) endif() configure_file(${CMAKE_SOURCE_DIR}/src/QtCore.h.cmake ${CMAKE_BINARY_DIR}/src/QtCore.h) configure_file(${CMAKE_SOURCE_DIR}/src/QtWidgets.h.cmake ${CMAKE_BINARY_DIR}/src/QtWidgets.h) function(qt_find_and_add_translation _qm_files _tr_dir _qm_dir) file(GLOB _ts_files ${_tr_dir}) set_source_files_properties(${_ts_files} PROPERTIES OUTPUT_LOCATION ${_qm_dir}) qt_add_translation("${_qm_files}" ${_ts_files}) set("${_qm_files}" "${${_qm_files}}" PARENT_SCOPE) endfunction() function(qt_create_resource_file outfile) set(QRC "\n \n") foreach (it ${ARGN}) get_filename_component(qmfile "${it}" NAME) string(APPEND QRC " translations/${qmfile}") endforeach() string(APPEND QRC " \n\n") file(WRITE ${outfile} ${QRC}) endfunction() function(qt_create_resource_file_prefix outfile) set(QRC "\n \n") foreach (it ${ARGN}) get_filename_component(qmfile "${it}" NAME) string(APPEND QRC " ${qmfile}") endforeach() string(APPEND QRC " \n\n") file(WRITE ${outfile} ${QRC}) endfunction()