Skip to content

Commit 2ad8594

Browse files
jcfrjamesobutler
authored andcommitted
cmake: Add PythonQtConfigure.h to map CMake option to public macro
Introduce `PythonQtConfigure.h` to derive `PYTHONQT_USE_RELEASE_PYTHON_FALLBACK` from the CMake option `PythonQt_USE_RELEASE_PYTHON_FALLBACK`. Export build-tree binary include dir and install the configured header so `#include <PythonQtConfigure.h>` works for both build and install trees. Stop requiring downstreams to set the macro via compile definitions; users can still override by predefining `PYTHONQT_USE_RELEASE_PYTHON_FALLBACK`.
1 parent 10846ad commit 2ad8594

3 files changed

Lines changed: 67 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,23 @@ foreach(qtlib ${qtlibs})
267267
endif()
268268
endforeach()
269269

270+
#-----------------------------------------------------------------------------
271+
# Configure header
272+
273+
# Map the CMake option `PythonQt_USE_RELEASE_PYTHON_FALLBACK` (camelCase)
274+
# to a plain variable used by the configured header. The public-facing
275+
# preprocessor symbol remains `PYTHONQT_USE_RELEASE_PYTHON_FALLBACK`.
276+
set(PYTHONQT_USE_RELEASE_PYTHON_FALLBACK ${PythonQt_USE_RELEASE_PYTHON_FALLBACK})
277+
configure_file(
278+
src/PythonQtConfigure.h.in
279+
${CMAKE_CURRENT_BINARY_DIR}/src/PythonQtConfigure.h
280+
)
281+
unset(PYTHONQT_USE_RELEASE_PYTHON_FALLBACK)
282+
283+
list(APPEND headers
284+
${CMAKE_CURRENT_BINARY_DIR}/src/PythonQtConfigure.h
285+
)
286+
270287
#-----------------------------------------------------------------------------
271288
# Do wrapping
272289
pythonqt_wrap_cpp(gen_moc_sources ${moc_sources})
@@ -284,8 +301,8 @@ target_compile_definitions(PythonQt
284301
PRIVATE
285302
$<$<BOOL:${PythonQt_DEBUG}>:PYTHONQT_DEBUG>
286303
$<$<BOOL:${PythonQt_SUPPORT_NAME_PROPERTY}>:PYTHONQT_SUPPORT_NAME_PROPERTY>
287-
PUBLIC
288-
$<$<BOOL:${PythonQt_USE_RELEASE_PYTHON_FALLBACK}>:PYTHONQT_USE_RELEASE_PYTHON_FALLBACK>
304+
# No need to export PYTHONQT_USE_RELEASE_PYTHON_FALLBACK publicly. the
305+
# configured header handles consumers.
289306
)
290307

291308
target_compile_options(PythonQt PRIVATE
@@ -295,6 +312,7 @@ target_compile_options(PythonQt PRIVATE
295312
target_include_directories(PythonQt
296313
PUBLIC
297314
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
315+
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
298316
$<INSTALL_INTERFACE:${PythonQt_INSTALL_INCLUDE_DIR}>
299317
PRIVATE
300318
# Required for use of "QtCore/private/qmetaobjectbuilder_p.h" in "PythonQt.cpp"

src/PythonQtConfigure.h.in

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
*
3+
* Copyright (C) 2025 MeVis Medical Solutions AG All Rights Reserved.
4+
* Copyright (C) 2025 Kitware, Inc.
5+
*
6+
* This library is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 2.1 of the License, or (at your option) any later version.
10+
*
11+
* This library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* Further, this software is distributed without any warranty that it is
17+
* free of the rightful claim of any third person regarding infringement
18+
* or the like. Any license provided herein, whether implied or
19+
* otherwise, applies only to this software file. Patent licenses, if
20+
* any, provided herein do not apply to combinations of this program with
21+
* other software, or any other product whatsoever.
22+
*
23+
* You should have received a copy of the GNU Lesser General Public
24+
* License along with this library; if not, write to the Free Software
25+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26+
*
27+
* Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
28+
* 28359 Bremen, Germany or:
29+
*
30+
* http://www.mevis.de
31+
*
32+
*/
33+
34+
#ifndef _PYTHONQTCONFIGURE_H
35+
#define _PYTHONQTCONFIGURE_H
36+
37+
// If the user has not pre-defined the macro, derive it from the CMake
38+
// configure-time variable `PYTHONQT_USE_RELEASE_PYTHON_FALLBACK`, which
39+
// mirrors the `PythonQt_USE_RELEASE_PYTHON_FALLBACK` (camelCase) CMake
40+
// option.
41+
#ifndef PYTHONQT_USE_RELEASE_PYTHON_FALLBACK
42+
#cmakedefine PYTHONQT_USE_RELEASE_PYTHON_FALLBACK
43+
#endif
44+
45+
#endif

src/PythonQtPythonInclude.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#ifndef __PythonQtPythonInclude_h
3434
#define __PythonQtPythonInclude_h
3535

36+
#include <PythonQtConfigure.h>
37+
3638
// Undefine macros that features.h defines to avoid redefinition warning
3739
#ifdef _POSIX_C_SOURCE
3840
#undef _POSIX_C_SOURCE

0 commit comments

Comments
 (0)