Skip to content

Commit c29a8e1

Browse files
authored
Merge pull request InsightSoftwareConsortium#5865 from blowekamp/update_expat
ENH: Update Expat to R_2_7_4
2 parents 093598d + 27c4b65 commit c29a8e1

12 files changed

Lines changed: 164 additions & 129 deletions

File tree

Modules/ThirdParty/Expat/UpdateFromUpstream.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ readonly name="expat"
88
readonly ownership="Expat Upstream <kwrobot@kitware.com>"
99
readonly subtree="Modules/ThirdParty/Expat/src/itk$name"
1010
readonly repo="https://github.com/libexpat/libexpat.git"
11-
readonly tag="R_2_7_2"
11+
readonly tag="R_2_7_4"
1212
readonly exact_tree_match=false
1313
readonly paths="
1414
expat/CMakeLists.txt

Modules/ThirdParty/Expat/src/itkexpat/CMakeLists.txt

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
# Copyright (c) 2010 Patrick Spendrin <ps_ml@gmx.de>
99
# Copyright (c) 2012 Karl Waclawek <karl@waclawek.net>
10-
# Copyright (c) 2016-2025 Sebastian Pipping <sebastian@pipping.org>
10+
# Copyright (c) 2016-2026 Sebastian Pipping <sebastian@pipping.org>
1111
# Copyright (c) 2016 Sergei Nikulov <sergey.nikulov@gmail.com>
1212
# Copyright (c) 2016 Björn Lindahl <bjorn.lindahl@foi.se>
1313
# Copyright (c) 2016 Tobias Taschner <github@tc84.de>
@@ -32,15 +32,18 @@
3232
# Copyright (c) 2022 Johnny Jazeix <jazeix@gmail.com>
3333
# Copyright (c) 2022 Mark Brand <markbrand@google.com>
3434
# Copyright (c) 2022 David Faure <david.faure@kdab.com>
35+
# Copyright (c) 2025 Alfonso Gregory <gfunni234@gmail.com>
36+
# Copyright (c) 2026 Rosen Penev <rosenp@gmail.com>
37+
# Copyright (c) 2026 Gordon Messmer <gordon.messmer@gmail.com>
3538
# Unlike most of Expat,
3639
# this file is copyrighted under the BSD-license for buildsystem files of KDE.
3740

38-
cmake_minimum_required(VERSION 3.15.0)
41+
cmake_minimum_required(VERSION 3.17.0)
3942

