Skip to content

Commit a1a5aed

Browse files
jcfrjamesobutler
authored andcommitted
cmake(generator): Modernize generator build-system
- Leverages automatic execution of MOC and RCC. - Removes obsolete install rules for `build_*.txt` and `typesystem_*.xml`. - Uses "usage requirements" and aligns source lists with `parser/rxx.pro`, `simplecpp/simplecpp.pri`, `generator.pri`, and `generator.pro`.
1 parent 1e69790 commit a1a5aed

1 file changed

Lines changed: 43 additions & 97 deletions

File tree

generator/CMakeLists.txt

Lines changed: 43 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
1-
cmake_minimum_required(VERSION 2.8)
1+
cmake_minimum_required(VERSION 3.20.6)
22

3-
#-----------------------------------------------------------------------------
4-
project(PythonQtGenerator)
5-
#-----------------------------------------------------------------------------
6-
7-
include(CTestUseLaunchers OPTIONAL)
3+
project(PythonQtGenerator LANGUAGES CXX)
84

9-
#-----------------------------------------------------------------------------
5+
#----------------------------------------------------------------------------
106
# Setup Qt
117

12-
set(minimum_required_qt_version "4.6.2")
13-
14-
find_package(Qt4)
8+
# Set PythonQtGenerator_QT_VERSION
9+
set(PythonQtGenerator_QT_VERSION 5)
1510

16-
if(QT4_FOUND)
11+
set(minimum_required_qt5_version "5.15.0")
12+
set(minimum_required_qt_version ${minimum_required_qt${PythonQtGenerator_QT_VERSION}_version})
1713

18-
set(found_qt_version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})
14+
set(qt_required_components Core Xml)
1915

20-
if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version})
21-
message(FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version}.")
22-
endif()
16+
message(STATUS "${PROJECT_NAME}: Required Qt${PythonQtGenerator_QT_VERSION} components [${qt_required_components}]")
2317

24-
set(QT_USE_QTXML ON)
25-
26-
include(${QT_USE_FILE})
27-
else()
28-
message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable")
29-
endif()
18+
# Requirements
19+
find_package(Qt${PythonQtGenerator_QT_VERSION} ${minimum_required_qt_version}
20+
COMPONENTS ${qt_required_components} REQUIRED)
3021

3122
#-----------------------------------------------------------------------------
3223
# Sources
3324

3425
set(sources
26+
# Based of parser/rxx.pro
3527
parser/ast.cpp
3628
parser/binder.cpp
3729
parser/class_compiler.cpp
@@ -51,108 +43,62 @@ set(sources
5143
parser/type_compiler.cpp
5244
parser/visitor.cpp
5345

46+
# Based of simplecpp/simplecpp.pri
47+
simplecpp/simplecpp.cpp
48+
49+
# Based of generator.pri
5450
abstractmetabuilder.cpp
5551
abstractmetalang.cpp
5652
asttoxml.cpp
5753
customtypes.cpp
5854
fileout.cpp
5955
generator.cpp
56+
generator.qrc
6057
generatorset.cpp
61-
generatorsetqtscript.cpp
6258
main.cpp
6359
metajava.cpp
64-
metaqtscriptbuilder.cpp
65-
metaqtscript.cpp
6660
prigenerator.cpp
6761
reporthandler.cpp
62+
typeparser.cpp
63+
typesystem.cpp
64+
65+
# Based of generator.pro
66+
generatorsetqtscript.cpp
67+
metaqtscriptbuilder.cpp
68+
metaqtscript.cpp
6869
setupgenerator.cpp
6970
shellgenerator.cpp
7071
shellheadergenerator.cpp
7172
shellimplgenerator.cpp
72-
typeparser.cpp
73-
typesystem.cpp
7473
)
7574

76-
#-----------------------------------------------------------------------------
77-
# List headers. This list is used for the install command.
75+
add_executable(${PROJECT_NAME} ${sources})
7876

79-
set(headers
77+
set_target_properties(${PROJECT_NAME}
78+
PROPERTIES
79+
AUTOMOC TRUE
80+
AUTORCC TRUE
8081
)
8182

82-
#-----------------------------------------------------------------------------
83-
# Headers that should run through moc
84-
85-
set(moc_sources
86-
fileout.h
87-
generator.h
88-
generatorset.h
89-
generatorsetqtscript.h
90-
prigenerator.h
91-
setupgenerator.h
92-
shellgenerator.h
93-
shellheadergenerator.h
94-
shellimplgenerator.h
83+
target_include_directories(${PROJECT_NAME}
84+
PUBLIC
85+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
86+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/parser>
87+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/simplecpp>
9588
)
9689

97-
#-----------------------------------------------------------------------------
98-
# UI files
99-
100-
set(ui_sources )
101-
102-
#-----------------------------------------------------------------------------
103-
# Resources
104-
105-
set(qrc_sources
106-
generator.qrc
90+
target_link_libraries(${PROJECT_NAME}
91+
PUBLIC
92+
Qt::Core
93+
Qt::Xml
10794
)
10895

109-
#-----------------------------------------------------------------------------
110-
# Do wrapping
111-
qt4_wrap_cpp(gen_moc_sources ${moc_sources})
112-
qt4_wrap_ui(gen_ui_sources ${ui_sources})
113-
qt4_add_resources(gen_qrc_sources ${qrc_sources})
114-
115-
#-----------------------------------------------------------------------------
116-
# Copy file expected by the generator and specify install rules
117-
118-
file(GLOB files_to_copy RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "build_*.txt" "typesystem_*.xml")
119-
list(APPEND files_to_copy qtscript_masterinclude.h parser/rpp/pp-qt-configuration)
120-
foreach(file ${files_to_copy})
121-
configure_file(
122-
${file}
123-
${CMAKE_CURRENT_BINARY_DIR}/${file}
124-
COPYONLY
125-
)
126-
get_filename_component(destination_dir ${file} PATH)
127-
install(FILES ${file} DESTINATION bin/${destination_dir})
128-
endforeach()
129-
130-
#-----------------------------------------------------------------------------
131-
# Build the library
132-
133-
SOURCE_GROUP("Resources" FILES
134-
${qrc_sources}
135-
${ui_sources}
136-
${files_to_copy}
96+
target_compile_definitions(${PROJECT_NAME}
97+
PRIVATE
98+
RXX_ALLOCATOR_INIT_0 # Based of parser/rxx.pro
99+
QT_NO_CAST_TO_ASCII # Based of generator.pro
137100
)
138101

139-
include_directories(
140-
${CMAKE_CURRENT_SOURCE_DIR}
141-
${CMAKE_CURRENT_SOURCE_DIR}/parser
142-
${CMAKE_CURRENT_SOURCE_DIR}/parser/rpp
143-
)
144-
145-
add_definitions(-DRXX_ALLOCATOR_INIT_0)
146-
147-
add_executable(${PROJECT_NAME}
148-
${sources}
149-
${gen_moc_sources}
150-
${gen_ui_sources}
151-
${gen_qrc_sources}
152-
)
153-
154-
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES})
155-
156102
#-----------------------------------------------------------------------------
157103
# Install library (on windows, put the dll in 'bin' and the archive in 'lib')
158104

0 commit comments

Comments
 (0)