Skip to content

Commit

Permalink
sync: from linuxdeepin/dtkcore
Browse files Browse the repository at this point in the history
Synchronize source files from linuxdeepin/dtkcore.

Source-pull-request: linuxdeepin/dtkcore#448
  • Loading branch information
deepin-ci-robot committed Dec 4, 2024
1 parent a711231 commit a18ea9d
Show file tree
Hide file tree
Showing 4 changed files with 402 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cmake/DtkDConfig/DtkDConfigConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,41 @@ if(NOT DEFINED DSG_DATA_DIR)
endif()

add_definitions(-DDSG_DATA_DIR=\"${DSG_DATA_DIR}\")

# Define the helper function
function(dtk_config_to_cpp JSON_FILE OUTPUT_VAR)
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_WE ${JSON_FILE} NAME_WE)
if(DEFINED OUTPUT_FILE_NAME)
set(OUTPUT_HEADER "${CMAKE_CURRENT_BINARY_DIR}/${OUTPUT_FILE_NAME}")
else()
set(OUTPUT_HEADER "${CMAKE_CURRENT_BINARY_DIR}/${FILE_NAME_WE}.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()

# Add a custom command to run dconfig2cpp
add_custom_command(
OUTPUT ${OUTPUT_HEADER}
COMMAND ${TOOL_INSTALL_DIR}/dconfig2cpp -o ${OUTPUT_HEADER} ${CLASS_NAME_ARG} ${JSON_FILE}
DEPENDS ${JSON_FILE}
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()

# deploy some `meta` 's configure.
#
# FILES - deployed files.
Expand Down
1 change: 1 addition & 0 deletions tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ add_subdirectory(deepin-os-release)
add_subdirectory(qdbusxml2cpp)
add_subdirectory(settings)
add_subdirectory(ch2py)
add_subdirectory(dconfig2cpp)
26 changes: 26 additions & 0 deletions tools/dconfig2cpp/CMakeLists.txt
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}
)
Loading

0 comments on commit a18ea9d

Please sign in to comment.