4043
if (0) # ITK --start
4144
project(expat
4245
VERSION
43-
2.7.2
46+
2.7.4
4447
LANGUAGES
4548
C
4649
)
@@ -154,12 +157,10 @@ expat_shy_set(EXPAT_BUILD_DOCS ${_EXPAT_BUILD_DOCS_DEFAULT} CACHE BOOL "Build ma
154157
expat_shy_set(EXPAT_BUILD_FUZZERS OFF CACHE BOOL "Build fuzzers for the expat library")
155158
expat_shy_set(EXPAT_BUILD_PKGCONFIG ${_EXPAT_BUILD_PKGCONFIG_DEFAULT} CACHE BOOL "Build pkg-config file")
156159
expat_shy_set(EXPAT_OSSFUZZ_BUILD OFF CACHE BOOL "Build fuzzers via OSS-Fuzz for the expat library")
157-
if(UNIX OR _EXPAT_HELP)
158-
expat_shy_set(EXPAT_WITH_LIBBSD OFF CACHE BOOL "Utilize libbsd (for arc4random_buf)")
159-
endif()
160160
expat_shy_set(EXPAT_ENABLE_INSTALL ON CACHE BOOL "Install expat files in cmake install target")
161161
expat_shy_set(EXPAT_CONTEXT_BYTES 1024 CACHE STRING "Define to specify how much context to retain around the current parse point, 0 to disable")
162162
mark_as_advanced(EXPAT_CONTEXT_BYTES)
163+
expat_shy_set(EXPAT_SYMBOL_VERSIONING OFF CACHE BOOL "Define to provide symbol versioning for dependency generation")
163164
expat_shy_set(EXPAT_DTD ON CACHE BOOL "Define to make parameter entity parsing functionality available")
164165
mark_as_advanced(EXPAT_DTD)
165166
expat_shy_set(EXPAT_GE ON CACHE BOOL "Define to make general entity parsing functionality available")
@@ -214,15 +215,6 @@ if(EXPAT_DTD AND NOT EXPAT_GE)
214215
message(SEND_ERROR "Please either enable option EXPAT_GE (recommended) or disable EXPAT_DTD also.")
215216
endif()
216217

217-
if(EXPAT_WITH_LIBBSD)
218-
find_library(LIB_BSD NAMES bsd)
219-
if(NOT LIB_BSD)
220-
message(SEND_ERROR "EXPAT_WITH_LIBBSD option is enabled, but libbsd was not found")
221-
else()
222-
set(HAVE_LIBBSD TRUE)
223-
endif()
224-
endif()
225-
226218
if(MSVC)
227219
# For the three types of MSVC version values, please see:
228220
# - https://cmake.org/cmake/help/latest/variable/MSVC_VERSION.html
@@ -350,8 +342,8 @@ configure_file(itk_expat_mangle.h.in
350342
# ITK --stop
351343

352344
set(EXTRA_COMPILE_FLAGS)
353-
if(FLAG_NO_STRICT_ALIASING)
354-
set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -fno-strict-aliasing")
345+
if(FLAG_WSTRICT_ALIASING)
346+
set(EXTRA_COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -Wstrict-aliasing=3")
355347
endif()
356348
if(FLAG_VISIBILITY)
357349
if(EXPAT_SHARED_LIBS)
@@ -434,6 +426,12 @@ set(_EXPAT_C_SOURCES
434426

435427
if(EXPAT_SHARED_LIBS)
436428
set(_SHARED SHARED)
429+
if(EXPAT_DTD OR EXPAT_GE)
430+
set(_EXPAT_DTD_OR_GE TRUE)
431+
else()
432+
set(_EXPAT_DTD_OR_GE FALSE)
433+
endif()
434+
437435
#[[ ITK --start ITK does not use the .def file for MSVC
438436
if(WIN32)
439437
macro(_expat_def_file_toggle source_var target_var)
@@ -444,12 +442,6 @@ if(EXPAT_SHARED_LIBS)
444442
endif()
445443
endmacro()
446444
447-
if(EXPAT_DTD OR EXPAT_GE)
448-
set(_EXPAT_DTD_OR_GE TRUE)
449-
else()
450-
set(_EXPAT_DTD_OR_GE FALSE)
451-
endif()
452-
453445
_expat_def_file_toggle(_EXPAT_DTD_OR_GE _EXPAT_COMMENT_DTD_OR_GE)
454446
_expat_def_file_toggle(EXPAT_ATTR_INFO _EXPAT_COMMENT_ATTR_INFO)
455447
@@ -460,6 +452,20 @@ if(EXPAT_SHARED_LIBS)
460452
string(REPLACE "." "," _EXPAT_DLL_VERSION ${PROJECT_VERSION}.0)
461453
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/win32/version.rc.cmake" "${CMAKE_CURRENT_BINARY_DIR}/win32/version.rc")
462454
set(_EXPAT_EXTRA_SOURCES ${_EXPAT_EXTRA_SOURCES} "${CMAKE_CURRENT_BINARY_DIR}/win32/version.rc")
455+
else()
456+
macro(_expat_map_file_toggle source_var target_var)
457+
if(${source_var})
458+
set(${target_var} " ") # i.e. not commented out, a single space
459+
else()
460+
set(${target_var} "#") # i.e. commented out
461+
endif()
462+
endmacro()
463+
464+
_expat_map_file_toggle(_EXPAT_DTD_OR_GE _EXPAT_COMMENT_DTD_OR_GE)
465+
_expat_map_file_toggle(EXPAT_ATTR_INFO _EXPAT_COMMENT_ATTR_INFO)
466+
467+
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/lib/libexpat.map.in" "${CMAKE_CURRENT_BINARY_DIR}/lib/libexpat.map")
468+
set(_EXPAT_EXTRA_SOURCES ${_EXPAT_EXTRA_SOURCES} "${CMAKE_CURRENT_BINARY_DIR}/lib/libexpat.map")
463469
endif()
464470
#]] # ITK --stop
465471
else()
@@ -472,9 +478,6 @@ add_library(expat::expat ALIAS expat)
472478
if(_EXPAT_LIBM_FOUND)
473479
target_link_libraries(expat m)
474480
endif()
475-
if(EXPAT_WITH_LIBBSD)
476-
target_link_libraries(expat ${LIB_BSD})
477-
endif()
478481
479482
#]]
480483
# ITK -start
@@ -558,20 +561,19 @@ foreach(build_type_upper
558561
endforeach()
559562
560563
set(LIBCURRENT 12) # sync
561-
set(LIBREVISION 0) # with
564+
set(LIBREVISION 2) # with
562565
set(LIBAGE 11) # configure.ac!
563566
math(EXPR LIBCURRENT_MINUS_AGE "${LIBCURRENT} - ${LIBAGE}")
564567
565568
if(NOT WIN32)
566569
set_property(TARGET expat PROPERTY VERSION ${LIBCURRENT_MINUS_AGE}.${LIBAGE}.${LIBREVISION})
567570
set_property(TARGET expat PROPERTY SOVERSION ${LIBCURRENT_MINUS_AGE})
568571
set_property(TARGET expat PROPERTY NO_SONAME ${NO_SONAME})
572+
if(EXPAT_SYMBOL_VERSIONING)
573+
set_property(TARGET expat PROPERTY LINK_FLAGS "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/lib/libexpat.map")
574+
endif()
569575
570576
if(APPLE)
571-
if(NOT CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
572-
message(FATAL_ERROR "Expat requires CMake >=3.17 on platform \"APPLE\".")
573-
endif()
574-
575577
# NOTE: This intends to talk CMake into compatibility with GNU Libtool
576578
math(EXPR _EXPAT_MACHO_COMPATIBILITY_VERSION "${LIBCURRENT} + 1")
577579
set(_EXPAT_MACHO_CURRENT_VERSION "${_EXPAT_MACHO_COMPATIBILITY_VERSION}.${LIBREVISION}")
@@ -776,10 +778,6 @@ if(EXPAT_BUILD_TESTS)
776778
if(_EXPAT_LIBM_FOUND)
777779
target_link_libraries(${_target} m)
778780
endif()
779-
780-
if(EXPAT_WITH_LIBBSD)
781-
target_link_libraries(${_target} ${LIB_BSD})
782-
endif()
783781
endforeach()
784782
785783
add_executable(benchmark tests/benchmark/benchmark.c)
@@ -1105,7 +1103,6 @@ if(WIN32)
11051103
else()
11061104
message(STATUS " getrandom ................ ${HAVE_GETRANDOM}")
11071105
message(STATUS " syscall SYS_getrandom .... ${HAVE_SYSCALL_GETRANDOM}")
1108-
message(STATUS " libbsd ................... ${EXPAT_WITH_LIBBSD}")
11091106
message(STATUS " /dev/random .............. ${EXPAT_DEV_URANDOM}")
11101107
endif()
11111108
message(STATUS "")

Modules/ThirdParty/Expat/src/itkexpat/ConfigureChecks.cmake

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,9 @@ check_symbol_exists("getpagesize" "unistd.h" HAVE_GETPAGESIZE)
2222
check_symbol_exists("mmap" "sys/mman.h" HAVE_MMAP)
2323
check_symbol_exists("getrandom" "sys/random.h" HAVE_GETRANDOM)
2424

25-
if(EXPAT_WITH_LIBBSD)
26-
set(CMAKE_REQUIRED_LIBRARIES "${LIB_BSD}")
27-
set(_bsd "bsd/")
28-
else()
29-
set(_bsd "")
30-
endif()
31-
check_symbol_exists("arc4random_buf" "${_bsd}stdlib.h" HAVE_ARC4RANDOM_BUF)
25+
check_symbol_exists("arc4random_buf" "stdlib.h" HAVE_ARC4RANDOM_BUF)
3226
if(NOT HAVE_ARC4RANDOM_BUF)
33-
check_symbol_exists("arc4random" "${_bsd}stdlib.h" HAVE_ARC4RANDOM)
27+
check_symbol_exists("arc4random" "stdlib.h" HAVE_ARC4RANDOM)
3428
endif()
3529
set(CMAKE_REQUIRED_LIBRARIES)
3630

@@ -71,7 +65,24 @@ check_c_source_compiles("
7165
}"
7266
HAVE_SYSCALL_GETRANDOM)
7367

74-
check_c_compiler_flag("-fno-strict-aliasing" FLAG_NO_STRICT_ALIASING)
75-
check_c_compiler_flag("-fvisibility=hidden" FLAG_VISIBILITY)
68+
# If the compiler produces non-English messages and does not
69+
# listen to CMake's request for English through environment variables
70+
# LC_ALL/LC_MESSAGES/LANG, then command `check_c_compiler_flag` can produce
71+
# false positives as seen with e.g. `cl` of MSVC 19.44.35217 configured
72+
# to report errors in Italian language.
73+
check_c_compiler_flag("-no-such-thing" _FLAG_DETECTION_UNUSABLE)
74+
75+
if (_FLAG_DETECTION_UNUSABLE)
76+
message(WARNING
77+
"Your compiler breaks CMake's command `check_c_compiler_flag`."
78+
" HINT: Is it configured to report errors in a language other"
79+
" than English?"
80+
)
81+
set(FLAG_WSTRICT_ALIASING FALSE)
82+
set(FLAG_VISIBILITY FALSE)
83+
else()
84+
check_c_compiler_flag("-Wstrict-aliasing=3" FLAG_WSTRICT_ALIASING)
85+
check_c_compiler_flag("-fvisibility=hidden" FLAG_VISIBILITY)
86+
endif()
7687

7788
check_library_exists(m cos "" _EXPAT_LIBM_FOUND)

Modules/ThirdParty/Expat/src/itkexpat/expat_config.h.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
/* Define to 1 if you have the <inttypes.h> header file. */
2828
#cmakedefine HAVE_INTTYPES_H
2929

30-
/* Define to 1 if you have the `bsd' library (-lbsd). */
31-
#cmakedefine HAVE_LIBBSD
32-
3330
/* Define to 1 if you have the <memory.h> header file. */
3431
#cmakedefine HAVE_MEMORY_H
3532

Modules/ThirdParty/Expat/src/itkexpat/lib/expat.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
Copyright (c) 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
1212
Copyright (c) 2001-2002 Greg Stein <gstein@users.sourceforge.net>
1313
Copyright (c) 2002-2016 Karl Waclawek <karl@waclawek.net>
14-
Copyright (c) 2016-2025 Sebastian Pipping <sebastian@pipping.org>
14+
Copyright (c) 2016-2026 Sebastian Pipping <sebastian@pipping.org>
1515
Copyright (c) 2016 Cristian Rodríguez <crrodriguez@opensuse.org>
1616
Copyright (c) 2016 Thomas Beutlich <tc@tbeu.de>
1717
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
1818
Copyright (c) 2022 Thijs Schreijer <thijs@thijsschreijer.nl>
1919
Copyright (c) 2023 Hanno Böck <hanno@gentoo.org>
2020
Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>
2121
Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp>
22+
Copyright (c) 2025 Matthew Fernandez <matthew.fernandez@gmail.com>
2223
Licensed under the MIT license:
2324
2425
Permission is hereby granted, free of charge, to any person obtaining
@@ -276,7 +277,7 @@ XML_ParserCreate_MM(const XML_Char *encoding,
276277

277278
/* Prepare a parser object to be reused. This is particularly
278279
valuable when memory allocation overhead is disproportionately high,
279-
such as when a large number of small documnents need to be parsed.
280+
such as when a large number of small documents need to be parsed.
280281
All handlers are cleared from the parser, except for the
281282
unknownEncodingHandler. The parser's external state is re-initialized
282283
except for the values of ns and ns_triplets.
@@ -1081,7 +1082,7 @@ XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled);
10811082
*/
10821083
# define XML_MAJOR_VERSION 2
10831084
# define XML_MINOR_VERSION 7
1084-
# define XML_MICRO_VERSION 2
1085+
# define XML_MICRO_VERSION 4
10851086

10861087
# ifdef __cplusplus
10871088
}

Modules/ThirdParty/Expat/src/itkexpat/lib/expat_external.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
Copyright (c) 2001-2002 Greg Stein <gstein@users.sourceforge.net>
1313
Copyright (c) 2002-2006 Karl Waclawek <karl@waclawek.net>
1414
Copyright (c) 2016 Cristian Rodríguez <crrodriguez@opensuse.org>
15-
Copyright (c) 2016-2019 Sebastian Pipping <sebastian@pipping.org>
15+
Copyright (c) 2016-2025 Sebastian Pipping <sebastian@pipping.org>
1616
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
1717
Copyright (c) 2018 Yury Gribov <tetra2005@gmail.com>
1818
Licensed under the MIT license:
@@ -96,8 +96,7 @@
9696
# ifndef XML_BUILDING_EXPAT
9797
/* using Expat from an application */
9898

99-
# if defined(_MSC_EXTENSIONS) && ! defined(__BEOS__) \
100-
&& ! defined(__CYGWIN__)
99+
# if defined(_MSC_VER) && ! defined(__BEOS__) && ! defined(__CYGWIN__)
101100
# define XMLIMPORT __declspec(dllimport)
102101
# endif
103102
# endif

Modules/ThirdParty/Expat/src/itkexpat/lib/internal.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
#endif
109109

110110
#include <limits.h> // ULONG_MAX
111+
#include <stddef.h> // size_t
111112

112113
#if defined(_WIN32) \
113114
&& (! defined(__USE_MINGW_ANSI_STDIO) \
@@ -127,7 +128,7 @@
127128
# elif ULONG_MAX == 18446744073709551615u // 2^64-1
128129
# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "ld"
129130
# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "lu"
130-
# elif defined(EMSCRIPTEN) // 32bit mode Emscripten
131+
# elif defined(__wasm32__) // 32bit mode Emscripten or WASI SDK
131132
# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "ld"
132133
# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "zu"
133134
# else
@@ -153,6 +154,11 @@
153154
#define EXPAT_ALLOC_TRACKER_ACTIVATION_THRESHOLD_DEFAULT \
154155
67108864 // 64 MiB, 2^26
155156

157+
// NOTE: If function expat_alloc was user facing, EXPAT_MALLOC_ALIGNMENT would
158+
// have to take sizeof(long double) into account
159+
#define EXPAT_MALLOC_ALIGNMENT sizeof(long long) // largest parser (sub)member
160+
#define EXPAT_MALLOC_PADDING ((EXPAT_MALLOC_ALIGNMENT) - sizeof(size_t))
161+
156162
/* NOTE END */
157163

158164
#include "expat.h" // so we can use type XML_Parser below

0 commit comments

Comments
 (0)