@@ -2,59 +2,6 @@ cmake_minimum_required(VERSION 3.16)
22
33include (${CMAKE_CURRENT_LIST_DIR} /mo2_utils.cmake )
44
5- #! mo2_python_uifiles : create .py files from .ui files for a python target
6- #
7- # \param:TARGET target to generate .py files for
8- # \param:INPLACE if specified, .py files are generated next to the .ui files, useful
9- # for Python modules, otherwise files are generated in the binary directory
10- # \param:FILES list of .ui files to generate .py files from
11- #
12- function (mo2_python_uifiles TARGET )
13- cmake_parse_arguments (MO2 "INPLACE" "" "FILES" ${ARGN} )
14-
15- if (NOT MO2_FILES)
16- return ()
17- endif ()
18-
19- mo2_find_python_executable (PYTHON_EXE )
20-
21- message (DEBUG "generating .py from ui files: ${MO2_FILES} " )
22-
23- set (pyui_files "" )
24- foreach (UI_FILE ${MO2_FILES} )
25- get_filename_component (name "${UI_FILE} " NAME_WLE )
26- if (${MO2_INPLACE} )
27- get_filename_component (folder "${UI_FILE} " DIRECTORY )
28- else ()
29- set (folder "${CMAKE_CURRENT_BINARY_DIR} " )
30- endif ()
31-
32- set (output "${folder} /${name} .py" )
33- add_custom_command (
34- OUTPUT "${output} "
35- COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/pylibs
36- ${CMAKE_BINARY_DIR} /pylibs/bin/pyuic${Qt_VERSION_MAJOR}.exe
37- -o "${output} "
38- "${UI_FILE} "
39- DEPENDS "${UI_FILE} "
40- )
41-
42- list (APPEND pyui_files "${output} " )
43- endforeach ()
44-
45- if (${MO2_INPLACE} )
46- source_group (TREE ${CMAKE_CURRENT_SOURCE_DIR}
47- PREFIX autogen FILES ${pyui_files} )
48- endif ()
49-
50- add_custom_target ("${TARGET} _uic" DEPENDS ${pyui_files} )
51- set_target_properties ("${TARGET} _uic" PROPERTIES FOLDER autogen )
52-
53- add_dependencies (${TARGET} "${TARGET} _uic" )
54- add_dependencies ("${TARGET} _uic" PyQt6 )
55-
56- endfunction ()
57-
585#! mo2_python_pip_install : run "pip install ..."
596#
607# \param:TARGET target to install Python package for
@@ -118,6 +65,78 @@ function(mo2_python_pip_install TARGET)
11865
11966endfunction ()
12067
68+ #! mo2_python_install_pyqt : install PyQt6 and create a PyQt6 target for it
69+ #
70+ # it is safe to call this function multiple times, PyQt6 will only be installed once
71+ #
72+ function (mo2_python_install_pyqt )
73+ if (TARGET PyQt6)
74+ return ()
75+ endfunction ()
76+
77+ add_custom_target (PyQt6 )
78+ mo2_python_pip_install (PyQt6
79+ DIRECTORY ${CMAKE_BINARY_DIR} /pylibs/
80+ PACKAGES
81+ PyQt${MO2_QT_VERSION_MAJOR}==${MO2_QT_VERSION}
82+ sip==6.8.5 )
83+ endfunction ()
84+
85+ #! mo2_python_uifiles : create .py files from .ui files for a python target
86+ #
87+ # \param:TARGET target to generate .py files for
88+ # \param:INPLACE if specified, .py files are generated next to the .ui files, useful
89+ # for Python modules, otherwise files are generated in the binary directory
90+ # \param:FILES list of .ui files to generate .py files from
91+ #
92+ function (mo2_python_uifiles TARGET )
93+ cmake_parse_arguments (MO2 "INPLACE" "" "FILES" ${ARGN} )
94+
95+ if (NOT MO2_FILES)
96+ return ()
97+ endif ()
98+
99+ mo2_find_python_executable (PYTHON_EXE )
100+ mo2_python_install_pyqt ()
101+
102+ message (DEBUG "generating .py from ui files: ${MO2_FILES} " )
103+
104+ set (pyui_files "" )
105+ foreach (UI_FILE ${MO2_FILES} )
106+ get_filename_component (name "${UI_FILE} " NAME_WLE )
107+ if (${MO2_INPLACE} )
108+ get_filename_component (folder "${UI_FILE} " DIRECTORY )
109+ else ()
110+ set (folder "${CMAKE_CURRENT_BINARY_DIR} " )
111+ endif ()
112+
113+ set (output "${folder} /${name} .py" )
114+ add_custom_command (
115+ OUTPUT "${output} "
116+ COMMAND ${CMAKE_COMMAND} -E env PYTHONPATH=${CMAKE_BINARY_DIR}/pylibs
117+ ${CMAKE_BINARY_DIR} /pylibs/bin/pyuic${Qt_VERSION_MAJOR}.exe
118+ -o "${output} "
119+ "${UI_FILE} "
120+ DEPENDS "${UI_FILE} "
121+ )
122+
123+ list (APPEND pyui_files "${output} " )
124+ endforeach ()
125+
126+ if (${MO2_INPLACE} )
127+ source_group (TREE ${CMAKE_CURRENT_SOURCE_DIR}
128+ PREFIX autogen FILES ${pyui_files} )
129+ endif ()
130+
131+ add_custom_target ("${TARGET} _uic" DEPENDS ${pyui_files} )
132+ set_target_properties ("${TARGET} _uic" PROPERTIES FOLDER autogen )
133+
134+ add_dependencies (${TARGET} "${TARGET} _uic" )
135+
136+ add_dependencies ("${TARGET} _uic" PyQt6 )
137+
138+ endfunction ()
139+
121140#! mo2_python_requirements : install requirements for a python target
122141#
123142# \param:TARGET target to install requirements for
0 commit comments