-
Notifications
You must be signed in to change notification settings - Fork 106
add CMake build system support #240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
e0291e7
add CMake build system support
651427e
add static link support
6bbd177
add CMake build support to PythonQtGenerator
5ac1eca
prefer to use ${CMAKE_CURRENT_LIST_DIR}/generated_cpp
d1c8d34
add custom targets to automatically run generated commands
815730f
Initial support for using auto-generated wrappers
56bd7e4
enable testing
e02479f
add cmake ci
bd2ef21
CMake CI Process Validation
b1f079c
CMake CI Process Validation
85aa600
CMake CI Process Validation
d4f5f7f
CMake CI Process Validation
a02dd49
CMake CI Process Validation
09ea478
CMake CI Process Validation
e469f27
CMake CI Process Validation
952b6d3
Update cmake.yml
feihong-gz f474b3f
Update cmake.yml
feihong-gz 473efa0
adapting more Qt header file include paths
22e38fc
fix _qt_include_prefix
cb96f7f
update cmake.yml
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
cmake_minimum_required(VERSION 3.27) | ||
|
||
project(PythonQt LANGUAGES CXX VERSION 3.5.6) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
|
||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core) | ||
find_package(Python3 COMPONENTS Development) | ||
|
||
set(PYTHONQT_SUFFIX Qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}-Python${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}) | ||
|
||
|
||
if(${QT_VERSION_MAJOR} VERSION_EQUAL 5) | ||
if(${QT_VERSION_MINOR} VERSION_LESS 3) | ||
set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_LIST_DIR}/generated_cpp_50) | ||
elseif(${QT_VERSION_MINOR} VERSION_LESS 6) | ||
set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_LIST_DIR}/generated_cpp_54) | ||
elseif(${QT_VERSION_MINOR} VERSION_LESS 11) | ||
set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_LIST_DIR}/generated_cpp_56) | ||
elseif(${QT_VERSION_MINOR} VERSION_LESS 15) | ||
set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_LIST_DIR}/generated_cpp_511) | ||
else() | ||
set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_LIST_DIR}/generated_cpp_515) | ||
endif() | ||
# elseif(${QT_VERSION_MAJOR} VERSION_EQUAL 6) | ||
else() | ||
message(FATAL "No generated sources exist for Qt${QT_VERSION}") | ||
endif() | ||
|
||
add_subdirectory(src) | ||
# add_subdirectory(generator) | ||
add_subdirectory(extensions) | ||
add_subdirectory(tests) | ||
# add_subdirectory(examples) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(PythonQt_QtAll) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
project(QtAll LANGUAGES CXX) | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
|
||
file(GLOB SOURCES *.h *.cpp) | ||
|
||
if(BUILD_SHARED_LIBS) | ||
add_library(${PROJECT_NAME} SHARED) | ||
else() | ||
add_library(${PROJECT_NAME} STATIC) | ||
endif() | ||
|
||
target_sources(${PROJECT_NAME} PRIVATE | ||
${SOURCES} | ||
${GENERATE_SOURCES} | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} PUBLIC | ||
Core | ||
) | ||
|
||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
target_compile_definitions(${PROJECT_NAME} PRIVATE PYTHONQT_QTALL_EXPORTS) | ||
|
||
list(APPEND QTMODULES Core Gui Svg Sql Network OpenGL Xml XmlPatterns Multimedia Qml Quick UiTools WebEngineWidgets WebKit) | ||
mrbean-bremen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS ${QTMODULES}) | ||
|
||
foreach(QTMODULE IN LISTS QTMODULES) | ||
if(NOT TARGET Qt${QT_VERSION_MAJOR}::${QTMODULE}) | ||
continue() | ||
endif() | ||
|
||
string(TOLOWER ${QTMODULE} qtmodule) | ||
file(GLOB GENERATE_SOURCES | ||
${PYTHONQT_GENERATED_PATH}/com_trolltech_qt_${qtmodule}/*.h | ||
${PYTHONQT_GENERATED_PATH}/com_trolltech_qt_${qtmodule}/*.cpp | ||
) | ||
target_sources(${PROJECT_NAME} PRIVATE ${GENERATE_SOURCES}) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC Qt${QT_VERSION_MAJOR}::${QTMODULE}) | ||
|
||
string(TOUPPER ${QTMODULE} qtmodule) | ||
target_compile_definitions(${PROJECT_NAME} PRIVATE PYTHONQT_WITH_${qtmodule}) | ||
endforeach() | ||
|
||
if(TARGET Qt${QT_VERSION_MAJOR}::Gui) | ||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets PrintSupport REQUIRED) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC | ||
Qt${QT_VERSION_MAJOR}::Widgets | ||
Qt${QT_VERSION_MAJOR}::PrintSupport | ||
) | ||
endif() | ||
|
||
if(TARGET Qt${QT_VERSION_MAJOR}::Svg AND QT_VERSION_MAJOR VERSION_GREATER_EQUAL 6) | ||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS SvgWidgets REQUIRED) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC | ||
Qt${QT_VERSION_MAJOR}::SvgWidgets | ||
) | ||
endif() | ||
|
||
if(TARGET Qt${QT_VERSION_MAJOR}::Multimedia) | ||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS MultimediaWidgets REQUIRED) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC | ||
Qt${QT_VERSION_MAJOR}::MultimediaWidgets | ||
) | ||
endif() | ||
|
||
if(TARGET Qt${QT_VERSION_MAJOR}::Quick) | ||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS QuickWidgets REQUIRED) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC | ||
Qt${QT_VERSION_MAJOR}::QuickWidgets | ||
) | ||
endif() | ||
|
||
if(TARGET Qt${QT_VERSION_MAJOR}::WebKit) | ||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS WebKitWidgets REQUIRED) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC | ||
Qt${QT_VERSION_MAJOR}::WebKitWidgets | ||
) | ||
endif() | ||
|
||
file(GLOB PUBLIC_HEADER *.h) | ||
|
||
set_target_properties(${PROJECT_NAME} PROPERTIES | ||
OUTPUT_NAME PythonQt-QtAll-${PYTHONQT_SUFFIX} | ||
PUBLIC_HEADER "${PUBLIC_HEADER}" | ||
) | ||
|
||
if(MSVC) | ||
target_compile_options(${PROJECT_NAME} PRIVATE "/bigobj") | ||
elseif(MINGW) | ||
target_compile_options(${PROJECT_NAME} PRIVATE "-Wa,-mbig-obj") | ||
endif() | ||
|
||
include(GNUInstallDirs) | ||
install(TARGETS ${PROJECT_NAME} | ||
BUNDLE DESTINATION . | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
project(Core LANGUAGES CXX) | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
|
||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Widgets REQUIRED) | ||
find_package(Python3 COMPONENTS Development REQUIRED) | ||
|
||
file(GLOB SOURCES *.h *.cpp) | ||
|
||
if(BUILD_SHARED_LIBS) | ||
add_library(${PROJECT_NAME} SHARED) | ||
else() | ||
add_library(${PROJECT_NAME} STATIC) | ||
endif() | ||
|
||
file(GLOB GENERATE_SOURCES | ||
${PYTHONQT_GENERATED_PATH}/com_trolltech_qt_core_builtin/*.h | ||
${PYTHONQT_GENERATED_PATH}/com_trolltech_qt_core_builtin/*.cpp | ||
${PYTHONQT_GENERATED_PATH}/com_trolltech_qt_gui_builtin/*.h | ||
${PYTHONQT_GENERATED_PATH}/com_trolltech_qt_gui_builtin/*.cpp | ||
) | ||
|
||
target_sources(${PROJECT_NAME} PRIVATE | ||
${SOURCES} | ||
${GENERATE_SOURCES} | ||
) | ||
|
||
file(GLOB PUBLIC_HEADER *.h) | ||
|
||
set_target_properties(${PROJECT_NAME} PROPERTIES | ||
OUTPUT_NAME PythonQt-${PYTHONQT_SUFFIX} | ||
PUBLIC_HEADER "${PUBLIC_HEADER}" | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} PUBLIC | ||
Qt${QT_VERSION_MAJOR}::Core | ||
Qt${QT_VERSION_MAJOR}::CorePrivate | ||
Qt${QT_VERSION_MAJOR}::Widgets | ||
Python3::Python | ||
) | ||
|
||
target_compile_definitions(${PROJECT_NAME} PRIVATE PYTHONQT_EXPORTS PYTHONQT_CATCH_ALL_EXCEPTIONS) | ||
|
||
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
if(MSVC) | ||
target_compile_options(${PROJECT_NAME} PRIVATE "/bigobj") | ||
elseif(MINGW) | ||
target_compile_options(${PROJECT_NAME} PRIVATE "-Wa,-mbig-obj") | ||
endif() | ||
|
||
include(GNUInstallDirs) | ||
install(TARGETS ${PROJECT_NAME} | ||
BUNDLE DESTINATION . | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
project(tests LANGUAGES CXX) | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
|
||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Test REQUIRED) | ||
|
||
file(GLOB SOURCES *.h *.cpp) | ||
|
||
add_executable(${PROJECT_NAME}) | ||
|
||
target_sources(${PROJECT_NAME} PRIVATE | ||
${SOURCES} | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} PRIVATE | ||
Qt${QT_VERSION_MAJOR}::Widgets | ||
Qt${QT_VERSION_MAJOR}::Test | ||
Core | ||
QtAll | ||
) | ||
|
||
add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not handle the (actually preferred) case of self-generated wrappers in
generated_cpp
, as done in the qmake file. Especially this will not work for Qt6, unless I'm missing something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to build generator using CMake, and so far it's testing well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently compiles and installs properly. Earlier I was thinking about how to use the code generated by generator, because in the configuration phase generator is not generated yet, and in the compilation phase it's too late. So I didn't do much about this later. But I currently have some ideas on how to solve this problem.
I apologize for not replying to you until now, as I don't usually follow github. It's going to be Chinese New Year now, so I probably won't do anything until after Chinese New Year.
My English is not very good either, so I hope you can understand what I said.
Meanwhile, wish you happy Chinese New Year in advance.
Translated with DeepL.com (free version)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, take your time, and thank you for your contribution!
Happy New Year to you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On CMake, I had to know the exact filename of the file to be generated, so I modified the file size limit. Also, this commit only executes properly on Qt5, Qt6 seems to generate some duplicates inside the source file. Maybe the generator needs some changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the current implementation may not be elegant, but it is a viable solution, subject to subsequent improvements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@usiems is currently working on changing the preprocessor, this might resolve some issues, though I'm not sure.
If the solution is working, we can always improve it later, and if we have the CI tests in place (see my previous comment), this should be easier.