From e0291e73d2243a05614d0d28a4339c2020b82697 Mon Sep 17 00:00:00 2001 From: feihong Date: Tue, 26 Nov 2024 15:18:15 +0800 Subject: [PATCH 1/5] add CMake build system support --- CMakeLists.txt | 35 ++++++++ extensions/CMakeLists.txt | 1 + extensions/PythonQt_QtAll/CMakeLists.txt | 103 +++++++++++++++++++++++ src/CMakeLists.txt | 59 +++++++++++++ tests/CMakeLists.txt | 22 +++++ 5 files changed, 220 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 extensions/CMakeLists.txt create mode 100644 extensions/PythonQt_QtAll/CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..183660d7d --- /dev/null +++ b/CMakeLists.txt @@ -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) diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt new file mode 100644 index 000000000..03577a7a2 --- /dev/null +++ b/extensions/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory(PythonQt_QtAll) \ No newline at end of file diff --git a/extensions/PythonQt_QtAll/CMakeLists.txt b/extensions/PythonQt_QtAll/CMakeLists.txt new file mode 100644 index 000000000..fe0132168 --- /dev/null +++ b/extensions/PythonQt_QtAll/CMakeLists.txt @@ -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) + +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} +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 000000000..0d947db2a --- /dev/null +++ b/src/CMakeLists.txt @@ -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} +) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 000000000..9accf7bd2 --- /dev/null +++ b/tests/CMakeLists.txt @@ -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}) From 651427e24cb727659762e43bd3f0ca3f456fb511 Mon Sep 17 00:00:00 2001 From: feihong Date: Tue, 26 Nov 2024 17:21:06 +0800 Subject: [PATCH 2/5] add static link support --- extensions/PythonQt_QtAll/CMakeLists.txt | 3 ++- extensions/PythonQt_QtAll/PythonQt_QtAll.h | 16 +++++++++------- src/CMakeLists.txt | 2 ++ src/PythonQtSystem.h | 20 ++++++++------------ 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/extensions/PythonQt_QtAll/CMakeLists.txt b/extensions/PythonQt_QtAll/CMakeLists.txt index fe0132168..97ae4274f 100644 --- a/extensions/PythonQt_QtAll/CMakeLists.txt +++ b/extensions/PythonQt_QtAll/CMakeLists.txt @@ -6,8 +6,10 @@ 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 @@ -21,7 +23,6 @@ target_link_libraries(${PROJECT_NAME} PUBLIC 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) diff --git a/extensions/PythonQt_QtAll/PythonQt_QtAll.h b/extensions/PythonQt_QtAll/PythonQt_QtAll.h index 689e2e83c..f4a5ff769 100644 --- a/extensions/PythonQt_QtAll/PythonQt_QtAll.h +++ b/extensions/PythonQt_QtAll/PythonQt_QtAll.h @@ -33,14 +33,16 @@ * */ -#ifdef WIN32 -#ifdef PYTHONQT_QTALL_EXPORTS -#define PYTHONQT_QTALL_EXPORT __declspec(dllexport) -#else -#define PYTHONQT_QTALL_EXPORT __declspec(dllimport) -#endif +#include + +#ifndef PYTHONQT_QTALL_STATIC +# if defined(PYTHONQT_QTALL_EXPORTS) +# define PYTHONQT_QTALL_EXPORT Q_DECL_EXPORT +# else +# define PYTHONQT_QTALL_EXPORT Q_DECL_IMPORT +# endif #else -#define PYTHONQT_QTALL_EXPORT +# define PYTHONQT_QTALL_EXPORT #endif namespace PythonQt_QtAll diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0d947db2a..e07bad29f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -9,8 +9,10 @@ file(GLOB SOURCES *.h *.cpp) if(BUILD_SHARED_LIBS) add_library(${PROJECT_NAME} SHARED) + target_compile_definitions(${PROJECT_NAME} PRIVATE PYTHONQT_EXPORTS) else() add_library(${PROJECT_NAME} STATIC) + target_compile_definitions(${PROJECT_NAME} PUBLIC PYTHONQT_STATIC) endif() file(GLOB GENERATE_SOURCES diff --git a/src/PythonQtSystem.h b/src/PythonQtSystem.h index d49345eeb..dc0bfd0e6 100644 --- a/src/PythonQtSystem.h +++ b/src/PythonQtSystem.h @@ -42,21 +42,17 @@ */ //---------------------------------------------------------------------------------- +#include -#if defined(WIN32) - #ifdef PYTHONQT_EXPORTS - #define PYTHONQT_EXPORT __declspec(dllexport) - #else - #define PYTHONQT_EXPORT __declspec(dllimport) - #endif +#ifndef PYTHONQT_STATIC +# if defined(PYTHONQT_EXPORTS) +# define PYTHONQT_EXPORT Q_DECL_EXPORT +# else +# define PYTHONQT_EXPORT Q_DECL_IMPORT +# endif #else - #ifdef PYTHONQT_EXPORTS - #define PYTHONQT_EXPORT __attribute__((__visibility__("default"))) - #else - #define PYTHONQT_EXPORT - #endif +# define PYTHONQT_EXPORT #endif - #endif From 6bbd177d2f29c738114a694ab254aa2f20be0dfe Mon Sep 17 00:00:00 2001 From: feihong Date: Wed, 27 Nov 2024 11:49:03 +0800 Subject: [PATCH 3/5] add CMake build support to PythonQtGenerator --- CMakeLists.txt | 2 +- generator/CMakeLists.txt | 169 +++------------------------- generator/parser/CMakeLists.txt | 26 +++++ generator/parser/rpp/CMakeLists.txt | 14 +++ 4 files changed, 57 insertions(+), 154 deletions(-) create mode 100644 generator/parser/CMakeLists.txt create mode 100644 generator/parser/rpp/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 183660d7d..423d48fb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ else() endif() add_subdirectory(src) -# add_subdirectory(generator) +add_subdirectory(generator) add_subdirectory(extensions) add_subdirectory(tests) # add_subdirectory(examples) diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index 1d659dd87..6368e5da7 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -1,162 +1,25 @@ -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 +add_executable(${PROJECT_NAME}) - 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 - ) - -#----------------------------------------------------------------------------- -# UI files - -set(ui_sources ) - -#----------------------------------------------------------------------------- -# Resources - -set(qrc_sources - generator.qrc - ) - -#----------------------------------------------------------------------------- -# 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}) - -#----------------------------------------------------------------------------- -# Copy file expected by the generator and specify install rules - -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 - ) - 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_sources(${PROJECT_NAME} PRIVATE + ${SOURCES} ) -target_link_libraries(${PROJECT_NAME} ${QT_LIBRARIES}) - -#----------------------------------------------------------------------------- -# Install library (on windows, put the dll in 'bin' and the archive in 'lib') +target_link_libraries(${PROJECT_NAME} PUBLIC + Qt${QT_VERSION_MAJOR}::Widgets + Qt${QT_VERSION_MAJOR}::Xml + rxx +) -install(TARGETS ${PROJECT_NAME} - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) +target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}) diff --git a/generator/parser/CMakeLists.txt b/generator/parser/CMakeLists.txt new file mode 100644 index 000000000..7b70c98aa --- /dev/null +++ b/generator/parser/CMakeLists.txt @@ -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) diff --git a/generator/parser/rpp/CMakeLists.txt b/generator/parser/rpp/CMakeLists.txt new file mode 100644 index 000000000..99ccd130e --- /dev/null +++ b/generator/parser/rpp/CMakeLists.txt @@ -0,0 +1,14 @@ +project(rpp LANGUAGES CXX) + +find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED) + +file(GLOB SOURCES *.h preprocessor.cpp) + +add_library(${PROJECT_NAME} INTERFACE) + +target_sources(${PROJECT_NAME} INTERFACE ${SOURCES}) + +target_link_libraries(${PROJECT_NAME} INTERFACE Qt${QT_VERSION_MAJOR}::Core) + +target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) + From 5ac1ecaff991a6205b9688c690601dc0bc8e59d3 Mon Sep 17 00:00:00 2001 From: feihong Date: Thu, 28 Nov 2024 14:18:53 +0800 Subject: [PATCH 4/5] prefer to use ${CMAKE_CURRENT_LIST_DIR}/generated_cpp --- CMakeLists.txt | 31 +++++++++++++++++-------------- generator/CMakeLists.txt | 13 +++++++++++++ tests/CMakeLists.txt | 5 ++++- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 423d48fb1..6acb828f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,26 +10,29 @@ 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(${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) +set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_LIST_DIR}/generated_cpp) +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() - set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_LIST_DIR}/generated_cpp_515) + message(FATAL "No generated sources exist for Qt${QT_VERSION}") 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) diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index 6368e5da7..26d900a0d 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -23,3 +23,16 @@ target_link_libraries(${PROJECT_NAME} PUBLIC ) target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}) + +# file(GLOB resources_files *.txt *.xml) +# foreach(resources_file IN LISTS resources_files) +# configure_file(${resources_file} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) +# endforeach() + +# file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated_cpp") + +# add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD +# COMMAND set Path="%Path%;" +# COMMAND $ +# WORKING_DIRECTORY $ +# ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9accf7bd2..35a5c8252 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -19,4 +19,7 @@ target_link_libraries(${PROJECT_NAME} PRIVATE QtAll ) -add_test(NAME ${PROJECT_NAME} COMMAND ${PROJECT_NAME}) +add_test(NAME ${PROJECT_NAME} + COMMAND $ + WORKING_DIRECTORY $ +) From d1c8d34d9c8eab11e267890e91c295b2a0ee67c9 Mon Sep 17 00:00:00 2001 From: feihong Date: Thu, 5 Dec 2024 17:05:13 +0800 Subject: [PATCH 5/5] add custom targets to automatically run generated commands --- CMakeLists.txt | 5 +++-- generator/CMakeLists.txt | 33 +++++++++++++++++++++------------ tests/CMakeLists.txt | 4 ++++ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6acb828f4..e0fc19f6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ cmake_minimum_required(VERSION 3.27) +enable_testing() + project(PythonQt LANGUAGES CXX VERSION 3.5.6) set(CMAKE_CXX_STANDARD 11) @@ -12,8 +14,7 @@ set(PYTHONQT_SUFFIX Qt${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}-Python${Python3_VE add_subdirectory(generator) -set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_LIST_DIR}/generated_cpp) -if(NOT EXISTS ${PYTHONQT_GENERATED_PATH}) +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) diff --git a/generator/CMakeLists.txt b/generator/CMakeLists.txt index 26d900a0d..23f2c39bf 100644 --- a/generator/CMakeLists.txt +++ b/generator/CMakeLists.txt @@ -24,15 +24,24 @@ target_link_libraries(${PROJECT_NAME} PUBLIC target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_LIST_DIR}) -# file(GLOB resources_files *.txt *.xml) -# foreach(resources_file IN LISTS resources_files) -# configure_file(${resources_file} ${CMAKE_CURRENT_BINARY_DIR} COPYONLY) -# endforeach() - -# file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/generated_cpp") - -# add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD -# COMMAND set Path="%Path%;" -# COMMAND $ -# WORKING_DIRECTORY $ -# ) +set(PYTHONQT_GENERATED_PATH ${CMAKE_CURRENT_BINARY_DIR}/../generated_cpp PARENT_SCOPE) + +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() + + if(WIN32) + set(LIBRARY_SEARCH_PATH PATH) + else() + set(LIBRARY_SEARCH_PATH LD_LIBRARY_PATH) + endif() + + add_custom_target(GenerateCpp + COMMAND ${CMAKE_COMMAND} -E env --modify ${LIBRARY_SEARCH_PATH}=path_list_prepend:$ $ + WORKING_DIRECTORY $ + VERBATIM USES_TERMINAL + ) +endif() + diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 35a5c8252..8d9ad75fb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -23,3 +23,7 @@ add_test(NAME ${PROJECT_NAME} COMMAND $ WORKING_DIRECTORY $ ) + +set_tests_properties(${PROJECT_NAME} PROPERTIES + ENVIRONMENT_MODIFICATION "Path=path_list_append:$" +)