Skip to content

Commit

Permalink
Added xmldiff (library) and xml-diff (binary).
Browse files Browse the repository at this point in the history
  • Loading branch information
bilke committed Jan 28, 2025
1 parent 15dee21 commit 441ac44
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
19 changes: 17 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,29 @@
cmake_minimum_required(VERSION 3.13)
project(xmlpatch VERSION 0.4.0)
project(xmlpatch VERSION 0.4.5)
set(VERSION ${CMAKE_PROJECT_VERSION})
configure_file(cmake_config.h.in ${PROJECT_BINARY_DIR}/config.h @ONLY)
include_directories(${PROJECT_BINARY_DIR})

find_package(LibXml2 REQUIRED)

add_library(xmlpatch src/xml_patch.c)
target_link_libraries(xmlpatch PUBLIC LibXml2::LibXml2)
target_include_directories(xmlpatch INTERFACE src)
set_target_properties(xmlpatch PROPERTIES PUBLIC_HEADER src/xml_patch.h)
install(TARGETS xmlpatch)

find_package(PkgConfig)
if(PKG_CONFIG_FOUND)
# xmldiff requires glib
pkg_check_modules(glib IMPORTED_TARGET glib-2.0)
if(glib_FOUND)
add_library(xmldiff diff/xml_diff.c)
target_link_libraries(xmldiff PUBLIC LibXml2::LibXml2 PkgConfig::glib)
target_include_directories(xmldiff INTERFACE diff)
set_target_properties(xmldiff PROPERTIES PUBLIC_HEADER diff/xml_diff.h)
install(TARGETS xmldiff)
endif()
endif()

include(CTest)
if(BUILD_TESTING)
add_subdirectory(tests)
Expand Down
23 changes: 18 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
add_executable(xml_patch_main xml_patch_main.c)
target_link_libraries(xml_patch_main PRIVATE xmlpatch)
target_compile_definitions(xml_patch_main PRIVATE VERSION="0.4.x")
add_test(NAME xml_patch
COMMAND xml_patch_main -f ${CMAKE_CURRENT_SOURCE_DIR}/test.xml -p
add_executable(xml-patch xml_patch_main.c)
target_link_libraries(xml-patch PRIVATE xmlpatch)
install(TARGETS xml-patch)
add_test(NAME xml-patch
COMMAND xml-patch -f ${CMAKE_CURRENT_SOURCE_DIR}/test.xml -p
${CMAKE_CURRENT_SOURCE_DIR}/patch.xml)

if(TARGET xmldiff)
add_executable(xml-diff xml_diff_main.c)
target_link_libraries(xml-diff PRIVATE xmlpatch xmldiff)
install(TARGETS xml-diff)
add_test(NAME xml-diff
COMMAND xml-diff -f ${CMAKE_CURRENT_SOURCE_DIR}/test.xml -t
${CMAKE_CURRENT_SOURCE_DIR}/diff.xml)
set_property(TEST xml-diff PROPERTY WILL_FAIL true)
add_test(NAME xml-diff_equal
COMMAND xml-diff -f ${CMAKE_CURRENT_SOURCE_DIR}/test.xml -t
${CMAKE_CURRENT_SOURCE_DIR}/test.xml)
endif()
5 changes: 5 additions & 0 deletions tests/diff.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<root>
<foo a="1"/>
<foo a="2"/>
<bar a="3"/>
</root>
2 changes: 2 additions & 0 deletions tests/xml_patch_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*
*/

#include "config.h"

#include <stddef.h>
#include <stdlib.h>
#include <string.h>
Expand Down

0 comments on commit 441ac44

Please sign in to comment.