-
Notifications
You must be signed in to change notification settings - Fork 92
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
add CMake build system support #240
Open
feihong-gz
wants to merge
5
commits into
MeVisLab:master
Choose a base branch
from
feihong-gz:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 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
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 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,39 @@ | ||
cmake_minimum_required(VERSION 3.27) | ||
|
||
enable_testing() | ||
|
||
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}) | ||
|
||
add_subdirectory(generator) | ||
|
||
if(NOT EXISTS "${PYTHONQT_GENERATED_PATH}") | ||
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() | ||
endif() | ||
|
||
add_subdirectory(src) | ||
add_subdirectory(extensions) | ||
add_subdirectory(tests) | ||
# add_subdirectory(examples) |
This file contains 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 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,104 @@ | ||
project(QtAll LANGUAGES CXX) | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
|
||
file(GLOB SOURCES *.h *.cpp) | ||
|
||
if(BUILD_SHARED_LIBS) | ||
add_library(${PROJECT_NAME} SHARED) | ||
target_compile_definitions(${PROJECT_NAME} PRIVATE PYTHONQT_QTALL_EXPORTS) | ||
else() | ||
add_library(${PROJECT_NAME} STATIC) | ||
target_compile_definitions(${PROJECT_NAME} PUBLIC PYTHONQT_QTALL_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}) | ||
|
||
|
||
list(APPEND QTMODULES Core Gui Svg Sql Network OpenGL Xml XmlPatterns Multimedia Qml Quick UiTools WebEngineWidgets WebKit) | ||
|
||
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 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
This file contains 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 |
---|---|---|
@@ -1,162 +1,47 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
project(PythonQtGenerator LANGUAGES CXX) | ||
|
||
#----------------------------------------------------------------------------- | ||
project(PythonQtGenerator) | ||
#----------------------------------------------------------------------------- | ||
add_subdirectory(parser) | ||
|
||
include(CTestUseLaunchers OPTIONAL) | ||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
#----------------------------------------------------------------------------- | ||
# Setup Qt | ||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets Xml REQUIRED) | ||
|
||
set(minimum_required_qt_version "4.6.2") | ||
file(GLOB SOURCES *.h *.cpp *.qrc) | ||
list(REMOVE_ITEM SOURCES "${CMAKE_CURRENT_LIST_DIR}/qtscript_masterinclude.h") | ||
|
||
find_package(Qt4) | ||
|
||
if(QT4_FOUND) | ||
|
||
set(found_qt_version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}) | ||
|
||
if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version}) | ||
message(FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version}.") | ||
endif() | ||
|
||
set(QT_USE_QTXML ON) | ||
|
||
include(${QT_USE_FILE}) | ||
else() | ||
message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable") | ||
endif() | ||
|
||
#----------------------------------------------------------------------------- | ||
# Sources | ||
|
||
set(sources | ||
parser/ast.cpp | ||
parser/binder.cpp | ||
parser/class_compiler.cpp | ||
parser/codemodel.cpp | ||
parser/codemodel_finder.cpp | ||
parser/compiler_utils.cpp | ||
parser/control.cpp | ||
parser/declarator_compiler.cpp | ||
parser/default_visitor.cpp | ||
parser/dumptree.cpp | ||
parser/lexer.cpp | ||
parser/list.cpp | ||
parser/name_compiler.cpp | ||
parser/parser.cpp | ||
parser/smallobject.cpp | ||
parser/tokens.cpp | ||
parser/type_compiler.cpp | ||
parser/visitor.cpp | ||
|
||
abstractmetabuilder.cpp | ||
abstractmetalang.cpp | ||
asttoxml.cpp | ||
customtypes.cpp | ||
fileout.cpp | ||
generator.cpp | ||
generatorset.cpp | ||
generatorsetqtscript.cpp | ||
main.cpp | ||
metajava.cpp | ||
metaqtscriptbuilder.cpp | ||
metaqtscript.cpp | ||
prigenerator.cpp | ||
reporthandler.cpp | ||
setupgenerator.cpp | ||
shellgenerator.cpp | ||
shellheadergenerator.cpp | ||
shellimplgenerator.cpp | ||
typeparser.cpp | ||
typesystem.cpp | ||
) | ||
|
||
#----------------------------------------------------------------------------- | ||
# List headers. This list is used for the install command. | ||
|
||
set(headers | ||
) | ||
|
||
#----------------------------------------------------------------------------- | ||
# Headers that should run through moc | ||
|
||
set(moc_sources | ||
fileout.h | ||
generator.h | ||
generatorset.h | ||
generatorsetqtscript.h | ||
prigenerator.h | ||
setupgenerator.h | ||
shellgenerator.h | ||
shellheadergenerator.h | ||
shellimplgenerator.h | ||
) | ||
add_executable(${PROJECT_NAME}) | ||
|
||
#----------------------------------------------------------------------------- | ||
# UI files | ||
target_sources(${PROJECT_NAME} PRIVATE | ||
${SOURCES} | ||
) | ||
|
||
set(ui_sources ) | ||
target_link_libraries(${PROJECT_NAME} PUBLIC | ||
Qt${QT_VERSION_MAJOR}::Widgets | ||
Qt${QT_VERSION_MAJOR}::Xml | ||
rxx | ||
) | ||
|
||
#----------------------------------------------------------------------------- | ||
# Resources | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
set(qrc_sources | ||
generator.qrc | ||
) | ||
set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_BINARY_DIR}/../generated_cpp PARENT_SCOPE) | ||
|
||
#----------------------------------------------------------------------------- | ||
# Do wrapping | ||
qt4_wrap_cpp(gen_moc_sources ${moc_sources}) | ||
qt4_wrap_ui(gen_ui_sources ${ui_sources}) | ||
qt4_add_resources(gen_qrc_sources ${qrc_sources}) | ||
if(NOT EXISTS ${PYTHONQT_GENERATED_PATH}) | ||
file(GLOB resources_files *.txt *.xml qtscript_masterinclude.h) | ||
foreach(resources_file IN LISTS resources_files) | ||
configure_file(${resources_file} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) | ||
endforeach() | ||
|
||
#----------------------------------------------------------------------------- | ||
# Copy file expected by the generator and specify install rules | ||
if(WIN32) | ||
set(LIBRARY_SEARCH_PATH PATH) | ||
else() | ||
set(LIBRARY_SEARCH_PATH LD_LIBRARY_PATH) | ||
endif() | ||
|
||
file(GLOB files_to_copy RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "build_*.txt" "typesystem_*.xml") | ||
list(APPEND files_to_copy qtscript_masterinclude.h parser/rpp/pp-qt-configuration) | ||
foreach(file ${files_to_copy}) | ||
configure_file( | ||
${file} | ||
${CMAKE_CURRENT_BINARY_DIR}/${file} | ||
COPYONLY | ||
add_custom_target(GenerateCpp | ||
COMMAND ${CMAKE_COMMAND} -E env --modify ${LIBRARY_SEARCH_PATH}=path_list_prepend:$<TARGET_FILE_DIR:Qt${QT_VERSION_MAJOR}::Widgets> $<TARGET_FILE:${PROJECT_NAME}> | ||
WORKING_DIRECTORY $<TARGET_FILE_DIR:${PROJECT_NAME}> | ||
VERBATIM USES_TERMINAL | ||
) | ||
get_filename_component(destination_dir ${file} PATH) | ||
install(FILES ${file} DESTINATION bin/${destination_dir}) | ||
endforeach() | ||
|
||
#----------------------------------------------------------------------------- | ||
# Build the library | ||
|
||
SOURCE_GROUP("Resources" FILES | ||
${qrc_sources} | ||
${ui_sources} | ||
${files_to_copy} | ||
) | ||
|
||
include_directories( | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_SOURCE_DIR}/parser | ||
${CMAKE_CURRENT_SOURCE_DIR}/parser/rpp | ||
) | ||
|
||
add_definitions(-DRXX_ALLOCATOR_INIT_0) | ||
|
||
add_executable(${PROJECT_NAME} | ||
${sources} | ||
${gen_moc_sources} | ||
${gen_ui_sources} | ||
${gen_qrc_sources} | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES}) | ||
|
||
#----------------------------------------------------------------------------- | ||
# Install library (on windows, put the dll in 'bin' and the archive in 'lib') | ||
endif() | ||
|
||
install(TARGETS ${PROJECT_NAME} | ||
RUNTIME DESTINATION bin | ||
LIBRARY DESTINATION lib | ||
ARCHIVE DESTINATION lib) |
This file contains 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,26 @@ | ||
project(rxx LANGUAGES CXX) | ||
add_subdirectory(rpp) | ||
|
||
set(CMAKE_AUTOMOC ON) | ||
set(CMAKE_AUTORCC ON) | ||
|
||
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) | ||
|
||
file(GLOB SOURCES *.h *.cpp) | ||
|
||
add_library(${PROJECT_NAME} INTERFACE) | ||
|
||
target_sources(${PROJECT_NAME} INTERFACE | ||
${SOURCES} | ||
) | ||
|
||
target_link_libraries(${PROJECT_NAME} INTERFACE | ||
Qt${QT_VERSION_MAJOR}::Core | ||
rpp | ||
) | ||
|
||
target_include_directories(${PROJECT_NAME} INTERFACE | ||
${CMAKE_CURRENT_LIST_DIR} | ||
) | ||
|
||
target_compile_definitions(${PROJECT_NAME} INTERFACE RXX_ALLOCATOR_INIT_0) |
Oops, something went wrong.
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.
I think this list shall be different for Qt5 and Qt6.
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 think as long as there are no modules with the same name but different functionality in Qt 5 and Qt 6, there shouldn't be a problem.