Skip to content

Commit 4d4800b

Browse files
committed
[commontk] cmake: Introduce PythonQt_GENERATED_PATH variable
1 parent 606939f commit 4d4800b

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

CMakeLists.txt

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,13 +135,18 @@ if(UNIX)
135135
endif()
136136

137137
#-----------------------------------------------------------------------------
138-
# The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers
139-
# associated with the Qt version being used.
140-
141-
if("${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}" VERSION_GREATER_EQUAL "5.15")
142-
set(generated_cpp_suffix "_515")
143-
else()
144-
message(FATAL_ERROR "Generated wrappers only available for Qt >= 5.15 (found ${QT_VERSION}).")
138+
# Pre-generated wrappers default to Qt 5.15 set (generated_cpp_515). Users may override.
139+
set(generated_cpp_suffix "_515")
140+
set(_default_generated_path "${CMAKE_CURRENT_SOURCE_DIR}/generated_cpp${generated_cpp_suffix}")
141+
142+
set(PythonQt_GENERATED_PATH "${_default_generated_path}"
143+
CACHE PATH "Directory containing pre-generated PythonQt Qt wrappers for Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR} (e.g., generated_cpp_515)")
144+
145+
if(NOT IS_DIRECTORY "${PythonQt_GENERATED_PATH}")
146+
message(FATAL_ERROR
147+
"PythonQt: missing generated wrapper sources for Qt ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.\n"
148+
"Expected: ${PythonQt_GENERATED_PATH}\n"
149+
"Hint: pass -DPythonQt_GENERATED_PATH:PATH=/path/to/generated_cpp")
145150
endif()
146151

147152
#-----------------------------------------------------------------------------
@@ -172,10 +177,10 @@ set(sources
172177

173178
extensions/PythonQt_QtAll/PythonQt_QtAll.cpp
174179

175-
generated_cpp${generated_cpp_suffix}/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin0.cpp
176-
generated_cpp${generated_cpp_suffix}/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin_init.cpp
177-
generated_cpp${generated_cpp_suffix}/com_trolltech_qt_gui_builtin/com_trolltech_qt_gui_builtin0.cpp
178-
generated_cpp${generated_cpp_suffix}/com_trolltech_qt_gui_builtin/com_trolltech_qt_gui_builtin_init.cpp
180+
${PythonQt_GENERATED_PATH}/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin0.cpp
181+
${PythonQt_GENERATED_PATH}/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin_init.cpp
182+
${PythonQt_GENERATED_PATH}/com_trolltech_qt_gui_builtin/com_trolltech_qt_gui_builtin0.cpp
183+
${PythonQt_GENERATED_PATH}/com_trolltech_qt_gui_builtin/com_trolltech_qt_gui_builtin_init.cpp
179184
)
180185

181186
#-----------------------------------------------------------------------------
@@ -225,18 +230,18 @@ foreach(qtlib ${qtlibs})
225230
string(TOUPPER ${qt_wrapped_lib} qt_wrapped_lib_uppercase)
226231
ADD_DEFINITIONS(-DPYTHONQT_WITH_${qt_wrapped_lib_uppercase})
227232

228-
set(file_prefix generated_cpp${generated_cpp_suffix}/com_trolltech_qt_${qt_wrapped_lib}/com_trolltech_qt_${qt_wrapped_lib})
233+
set(file_prefix com_trolltech_qt_${qt_wrapped_lib}/com_trolltech_qt_${qt_wrapped_lib})
229234

230235
foreach(index RANGE 0 12)
231236

232237
# Source files
233-
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file_prefix}${index}.cpp)
234-
list(APPEND sources ${file_prefix}${index}.cpp)
238+
if(EXISTS ${PythonQt_GENERATED_PATH}/${file_prefix}${index}.cpp)
239+
list(APPEND sources ${PythonQt_GENERATED_PATH}/${file_prefix}${index}.cpp)
235240
endif()
236241

237242
endforeach()
238243

239-
list(APPEND sources ${file_prefix}_init.cpp)
244+
list(APPEND sources ${PythonQt_GENERATED_PATH}/${file_prefix}_init.cpp)
240245

241246
endif()
242247
endforeach()
@@ -338,7 +343,7 @@ if(BUILD_TESTING)
338343

339344
target_include_directories(PythonQtCppTests
340345
PRIVATE
341-
$<$<BOOL:${PythonQt_Wrap_Qtcore}>:${CMAKE_CURRENT_SOURCE_DIR}/generated_cpp${generated_cpp_suffix}>
346+
$<$<BOOL:${PythonQt_Wrap_Qtcore}>:${PythonQt_GENERATED_PATH}>
342347
)
343348

344349
target_link_libraries(PythonQtCppTests PythonQt)

0 commit comments

Comments
 (0)