-
Notifications
You must be signed in to change notification settings - Fork 70
[DoNotMerge] ✨Use declarative macros for better Qt integration (e.g. QDS) #172
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,3 +15,5 @@ CMakeLists.txt.user | |
| # nix files | ||
| result* | ||
| .direnv | ||
|
|
||
| cmake-build-*/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,6 +62,9 @@ endif() | |
|
|
||
| set(QATERIAL_ENABLE_INSTALL ${_default_QATERIAL_ENABLE_INSTALL} CACHE BOOL "Generate the install target") | ||
|
|
||
| # "d" postfix should also transitively apply to dependencies but won't affect the parent scope | ||
| set(CMAKE_DEBUG_POSTFIX "d") | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is useful so you can install both release and debug library in the install folder. |
||
|
|
||
| project(${QATERIAL_PROJECT} VERSION ${QATERIAL_VERSION} LANGUAGES CXX) | ||
| if(QATERIAL_MAIN_PROJECT) | ||
| set_property(GLOBAL PROPERTY USE_FOLDERS ON) | ||
|
|
@@ -119,19 +122,6 @@ endif() | |
|
|
||
| include(cmake/FetchQOlm.cmake) | ||
|
|
||
| # ───── RESSOURCES ───── | ||
|
|
||
| add_subdirectory(qml) | ||
| include(cmake/QaterialGenerateIcons.cmake) | ||
| set(QATERIAL_ICONS_OUTPUT_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/Qaterial_icons") | ||
| set(QATERIAL_ICONS_CLASS_FILE "${QATERIAL_ICONS_OUTPUT_FOLDER}/Qaterial/Display/Icons.hpp") | ||
| set(QATERIAL_ICONS_SRC_FILE "${QATERIAL_ICONS_OUTPUT_FOLDER}/Qaterial/Display/Icons.cpp") | ||
| qaterial_generate_icons_class(${QATERIAL_ICONS_CLASS_FILE} ${QATERIAL_ICONS_SRC_FILE}) | ||
| set(QATERIAL_GEN_SRCS | ||
| ${QATERIAL_ICONS_CLASS_FILE} | ||
| ${QATERIAL_ICONS_SRC_FILE} | ||
| ) | ||
|
|
||
| # ───── QML SOURCES ───── | ||
|
|
||
| set(QATERIAL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/Qaterial) | ||
|
|
@@ -182,12 +172,28 @@ set(QATERIAL_SRCS | |
| source_group(TREE "${QATERIAL_SOURCE_DIR}" FILES ${QATERIAL_SRCS}) | ||
| source_group(TREE "${QATERIAL_ICONS_OUTPUT_FOLDER}/Qaterial" FILES ${QATERIAL_GEN_SRCS}) | ||
|
|
||
| set(QATERIAL_SRCS ${QATERIAL_SRCS} ${QATERIAL_GEN_SRCS}) | ||
| set(QATERIAL_SRCS ${QATERIAL_SRCS}) | ||
|
|
||
| # ───── QATERIAL TARGET ───── | ||
|
|
||
| qt_policy(SET QTP0004 NEW) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is neat since Qt6.8, thank you for the discovery I missed it. I guess it won't change much in here, but I have some projects that may be affected so I can remove lots of CMake code. |
||
|
|
||
| set(QATERIAL_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/gen_out/${QATERIAL_TARGET}") | ||
|
|
||
| if(${QATERIAL_BUILD_SHARED}) | ||
| qt_add_library(${QATERIAL_TARGET} SHARED ${QATERIAL_SRCS}) | ||
| qt_add_qml_module(Qaterial SHARED | ||
| URI "Qaterial" | ||
| VERSION ${QATERIAL_VERSION} | ||
| DEPENDENCIES | ||
| QtQuick/auto | ||
| CLASS_NAME QaterialPlugin | ||
| PLUGIN_TARGET qaterialplugin | ||
| NO_PLUGIN_OPTIONAL | ||
| RESOURCE_PREFIX "/" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had a lot of troubles with these prefixes and what not. I haven't tried to go back to individual subtargets linking into this library. |
||
| SOURCES ${QATERIAL_SRCS} | ||
| OUTPUT_DIRECTORY "${QATERIAL_OUTPUT_DIR}" | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OUTPUT_DIRECTORY contains everything one might need to install into output "qml" dir. Haven't found some dedicated target for that or example for "how it is done in Qt". |
||
| ) | ||
|
|
||
| target_compile_definitions(${QATERIAL_TARGET} PRIVATE -DQATERIAL_SHARED) | ||
| else() | ||
| qt_add_library(${QATERIAL_TARGET} STATIC ${QATERIAL_SRCS}) | ||
|
|
@@ -197,18 +203,47 @@ add_library(${QATERIAL_TARGET}::${QATERIAL_TARGET} ALIAS ${QATERIAL_TARGET}) | |
|
|
||
| target_compile_features(${QATERIAL_TARGET} PUBLIC cxx_std_17) | ||
| target_include_directories(${QATERIAL_TARGET} PRIVATE src ${QATERIAL_ICONS_OUTPUT_FOLDER}) | ||
| # Glob all include directories in src Qaterial | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The next section is needed, because the generated files always include the "parent header" with not prefix. Looks a bit hacky though. There could be better solution. This is related: |
||
| file(GLOB_RECURSE QATERIAL_INCLUDE_DIRS LIST_DIRECTORIES true RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} src/Qaterial/*) | ||
| # Add to include directories | ||
| foreach(INCLUDE_DIR ${QATERIAL_INCLUDE_DIRS}) | ||
| # Convert to absolute path, because IS_DIRECTORY only works with absolute paths | ||
| get_filename_component(INCLUDE_DIR_ABS ${INCLUDE_DIR} ABSOLUTE) | ||
| if(IS_DIRECTORY ${INCLUDE_DIR_ABS}) | ||
| get_filename_component(INCLUDE_DIR_NAME ${INCLUDE_DIR} NAME) | ||
| if(NOT INCLUDE_DIR_NAME STREQUAL "Pch") | ||
| message(VERBOSE "Adding include directory: ${INCLUDE_DIR}") | ||
| target_include_directories(${QATERIAL_TARGET} PRIVATE ${INCLUDE_DIR}) | ||
| endif() | ||
| endif() | ||
| endforeach() | ||
|
|
||
| target_include_directories(${QATERIAL_TARGET} PUBLIC | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src> | ||
| $<INSTALL_INTERFACE:include> | ||
| ) | ||
|
|
||
| if(QATERIAL_ENABLE_PCH AND COMMAND target_precompile_headers) | ||
| target_precompile_headers(${QATERIAL_TARGET} PRIVATE src/Qaterial/Pch/Pch.hpp) | ||
| endif() | ||
|
|
||
| add_subdirectory(qml) | ||
| include(cmake/QaterialGenerateIcons.cmake) | ||
|
|
||
| set(QATERIAL_ICONS_OUTPUT_FOLDER "${CMAKE_CURRENT_BINARY_DIR}/Qaterial_icons") | ||
| set(QATERIAL_ICONS_CLASS_FILE "${QATERIAL_ICONS_OUTPUT_FOLDER}/Qaterial/Display/Icons.hpp") | ||
| set(QATERIAL_ICONS_SRC_FILE "${QATERIAL_ICONS_OUTPUT_FOLDER}/Qaterial/Display/Icons.cpp") | ||
| qaterial_generate_icons_class(${QATERIAL_ICONS_CLASS_FILE} ${QATERIAL_ICONS_SRC_FILE}) | ||
|
|
||
| set(QATERIAL_GEN_SRCS | ||
| ${QATERIAL_ICONS_CLASS_FILE} | ||
| ${QATERIAL_ICONS_SRC_FILE} | ||
| ) | ||
| target_sources(${QATERIAL_TARGET} PRIVATE ${QATERIAL_GEN_SRCS}) | ||
| target_include_directories(${QATERIAL_TARGET} PRIVATE ${QATERIAL_ICONS_OUTPUT_FOLDER}) | ||
| target_include_directories(${QATERIAL_TARGET} PRIVATE ${QATERIAL_ICONS_OUTPUT_FOLDER}/Qaterial/Display) | ||
|
|
||
| target_link_libraries(${QATERIAL_TARGET} | ||
| PRIVATE ${QATERIAL_TARGET}::Icons | ||
| PRIVATE ${QATERIAL_TARGET}::Fonts | ||
| PRIVATE ${QATERIAL_TARGET}::Components | ||
| PUBLIC QOlm::QOlm | ||
| PUBLIC Qt::Core | ||
| PUBLIC Qt::Gui | ||
|
|
@@ -276,6 +311,11 @@ if (QATERIAL_ENABLE_INSTALL) | |
| EXPORT ${QATERIAL_TARGET}Targets | ||
| ) | ||
|
|
||
| install(DIRECTORY ${QATERIAL_OUTPUT_DIR} | ||
| DESTINATION ${CMAKE_INSTALL_PREFIX}/qml/ | ||
| FILES_MATCHING PATTERN "*.qml" PATTERN "qmldir" PATTERN "*.qmltypes" PATTERN "*.dll" PATTERN "*.so" | ||
| ) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Installs all that is needed for QDS into QML dir. |
||
|
|
||
| foreach(HDR_FILE ${QATERIAL_PUBLIC_HEADERS}) | ||
| get_filename_component(HDR_DIRECTORY ${HDR_FILE} DIRECTORY) | ||
| get_filename_component(ABSOLUTE_HDR_DIRECTORY ${HDR_DIRECTORY} ABSOLUTE) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,32 +17,23 @@ file(GLOB_RECURSE QATERIAL_QML_FILES | |
| ) | ||
|
|
||
| set(SINGLETON_FILES | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/Calendar.qml | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug I think, This can also be probably split and merged immediately. |
||
| ${CMAKE_CURRENT_SOURCE_DIR}/Style.qml | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/Colors.qml | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/DataFormat.qml | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/DateFormat.qml | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/DialogManager.qml | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/SnackbarManager.qml | ||
| ${CMAKE_CURRENT_SOURCE_DIR}/Style.qml | ||
| ) | ||
|
|
||
| set_source_files_properties(${SINGLETON_FILES} PROPERTIES QT_QML_SINGLETON_TYPE TRUE) | ||
|
|
||
| qt_add_library(${QATERIAL_TARGET}Components STATIC) | ||
| qt_add_qml_module(${QATERIAL_TARGET}Components | ||
| URI Qaterial | ||
| VERSION 1.0 | ||
| RESOURCE_PREFIX "/" | ||
| QML_FILES | ||
| ${QATERIAL_QML_FILES} | ||
| OUTPUT_TARGETS QATERIAL_COMPONENTS_QML_TARGETS | ||
| NO_PLUGIN | ||
| qt_target_qml_sources(${QATERIAL_TARGET} | ||
| QML_FILES ${QATERIAL_QML_FILES} | ||
| NO_CACHEGEN | ||
| ) | ||
| add_library(${QATERIAL_TARGET}::Components ALIAS ${QATERIAL_TARGET}Components) | ||
|
|
||
| set_target_properties(${QATERIAL_TARGET}Components PROPERTIES AUTORCC TRUE) | ||
|
|
||
| target_link_libraries(${QATERIAL_TARGET}Components PRIVATE | ||
| target_link_libraries(${QATERIAL_TARGET} PRIVATE | ||
| Qt::Core | ||
| Qt::Gui | ||
| Qt::Svg | ||
|
|
@@ -52,26 +43,3 @@ target_link_libraries(${QATERIAL_TARGET}Components PRIVATE | |
| Qt::QuickControls2 | ||
| Qt::Core5Compat | ||
| ) | ||
|
|
||
| if(QATERIAL_FOLDER_PREFIX) | ||
| set_target_properties(${QATERIAL_TARGET}Components PROPERTIES FOLDER ${QATERIAL_FOLDER_PREFIX}) | ||
| endif() | ||
|
|
||
| if(QATERIAL_ENABLE_INSTALL AND NOT QATERIAL_BUILD_SHARED) | ||
| include(GNUInstallDirs) | ||
| install(TARGETS ${QATERIAL_TARGET}Components ${QATERIAL_COMPONENTS_QML_TARGETS} | ||
| EXPORT ${QATERIAL_TARGET}ComponentsTargets | ||
| ) | ||
|
|
||
| export(EXPORT ${QATERIAL_TARGET}ComponentsTargets | ||
| FILE "${CMAKE_CURRENT_BINARY_DIR}/${QATERIAL_TARGET}/${QATERIAL_TARGET}ComponentsTargets.cmake" | ||
| ) | ||
|
|
||
| set(ConfigPackageLocation lib/cmake/${QATERIAL_TARGET}) | ||
| install(EXPORT ${QATERIAL_TARGET}ComponentsTargets | ||
| FILE | ||
| ${QATERIAL_TARGET}ComponentsTargets.cmake | ||
| DESTINATION | ||
| ${ConfigPackageLocation} | ||
| ) | ||
| endif() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,5 +22,4 @@ Qaterial.Dialog | |
|
|
||
| parent: Overlay.overlay | ||
| property int dialogImplicitWidth: Qaterial.Style.dialog.implicitWidth | ||
| implicitWidth: Math.floor(Math.min(parent.width - 2 * Qaterial.Style.card.horizontalPadding, dialogImplicitWidth)) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to remove this line because my AlertDialogs had a cut headers. E.g. "Failed to blah glah flah" would become "Failed to blah gla..." Not sure if this is a correct place to treat this, but it works 😄 |
||
| } // Dialog | ||
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 is mainly for CLion. As the IDE generates in source build folder like this.