@@ -53,52 +53,106 @@ message(STATUS " server headers: ${PG_SERVER_INCLUDEDIR}")
5353message (STATUS " pkglibdir: ${PG_PKGLIBDIR} " )
5454
5555# -------------------------------------------------------------------
56- # xerces-c (needed by ORCA for DXL XML parsing)
57- # Prefer pkg-config (works on Linux and Homebrew macOS); fall back to
58- # manual find_library + find_path for installations without .pc files.
56+ # xerces-c (needed by ORCA for DXL XML parsing).
57+ #
58+ # Default on Linux: build the bundled submodule under third_party/xerces-c
59+ # as a static library folded into pg_orca.so. This makes the extension
60+ # self-contained — no runtime libxerces-c.so dependency — which matters
61+ # for the deb/rpm release packages (self-hosted Supabase, distroless
62+ # containers, hosts without a matching xerces-c package).
63+ #
64+ # Default on macOS: use Homebrew's xerces-c. Release packaging is
65+ # Linux-only; for macOS dev builds the system library is easier and
66+ # avoids quirks of the static build on the Apple toolchain.
67+ #
68+ # Override either way with -DPG_ORCA_BUNDLED_XERCES=ON/OFF.
5969# -------------------------------------------------------------------
60- find_package (PkgConfig QUIET )
61- if (PKG_CONFIG_FOUND)
62- pkg_check_modules (XERCES xerces-c )
70+ if (APPLE )
71+ set (_pg_orca_bundled_default OFF )
72+ else ()
73+ set (_pg_orca_bundled_default ON )
6374endif ()
75+ option (PG_ORCA_BUNDLED_XERCES
76+ "Build xerces-c from third_party/ submodule and link statically"
77+ ${_pg_orca_bundled_default} )
6478
65- if (XERCES_FOUND)
66- # pkg-config succeeded — prefer absolute paths from XERCES_LINK_LIBRARIES so
67- # the linker doesn't need to search for it. On macOS Homebrew, xerces-c
68- # lives in /opt/homebrew/opt/xerces-c/lib which is not a default search
69- # path, so passing only "-lxerces-c" fails with "library not found".
70- if (XERCES_LINK_LIBRARIES)
71- set (XERCES_LIB ${XERCES_LINK_LIBRARIES} )
72- else ()
73- set (XERCES_LIB ${XERCES_LIBRARIES} )
79+ if (PG_ORCA_BUNDLED_XERCES)
80+ set (_xerces_src "${CMAKE_SOURCE_DIR } /third_party/xerces-c" )
81+ if (NOT EXISTS "${_xerces_src} /CMakeLists.txt" )
82+ message (FATAL_ERROR
83+ "PG_ORCA_BUNDLED_XERCES=ON but ${_xerces_src} /CMakeLists.txt is "
84+ "missing. Run: git submodule update --init --recursive" )
7485 endif ()
75- set (XERCES_INCLUDE ${XERCES_INCLUDE_DIRS} )
76- message (STATUS "xerces-c (pkg-config): ${XERCES_LIB} " )
86+
87+ # Force xerces options before adding its subdirectory. FORCE is required
88+ # because xerces-c declares these with CACHE; without FORCE our values
89+ # would be ignored on the second cmake run.
90+ set (BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE )
91+ set (network OFF CACHE BOOL "" FORCE ) # no socket-based entity resolver
92+ set (transcoder "gnuiconv" CACHE STRING "" FORCE ) # use glibc iconv, not ICU
93+ set (message-loader "inmemory" CACHE STRING "" FORCE ) # no external catalog files
94+ set (threads ON CACHE BOOL "" FORCE )
95+ # Suppress xerces install rules; we never install its headers/libs.
96+ set (CMAKE_SKIP_INSTALL_RULES_BACKUP "${CMAKE_SKIP_INSTALL_RULES} " )
97+ set (CMAKE_SKIP_INSTALL_RULES TRUE )
98+ add_subdirectory (third_party/xerces-c EXCLUDE_FROM_ALL )
99+ set (CMAKE_SKIP_INSTALL_RULES "${CMAKE_SKIP_INSTALL_RULES_BACKUP} " )
100+
101+ set_target_properties (xerces-c PROPERTIES
102+ POSITION_INDEPENDENT_CODE ON
103+ CXX_VISIBILITY_PRESET hidden
104+ VISIBILITY_INLINES_HIDDEN ON )
105+
106+ # The xerces-c target propagates its include dirs as PUBLIC, so consumers
107+ # only need to link to it. Keep XERCES_INCLUDE empty for the static path.
108+ set (XERCES_LIB xerces-c)
109+ set (XERCES_INCLUDE "" )
110+ message (STATUS "xerces-c: bundled static build (third_party/xerces-c)" )
77111else ()
78- # Fall back to manual search
79- find_library (XERCES_LIB xerces-c
80- PATHS
81- /opt/homebrew/opt/xerces-c/lib # Apple Silicon Homebrew
82- /usr/local/opt/xerces-c/lib # Intel Homebrew
83- /usr/local/lib # Linux generic
84- /usr/lib
85- /usr/lib/x86_64-linux-gnu # Debian/Ubuntu amd64
86- /usr/lib/aarch64-linux-gnu # Debian/Ubuntu arm64
87- )
88- find_path (XERCES_INCLUDE xercesc/util/XercesDefs.hpp
89- PATHS
90- /opt/homebrew/opt/xerces-c/include
91- /usr/local/opt/xerces-c/include
92- /usr/local/include
93- /usr/include
94- )
95- if (NOT XERCES_LIB OR NOT XERCES_INCLUDE)
96- message (FATAL_ERROR
97- "xerces-c not found. Install it (e.g. 'apt install libxerces-c-dev' "
98- "or 'brew install xerces-c') or set -DXERCES_LIB= and "
99- "-DXERCES_INCLUDE= manually." )
112+ # Legacy path: find a system-installed xerces-c.
113+ find_package (PkgConfig QUIET )
114+ if (PKG_CONFIG_FOUND)
115+ pkg_check_modules (XERCES xerces-c )
116+ endif ()
117+
118+ if (XERCES_FOUND)
119+ # pkg-config succeeded — prefer absolute paths from XERCES_LINK_LIBRARIES
120+ # so the linker doesn't need to search for it. On macOS Homebrew,
121+ # xerces-c lives in /opt/homebrew/opt/xerces-c/lib which is not a
122+ # default search path, so passing only "-lxerces-c" fails.
123+ if (XERCES_LINK_LIBRARIES)
124+ set (XERCES_LIB ${XERCES_LINK_LIBRARIES} )
125+ else ()
126+ set (XERCES_LIB ${XERCES_LIBRARIES} )
127+ endif ()
128+ set (XERCES_INCLUDE ${XERCES_INCLUDE_DIRS} )
129+ message (STATUS "xerces-c (pkg-config): ${XERCES_LIB} " )
130+ else ()
131+ find_library (XERCES_LIB xerces-c
132+ PATHS
133+ /opt/homebrew/opt/xerces-c/lib # Apple Silicon Homebrew
134+ /usr/local/opt/xerces-c/lib # Intel Homebrew
135+ /usr/local/lib # Linux generic
136+ /usr/lib
137+ /usr/lib/x86_64-linux-gnu # Debian/Ubuntu amd64
138+ /usr/lib/aarch64-linux-gnu # Debian/Ubuntu arm64
139+ )
140+ find_path (XERCES_INCLUDE xercesc/util/XercesDefs.hpp
141+ PATHS
142+ /opt/homebrew/opt/xerces-c/include
143+ /usr/local/opt/xerces-c/include
144+ /usr/local/include
145+ /usr/include
146+ )
147+ if (NOT XERCES_LIB OR NOT XERCES_INCLUDE)
148+ message (FATAL_ERROR
149+ "xerces-c not found. Install it (e.g. 'apt install libxerces-c-dev' "
150+ "or 'brew install xerces-c'), set -DXERCES_LIB= and "
151+ "-DXERCES_INCLUDE= manually, or use the default "
152+ "-DPG_ORCA_BUNDLED_XERCES=ON to build from third_party/." )
153+ endif ()
154+ message (STATUS "xerces-c (manual): ${XERCES_LIB} , headers: ${XERCES_INCLUDE} " )
100155 endif ()
101- message (STATUS "xerces-c (manual): ${XERCES_LIB} , headers: ${XERCES_INCLUDE} " )
102156endif ()
103157
104158# -------------------------------------------------------------------
@@ -132,6 +186,15 @@ file(GLOB_RECURSE ORCA_CORE_SRC CONFIGURE_DEPENDS
132186
133187add_library (orca_core OBJECT ${ORCA_CORE_SRC} )
134188
189+ # Pull in xerces-c headers via the target's PUBLIC interface. For the
190+ # bundled build XERCES_LIB is the "xerces-c" target which propagates its
191+ # header search path; for the system build XERCES_LIB is a library path
192+ # with no usage requirements (XERCES_INCLUDE supplies headers separately,
193+ # see target_include_directories below). OBJECT libs accept
194+ # target_link_libraries since CMake 3.12 — no symbol is actually linked,
195+ # but compile-time properties propagate.
196+ target_link_libraries (orca_core PUBLIC ${XERCES_LIB} )
197+
135198target_compile_definitions (orca_core PUBLIC
136199 $<$<CONFIG :Debug >:GPOS_DEBUG >
137200 USE_CMAKE
0 commit comments