0029639: CMake - rename options for building samples
[occt.git] / adm / cmake / qt_macro.cmake
CommitLineData
14bbbdcb 1#qt
2
4f4b8935 3macro (FIND_QT_PACKAGE PROJECT_LIBRARIES_DEBUG PROJECT_LIBRARIES_RELEASE PROJECT_INCLUDES)
14bbbdcb 4
5 if ("${3RDPARTY_QT_DIR}" STREQUAL "")
6 message (FATAL_ERROR "Empty Qt dir")
7 endif()
8
4f4b8935 9 if (${Qt5_FOUND})
10 #message (STATUS "Qt5 cmake configuration")
11
6822a3be 12 set(PROJECT_INCLUDES "${Qt5Widgets_INCLUDE_DIRS}" "${Qt5Quick_INCLUDE_DIRS}" "${Qt5Xml_INCLUDE_DIRS}")
13 set(PROJECT_LIBRARIES_DEBUG "${Qt5Widgets_LIBRARIES}" "${Qt5Quick_LIBRARIES}" "${Qt5Xml_LIBRARIES}")
14 set(PROJECT_LIBRARIES_RELEASE "${Qt5Widgets_LIBRARIES}" "${Qt5Quick_LIBRARIES}" "${Qt5Xml_LIBRARIES}")
1fa16152 15
16 # processing *.ts files to generate *.qm
17 find_package(Qt5LinguistTools)
18 get_target_property(QT_LRELEASE_EXECUTABLE Qt5::lrelease LOCATION)
19 mark_as_advanced(QT_LRELEASE_EXECUTABLE)
20
21 GET_FILENAME_COMPONENT(QT_BINARY_DIR ${QT_LRELEASE_EXECUTABLE} DIRECTORY)
22 MARK_AS_ADVANCED(QT_BINARY_DIR)
4f4b8935 23 else()
4f4b8935 24 #message (STATUS "Qt4 cmake configuration")
14bbbdcb 25 set(PROJECT_INCLUDES ${QT_INCLUDES})
26 if (WIN32)
6822a3be 27 set(PROJECT_LIBRARIES_DEBUG "${3RDPARTY_QT_DIR}/lib/QtCored4.lib;${3RDPARTY_QT_DIR}/lib/QtGuid4.lib;${3RDPARTY_QT_DIR}/lib/QtXmld4.lib")
28 set(PROJECT_LIBRARIES_RELEASE "${3RDPARTY_QT_DIR}/lib/QtCore4.lib;${3RDPARTY_QT_DIR}/lib/QtGui4.lib;${3RDPARTY_QT_DIR}/lib/QtXml4.lib")
14bbbdcb 29 else()
6822a3be 30 set(PROJECT_LIBRARIES_DEBUG "${3RDPARTY_QT_DIR}/lib/libQtCore.so;${3RDPARTY_QT_DIR}/lib/libQtGui.so;${3RDPARTY_QT_DIR}/lib/libQtXml.so")
31 set(PROJECT_LIBRARIES_RELEASE "${3RDPARTY_QT_DIR}/lib/libQtCore.so;${3RDPARTY_QT_DIR}/lib/libQtGui.so;${3RDPARTY_QT_DIR}/lib/libQtXml.so")
14bbbdcb 32 endif(WIN32)
1fa16152 33 find_program(QT_LRELEASE_EXECUTABLE lrelease)
14bbbdcb 34 endif()
35endmacro()
36
37
410dd2c9 38macro (FIND_AND_WRAP_MOC_FILES HEADER_FILES GENERATED_MOC_FILES)
39 set (GENERATED_MOC_FILES "")
40 foreach (FILE ${HEADER_FILES})
41 # processing only files where Q_OBJECT exists
42 file(STRINGS "${FILE}" LINES REGEX "Q_OBJECT")
43 if(LINES)
44 unset (MOC_FILE)
45 if (${Qt5_FOUND})
46 qt5_wrap_cpp(MOC_FILE ${FILE})
47 else()
48 qt4_wrap_cpp(MOC_FILE ${FILE})
49 endif()
50 #message (STATUS "... Info: next MOC file ${MOC_FILE}")
51 list(APPEND ${GENERATED_MOC_FILES} ${MOC_FILE})
52 endif(LINES)
14bbbdcb 53 endforeach (FILE)
54
55endmacro()
56
57macro (FIND_AND_WRAP_RESOURCE_FILE RESOURCE_FILE_NAME RCC_FILES)
58 if(EXISTS "${RESOURCE_FILE_NAME}")
4f4b8935 59 if (${Qt5_FOUND})
60 qt5_add_resources(RCC_FILES "${RESOURCE_FILE_NAME}")
61 else()
14bbbdcb 62 qt4_add_resources(RCC_FILES "${RESOURCE_FILE_NAME}")
63 # suppress some GCC warnings coming from source files generated from .qrc resources
64 if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
65 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-variable")
66 endif()
14bbbdcb 67 endif()
68 endif()
69endmacro()
1fa16152 70
510d9690 71macro (FIND_AND_WRAP_TS_FILE RESOURCE_FILE_NAME TARGET_FOLDER QM_FILES)
1fa16152 72 if(EXISTS "${RESOURCE_FILE_NAME}")
510d9690 73 if (${Qt5_FOUND})
74 qt5_add_translation(QM_FILES "${RESOURCE_FILE_NAME}")
75 else()
76 qt4_add_translation(QM_FILES "${RESOURCE_FILE_NAME}")
1fa16152 77 endif()
78 endif()
79endmacro()
80
81macro (FIND_AND_INSTALL_QT_RESOURCES OCCT_PACKAGE RESOURCE_FILES)
82 file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" TS_FILES REGEX ".+[.]ts")
83 file (STRINGS "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/FILES" QRC_FILES REGEX ".+[.]qrc")
84
85 string (FIND "${OCCT_PACKAGE}" "/" _index)
86 if (_index GREATER -1)
87 math (EXPR _index "${_index}")
88 string (SUBSTRING "${OCCT_PACKAGE}" 0 ${_index} OCCT_PACKAGE_NAME)
89 else()
90 set (OCCT_PACKAGE_NAME "${OCCT_PACKAGE}")
91 endif(_index GREATER -1)
92
93 #message("QRC files are: ${QRC_FILES} in ${OCCT_PACKAGE}")
94 foreach (QRC_FILE ${QRC_FILES})
95 set (QRC_FILE_RELATIVE "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${QRC_FILE}")
96 if (EXISTS ${QRC_FILE_RELATIVE})
97 FIND_AND_WRAP_RESOURCE_FILE(${QRC_FILE_RELATIVE} RCC_FILES)
98 list (APPEND ${RESOURCE_FILES} "${RCC_FILES}")
99 endif()
100 endforeach()
101
102 #message("TS files are: ${TS_FILES} in ${OCCT_PACKAGE}")
103 foreach (TS_FILE ${TS_FILES})
104 set (TS_FILE_RELATIVE "${CMAKE_SOURCE_DIR}/${RELATIVE_SOURCES_DIR}/${OCCT_PACKAGE}/${TS_FILE}")
510d9690 105 FIND_AND_WRAP_TS_FILE(${TS_FILE_RELATIVE} "${TARGET_FOLDER}/${CURRENT_MODULE}" QM_FILES)
1fa16152 106 if (EXISTS ${TS_FILE_RELATIVE})
107 list (APPEND ${RESOURCE_FILES} "${TS_FILE_RELATIVE}")
510d9690 108 list (APPEND ${RESOURCE_FILES} "${QM_FILES}")
1fa16152 109 endif()
110 endforeach()
111
112 foreach (QM_FILE ${QM_FILES})
113 INSTALL(FILES ${QM_FILE} DESTINATION "${INSTALL_DIR_RESOURCE}/samples")
114 #message("install *.qm files (${QM_FILE}) to: ${INSTALL_DIR_RESOURCE}/samples")
115 endforeach (QM_FILE ${QM_FILES})
116endmacro()
117