Skip to content

Commit 8a47fd7

Browse files
committed
Add PyQt5 CMake script
1 parent 997ed1b commit 8a47fd7

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

CMake/FindPyQt5.cmake

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Try to find PYQT5 utilities, pyuic5 and pyrcc5:
2+
# PYUIC5BINARY - Location of pyuic5 executable
3+
# PYRCC5BINARY - Location of pyrcc5 executable
4+
# PYQT5_FOUND - PYQT5 utilities found.
5+
6+
# Also provides macro similar to FindQt5.cmake's WRAP_UI and WRAP_RC,
7+
# for the automatic generation of Python code from Qt5's user interface
8+
# ('.ui') and resource ('.qrc') files. These macros are called:
9+
# - PYQT5_WRAP_UI
10+
# - PYQT5_WRAP_RC
11+
12+
IF(PYUIC5BINARY AND PYRCC5BINARY)
13+
# Already in cache, be silent
14+
set(PYQT5_FIND_QUIETLY TRUE)
15+
ENDIF(PYUIC5BINARY AND PYRCC5BINARY)
16+
17+
if(WIN32)
18+
FIND_PROGRAM(PYUIC5BINARY pyuic5.bat)
19+
FIND_PROGRAM(PYRCC5BINARY pyrcc5)
20+
endif(WIN32)
21+
if(APPLE)
22+
FIND_PROGRAM( PYUIC5BINARY pyuic5
23+
HINTS ${PYTHON_BIN_DIR}
24+
)
25+
FIND_PROGRAM(PYRCC5BINARY pyrcc5
26+
HINTS ${PYTHON_BIN_DIR}
27+
)
28+
endif(APPLE)
29+
#message(STATUS "PYUIC5BINARY ${PYUIC5BINARY}" )
30+
#message(STATUS "PYRCC5BINARY ${PYRCC5BINARY}" )
31+
32+
MACRO(PYQT5_WRAP_UI outfiles)
33+
FOREACH(it ${ARGN})
34+
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
35+
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
36+
SET(outfile ${CMAKE_CURRENT_SOURCE_DIR}/ui_${outfile}.py)
37+
ADD_CUSTOM_TARGET(${it} ALL
38+
DEPENDS ${outfile}
39+
)
40+
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
41+
COMMAND ${PYUIC5BINARY} ${infile} -o ${outfile}
42+
MAIN_DEPENDENCY ${infile}
43+
)
44+
SET(${outfiles} ${${outfiles}} ${outfile})
45+
ENDFOREACH(it)
46+
ENDMACRO (PYQT5_WRAP_UI)
47+
48+
MACRO(PYQT5_WRAP_RC outfiles)
49+
FOREACH(it ${ARGN})
50+
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
51+
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
52+
SET(outfile ${CMAKE_CURRENT_SOURCE_DIR}/${outfile}_rc.py)
53+
message("target: ${it}")
54+
# remove slashes from the filename because target names can't have slashes in them
55+
string(REPLACE "/" "-" target-name ${it} )
56+
57+
ADD_CUSTOM_TARGET(${target-name} ALL
58+
DEPENDS ${outfile}
59+
)
60+
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
61+
COMMAND ${PYRCC5BINARY} ${infile} -o ${outfile}
62+
MAIN_DEPENDENCY ${infile}
63+
)
64+
SET(${outfiles} ${${outfiles}} ${outfile})
65+
ENDFOREACH(it)
66+
ENDMACRO (PYQT5_WRAP_RC)
67+
68+
IF(EXISTS ${PYUIC5BINARY} AND EXISTS ${PYRCC5BINARY})
69+
set(PYQT5_FOUND TRUE)
70+
ENDIF(EXISTS ${PYUIC5BINARY} AND EXISTS ${PYRCC5BINARY})
71+
72+
if(PYQT5_FOUND)
73+
if(NOT PYQT5_FIND_QUIETLY)
74+
message(STATUS "Found PYQT5: ${PYUIC5BINARY}, ${PYRCC5BINARY}")
75+
endif(NOT PYQT5_FIND_QUIETLY)
76+
endif(PYQT5_FOUND)

0 commit comments

Comments
 (0)