Skip to content

Commit a9469df

Browse files
committed
VDV: embed vdv452.xml if EMBED_RESOURCE_FILES
1 parent d75856f commit a9469df

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

ogr/ogrsf_frmts/vdv/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,21 @@ add_gdal_driver(TARGET ogr_VDV SOURCES ogr_vdv.h ogrvdvdatasource.cpp PLUGIN_CAP
22
gdal_standard_includes(ogr_VDV)
33

44
set(GDAL_DATA_FILES
5-
${CMAKE_CURRENT_SOURCE_DIR}/data/vdv452.xml
65
${CMAKE_CURRENT_SOURCE_DIR}/data/vdv452.xsd
76
)
7+
if (NOT USE_ONLY_EMBEDDED_RESOURCE_FILES)
8+
list(APPEND GDAL_DATA_FILES
9+
${CMAKE_CURRENT_SOURCE_DIR}/data/vdv452.xml
10+
)
11+
endif()
812
set_property(
913
TARGET ${GDAL_LIB_TARGET_NAME}
1014
APPEND
1115
PROPERTY RESOURCE "${GDAL_DATA_FILES}")
16+
17+
if (EMBED_RESOURCE_FILES)
18+
add_driver_embedded_resources(ogr_VDV OGR_ENABLE_DRIVER_VDV_PLUGIN embedded_resources.c)
19+
endif()
20+
if (USE_ONLY_EMBEDDED_RESOURCE_FILES)
21+
target_compile_definitions(ogr_VDV PRIVATE USE_ONLY_EMBEDDED_RESOURCE_FILES)
22+
endif()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright 2024, Even Rouault <even.rouault at spatialys.com>
3+
4+
#include "embedded_resources.h"
5+
6+
static const char vdv452_xml[] = {
7+
#embed "data/vdv452.xml"
8+
, 0};
9+
10+
const char *VDVGet452XML(void)
11+
{
12+
return vdv452_xml;
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: MIT
2+
// Copyright 2024, Even Rouault <even.rouault at spatialys.com>
3+
4+
#include "cpl_port.h"
5+
6+
CPL_C_START
7+
8+
const char *VDVGet452XML(void);
9+
10+
CPL_C_END

ogr/ogrsf_frmts/vdv/ogrvdvdatasource.cpp

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include "cpl_time.h"
1616
#include <map>
1717

18+
#ifdef EMBED_RESOURCE_FILES
19+
#include "embedded_resources.h"
20+
#endif
21+
1822
#ifndef STARTS_WITH_CI
1923
#define STARTS_WITH(a, b) (strncmp(a, b, strlen(b)) == 0)
2024
#define STARTS_WITH_CI(a, b) EQUALN(a, b, strlen(b))
@@ -1702,14 +1706,34 @@ static bool OGRVDVWriteHeader(VSILFILE *fpL, CSLConstList papszOptions)
17021706

17031707
static bool OGRVDVLoadVDV452Tables(OGRVDV452Tables &oTables)
17041708
{
1709+
CPLXMLNode *psRoot = nullptr;
1710+
#if defined(USE_ONLY_EMBEDDED_RESOURCE_FILES)
1711+
const char *pszXMLDescFilename = nullptr;
1712+
#else
17051713
const char *pszXMLDescFilename = CPLFindFile("gdal", "vdv452.xml");
1706-
if (pszXMLDescFilename == nullptr)
1714+
#endif
1715+
if (pszXMLDescFilename == nullptr ||
1716+
EQUAL(pszXMLDescFilename, "vdv452.xml"))
17071717
{
1718+
#ifdef EMBED_RESOURCE_FILES
1719+
static const bool bOnce [[maybe_unused]] = []()
1720+
{
1721+
CPLDebug("VDV", "Using embedded vdv452.xml");
1722+
return true;
1723+
}();
1724+
psRoot = CPLParseXMLString(VDVGet452XML());
1725+
#else
17081726
CPLDebug("VDV", "Cannot find XML file : %s", "vdv452.xml");
17091727
return false;
1728+
#endif
17101729
}
17111730

1712-
CPLXMLNode *psRoot = CPLParseXMLFile(pszXMLDescFilename);
1731+
#ifdef EMBED_RESOURCE_FILES
1732+
if (!psRoot)
1733+
#endif
1734+
{
1735+
psRoot = CPLParseXMLFile(pszXMLDescFilename);
1736+
}
17131737
if (psRoot == nullptr)
17141738
{
17151739
return false;

0 commit comments

Comments
 (0)