forked from FreeCAD/FreeCAD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFindPySideTools.cmake
101 lines (93 loc) · 4.15 KB
/
FindPySideTools.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# Try to find PySide utilities, PYSIDEUIC4 and PYSIDERCC4:
# PYSIDEUIC4BINARY - Location of PYSIDEUIC4 executable
# PYSIDERCC4BINARY - Location of PYSIDERCC4 executable
# PYSIDE_TOOLS_FOUND - PySide utilities found.
# Also provides macro similar to FindQt4.cmake's WRAP_UI and WRAP_RC,
# for the automatic generation of Python code from Qt4's user interface
# ('.ui') and resource ('.qrc') files. These macros are called:
# - PYSIDE_WRAP_UI
# - PYSIDE_WRAP_RC
IF(PYSIDEUIC4BINARY AND PYSIDERCC4BINARY)
# Already in cache, be silent
set(PYSIDE_TOOLS_FOUND_QUIETLY TRUE)
ENDIF(PYSIDEUIC4BINARY AND PYSIDERCC4BINARY)
if(WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
#pyside tools are often in same location as python interpreter
get_filename_component(PYTHON_BIN_DIR ${PYTHON_EXECUTABLE} PATH)
set(PYSIDE_BIN_DIR ${PYTHON_BIN_DIR})
endif(WIN32 OR ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
FIND_PROGRAM(PYSIDEUIC4BINARY NAMES python2-pyside-uic pyside-uic pyside-uic-${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} HINTS ${PYSIDE_BIN_DIR})
FIND_PROGRAM(PYSIDERCC4BINARY NAMES pyside-rcc pyside-rcc-${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR} HINTS ${PYSIDE_BIN_DIR})
MACRO(PYSIDE_WRAP_UI outfiles)
FOREACH(it ${ARGN})
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
SET(outfile ${CMAKE_CURRENT_BINARY_DIR}/ui_${outfile}.py)
#ADD_CUSTOM_TARGET(${it} ALL
# DEPENDS ${outfile}
#)
if(WIN32)
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
COMMAND ${PYSIDEUIC4BINARY} ${infile} -o ${outfile}
MAIN_DEPENDENCY ${infile}
)
else(WIN32)
# Especially on Open Build Service we don't want changing date like
# pyside-uic generates in comments at beginning, which is why
# we follow the tool command with in-place sed.
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
COMMAND "${PYSIDEUIC4BINARY}" "${infile}" -o "${outfile}"
COMMAND sed -i "/^# /d" "${outfile}"
MAIN_DEPENDENCY "${infile}"
)
endif(WIN32)
list(APPEND ${outfiles} ${outfile})
ENDFOREACH(it)
ENDMACRO (PYSIDE_WRAP_UI)
MACRO(PYSIDE_WRAP_RC outfiles)
FOREACH(it ${ARGN})
GET_FILENAME_COMPONENT(outfile ${it} NAME_WE)
GET_FILENAME_COMPONENT(infile ${it} ABSOLUTE)
SET(outfile "${CMAKE_CURRENT_BINARY_DIR}/${outfile}_rc.py")
#ADD_CUSTOM_TARGET(${it} ALL
# DEPENDS ${outfile}
#)
if (${PYTHON_VERSION_MAJOR} LESS 3)
SET(PY_ATTRIBUTE "")
else (${PYTHON_VERSION_MAJOR} LESS 3)
SET(PY_ATTRIBUTE "-py3")
endif (${PYTHON_VERSION_MAJOR} LESS 3)
if(WIN32)
ADD_CUSTOM_COMMAND(OUTPUT ${outfile}
COMMAND ${PYSIDERCC4BINARY} ${infile} ${PY_ATTRIBUTE} -o ${outfile}
MAIN_DEPENDENCY ${infile}
)
else(WIN32)
# Especially on Open Build Service we don't want changing date like
# pyside-rcc generates in comments at beginning, which is why
# we follow the tool command with in-place sed.
ADD_CUSTOM_COMMAND(OUTPUT "${outfile}"
COMMAND "${PYSIDERCC4BINARY}" "${infile}" ${PY_ATTRIBUTE} -o "${outfile}"
COMMAND sed -i "/^# /d" "${outfile}"
MAIN_DEPENDENCY "${infile}"
)
endif(WIN32)
list(APPEND ${outfiles} ${outfile})
ENDFOREACH(it)
ENDMACRO (PYSIDE_WRAP_RC)
IF(EXISTS ${PYSIDEUIC4BINARY} AND EXISTS ${PYSIDERCC4BINARY})
set(PYSIDE_TOOLS_FOUND TRUE)
ENDIF(EXISTS ${PYSIDEUIC4BINARY} AND EXISTS ${PYSIDERCC4BINARY})
if(PYSIDERCC4BINARY AND PYSIDEUIC4BINARY)
if (NOT PySideTools_FIND_QUIETLY)
message(STATUS "Found PySide Tools: ${PYSIDEUIC4BINARY}, ${PYSIDERCC4BINARY}")
endif (NOT PySideTools_FIND_QUIETLY)
else(PYSIDERCC4BINARY AND PYSIDEUIC4BINARY)
if(PySideTools_FIND_REQUIRED)
message(FATAL_ERROR "PySideTools could not be found, but are required.")
else(PySideTools_FIND_REQUIRED)
if (NOT PySideTools_FIND_QUIETLY)
message(STATUS "PySideTools: not found.")
endif (NOT PySideTools_FIND_QUIETLY)
endif(PySideTools_FIND_REQUIRED)
endif(PYSIDERCC4BINARY AND PYSIDEUIC4BINARY)