-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: Support auto generate the Qt code for a dconfig's json
- Loading branch information
Showing
7 changed files
with
446 additions
and
6 deletions.
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
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,51 @@ | ||
# SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
# SPDX-License-Identifier: LGPL-3.0-or-later | ||
|
||
include(MacroAddFileDependencies) | ||
include(CMakeParseArguments) | ||
|
||
# Define the helper function | ||
function(dtk_add_config_to_cpp OUTPUT_VAR JSON_FILE) | ||
if(NOT EXISTS ${JSON_FILE}) | ||
message(FATAL_ERROR "JSON file ${JSON_FILE} does not exist.") | ||
endif() | ||
|
||
# Generate the output header file name | ||
get_filename_component(FILE_NAME_WLE ${JSON_FILE} NAME_WLE) | ||
if(DEFINED OUTPUT_FILE_NAME) | ||
set(OUTPUT_HEADER "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_FILE_NAME}") | ||
else() | ||
set(OUTPUT_HEADER "${CMAKE_CURRENT_BINARY_DIR}/dconfig_${FILE_NAME_WLE}.hpp") | ||
endif() | ||
|
||
# Check if CLASS_NAME is set | ||
if(DEFINED CLASS_NAME) | ||
set(CLASS_NAME_ARG -c ${CLASS_NAME}) | ||
else() | ||
set(CLASS_NAME_ARG "") | ||
endif() | ||
|
||
if(NOT DEFINED USE_QPROPERTY) | ||
if(${QT_VERSION_MAJOR} GREATER_EQUAL 6) | ||
set(USE_QPROPERTY ON) | ||
endif() | ||
endif() | ||
|
||
if (USE_QPROPERTY) | ||
set(USE_QPROPERTY_ARG "--use-qproperty") | ||
else() | ||
set(USE_QPROPERTY_ARG "") | ||
endif() | ||
|
||
# Add a custom command to run dconfig2cpp | ||
add_custom_command( | ||
OUTPUT ${OUTPUT_HEADER} | ||
COMMAND ${DTK_DCONFIG2CPP} -o ${OUTPUT_HEADER} ${CLASS_NAME_ARG} ${USE_QPROPERTY_ARG} ${JSON_FILE} | ||
DEPENDS ${JSON_FILE} ${DTK_XML2CPP} | ||
COMMENT "Generating ${OUTPUT_HEADER} from ${JSON_FILE}" | ||
VERBATIM | ||
) | ||
|
||
# Add the generated header to the specified output variable | ||
set(${OUTPUT_VAR} ${${OUTPUT_VAR}} ${OUTPUT_HEADER} PARENT_SCOPE) | ||
endfunction() |
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
set(TARGET_NAME dconfig2cpp) | ||
set(BIN_NAME ${TARGET_NAME}${DTK_VERSION_MAJOR}) | ||
|
||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core) | ||
|
||
add_executable(${BIN_NAME} | ||
main.cpp | ||
) | ||
|
||
target_link_libraries( | ||
${BIN_NAME} PRIVATE | ||
Qt${QT_VERSION_MAJOR}::Core | ||
) | ||
|
||
set_target_properties( | ||
${BIN_NAME} PROPERTIES | ||
OUTPUT_NAME ${TARGET_NAME} | ||
EXPORT_NAME DConfig2Cpp | ||
) | ||
|
||
install( | ||
TARGETS ${BIN_NAME} | ||
EXPORT Dtk${DTK_VERSION_MAJOR}ToolsTargets | ||
DESTINATION ${TOOL_INSTALL_DIR} | ||
) |
Oops, something went wrong.