Skip to content

Commit

Permalink
ogr/: CMAKE_UNITY_BUILD fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed Dec 5, 2023
1 parent 8646278 commit b9938e0
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 130 deletions.
12 changes: 1 addition & 11 deletions ogr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,7 @@ add_library(
ogr_proj_p.cpp
ogr_wkb.cpp)
add_dependencies(ogr generate_gdal_version_h)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.16)
set_property(
SOURCE ogrfeaturequery.cpp
ogr_srs_usgs.cpp
ogr_srs_panorama.cpp
swq_expr_node.cpp
swq_op_general.cpp
swq_parser.cpp
swq_select.cpp
PROPERTY SKIP_UNITY_BUILD_INCLUSION ON)
endif ()

include(GdalStandardIncludes)
gdal_standard_includes(ogr)
target_compile_options(ogr PRIVATE ${GDAL_CXX_WARNING_FLAGS} ${WFLAG_OLD_STYLE_CAST} ${WFLAG_EFFCXX})
Expand Down
8 changes: 4 additions & 4 deletions ogr/ogr_geocoding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct _OGRGeocodingSessionHS
OGRDataSource *poDS;
};

static CPLMutex *hMutex = nullptr;
static CPLMutex *hOGRGeocodingMutex = nullptr;
static double dfLastQueryTimeStampOSMNominatim = 0.0;
static double dfLastQueryTimeStampMapQuestNominatim = 0.0;

Expand Down Expand Up @@ -547,7 +547,7 @@ static OGRLayer *OGRGeocodeGetCacheLayer(OGRGeocodingSessionH hSession,
static char *OGRGeocodeGetFromCache(OGRGeocodingSessionH hSession,
const char *pszURL)
{
CPLMutexHolderD(&hMutex);
CPLMutexHolderD(&hOGRGeocodingMutex);

int nIdxBlob = -1;
OGRLayer *poLayer = OGRGeocodeGetCacheLayer(hSession, FALSE, &nIdxBlob);
Expand Down Expand Up @@ -578,7 +578,7 @@ static char *OGRGeocodeGetFromCache(OGRGeocodingSessionH hSession,
static bool OGRGeocodePutIntoCache(OGRGeocodingSessionH hSession,
const char *pszURL, const char *pszContent)
{
CPLMutexHolderD(&hMutex);
CPLMutexHolderD(&hOGRGeocodingMutex);

int nIdxBlob = -1;
OGRLayer *poLayer = OGRGeocodeGetCacheLayer(hSession, TRUE, &nIdxBlob);
Expand Down Expand Up @@ -1308,7 +1308,7 @@ static OGRLayerH OGRGeocodeCommon(OGRGeocodingSessionH hSession,
CPLHTTPResult *psResult = nullptr;
if (pdfLastQueryTime != nullptr)
{
CPLMutexHolderD(&hMutex);
CPLMutexHolderD(&hOGRGeocodingMutex);
struct timeval tv;

gettimeofday(&tv, nullptr);
Expand Down
4 changes: 0 additions & 4 deletions ogr/ogr_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,6 @@ int CPL_DLL OGRGeneralCmdLineProcessor(int nArgc, char ***ppapszArgv,

extern const char *const SpecialFieldNames[SPECIAL_FIELD_COUNT];

#ifdef SWQ_H_INCLUDED_
extern const swq_field_type SpecialFieldTypes[SPECIAL_FIELD_COUNT];
#endif

/************************************************************************/
/* Some SRS related stuff, search in SRS data files. */
/************************************************************************/
Expand Down
24 changes: 13 additions & 11 deletions ogr/ogr_srs_panorama.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ constexpr int NUMBER_OF_DATUMS = static_cast<int>(CPL_ARRAYSIZE(aoDatums));
/* Correspondence between "Panorama" and EPSG ellipsoid codes. */
/************************************************************************/

constexpr int aoEllips[] = {
constexpr int aoPanoramaEllips[] = {
0, // 0. Undefined
7024, // 1. Krassovsky, 1940
7043, // 2. WGS, 1972
Expand Down Expand Up @@ -182,7 +182,8 @@ constexpr int aoEllips[] = {
7054 // 47. PZ-90
};

constexpr int NUMBER_OF_ELLIPSOIDS = static_cast<int>(CPL_ARRAYSIZE(aoEllips));
constexpr int NUMBER_OF_PANORAM_ELLIPSOIDS =
static_cast<int>(CPL_ARRAYSIZE(aoPanoramaEllips));

/************************************************************************/
/* Correspondence between "Panorama" and EPSG vertical CS. */
Expand Down Expand Up @@ -620,14 +621,15 @@ OGRErr OGRSpatialReference::importFromPanorama(long iProjSys, long iDatum,
oGCS.importFromEPSG(aoDatums[iDatum]);
CopyGeogCSFrom(&oGCS);
}
else if (iEllips > 0 && iEllips < NUMBER_OF_ELLIPSOIDS &&
aoEllips[iEllips])
else if (iEllips > 0 && iEllips < NUMBER_OF_PANORAM_ELLIPSOIDS &&
aoPanoramaEllips[iEllips])
{
char *pszName = nullptr;
double dfSemiMajor = 0.0;
double dfInvFlattening = 0.0;

if (OSRGetEllipsoidInfo(aoEllips[iEllips], &pszName, &dfSemiMajor,
if (OSRGetEllipsoidInfo(aoPanoramaEllips[iEllips], &pszName,
&dfSemiMajor,
&dfInvFlattening) == OGRERR_NONE)
{
SetGeogCS(
Expand All @@ -637,7 +639,7 @@ OGRErr OGRSpatialReference::importFromPanorama(long iProjSys, long iDatum,
pszName),
pszName, dfSemiMajor, dfInvFlattening, nullptr, 0.0,
nullptr, 0.0);
SetAuthority("SPHEROID", "EPSG", aoEllips[iEllips]);
SetAuthority("SPHEROID", "EPSG", aoPanoramaEllips[iEllips]);
}
else
{
Expand Down Expand Up @@ -1128,15 +1130,15 @@ OGRErr OGRSpatialReference::exportToPanorama(long *piProjSys, long *piDatum,
#endif

int i = 0; // Used after for.
for (; i < NUMBER_OF_ELLIPSOIDS; i++)
for (; i < NUMBER_OF_PANORAM_ELLIPSOIDS; i++)
{
if (aoEllips[i])
if (aoPanoramaEllips[i])
{
double dfSM = 0.0;
double dfIF = 1.0;

if (OSRGetEllipsoidInfo(aoEllips[i], nullptr, &dfSM, &dfIF) ==
OGRERR_NONE &&
if (OSRGetEllipsoidInfo(aoPanoramaEllips[i], nullptr, &dfSM,
&dfIF) == OGRERR_NONE &&
std::abs(dfSemiMajor - dfSM) < 1e-10 * dfSemiMajor &&
std::abs(dfInvFlattening - dfIF) < 1e-10 * dfInvFlattening)
{
Expand All @@ -1146,7 +1148,7 @@ OGRErr OGRSpatialReference::exportToPanorama(long *piProjSys, long *piDatum,
}
}

if (i == NUMBER_OF_ELLIPSOIDS) // Didn't found matches.
if (i == NUMBER_OF_PANORAM_ELLIPSOIDS) // Didn't found matches.
{
#ifdef DEBUG
CPLDebug("OSR_Panorama",
Expand Down
23 changes: 12 additions & 11 deletions ogr/ogr_srs_usgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ constexpr long WGS84 = 12L;
/* Correspondence between GCTP and EPSG ellipsoid codes. */
/************************************************************************/

constexpr int aoEllips[] = {
constexpr int aoEllipsUSGS[] = {
7008, // Clarke, 1866 (NAD1927)
7034, // Clarke, 1880
7004, // Bessel, 1841
Expand Down Expand Up @@ -148,7 +148,7 @@ constexpr int aoEllips[] = {
0 // FIXME: WGS 60 --- skipped
};

#define NUMBER_OF_ELLIPSOIDS static_cast<int>(CPL_ARRAYSIZE(aoEllips))
#define NUMBER_OF_USGS_ELLIPSOIDS static_cast<int>(CPL_ARRAYSIZE(aoEllipsUSGS))

/************************************************************************/
/* OSRImportFromUSGS() */
Expand Down Expand Up @@ -730,9 +730,10 @@ OGRErr OGRSpatialReference::importFromUSGS(long iProjSys, long iZone,
}
}
}
else if (iDatum < NUMBER_OF_ELLIPSOIDS && aoEllips[iDatum])
else if (iDatum < NUMBER_OF_USGS_ELLIPSOIDS && aoEllipsUSGS[iDatum])
{
if (OSRGetEllipsoidInfo(aoEllips[iDatum], &pszName, &dfSemiMajor,
if (OSRGetEllipsoidInfo(aoEllipsUSGS[iDatum], &pszName,
&dfSemiMajor,
&dfInvFlattening) == OGRERR_NONE)
{
SetGeogCS(
Expand All @@ -742,7 +743,7 @@ OGRErr OGRSpatialReference::importFromUSGS(long iProjSys, long iZone,
pszName),
pszName, dfSemiMajor, dfInvFlattening, nullptr, 0.0,
nullptr, 0.0);
SetAuthority("SPHEROID", "EPSG", aoEllips[iDatum]);
SetAuthority("SPHEROID", "EPSG", aoEllipsUSGS[iDatum]);
}
else
{
Expand All @@ -758,7 +759,7 @@ OGRErr OGRSpatialReference::importFromUSGS(long iProjSys, long iZone,
CPLError(CE_Warning, CPLE_AppDefined,
"Wrong datum code %d. Supported datums 0--%d only. "
"Setting WGS84 as a fallback.",
static_cast<int>(iDatum), NUMBER_OF_ELLIPSOIDS);
static_cast<int>(iDatum), NUMBER_OF_USGS_ELLIPSOIDS);
SetWellKnownGeogCS("WGS84");
}

Expand Down Expand Up @@ -1159,13 +1160,13 @@ OGRErr OGRSpatialReference::exportToUSGS(long *piProjSys, long *piZone,
#endif

int i = 0; // Used after for.
for (; i < NUMBER_OF_ELLIPSOIDS; i++)
for (; i < NUMBER_OF_USGS_ELLIPSOIDS; i++)
{
double dfSM = 0.0;
double dfIF = 0.0;

if (OSRGetEllipsoidInfo(aoEllips[i], nullptr, &dfSM, &dfIF) ==
OGRERR_NONE &&
if (OSRGetEllipsoidInfo(aoEllipsUSGS[i], nullptr, &dfSM,
&dfIF) == OGRERR_NONE &&
CPLIsEqual(dfSemiMajor, dfSM) &&
CPLIsEqual(dfInvFlattening, dfIF))
{
Expand All @@ -1174,8 +1175,8 @@ OGRErr OGRSpatialReference::exportToUSGS(long *piProjSys, long *piZone,
}
}

if (i == NUMBER_OF_ELLIPSOIDS) // Didn't found matches; set
{ // custom ellipsoid parameters.
if (i == NUMBER_OF_USGS_ELLIPSOIDS) // Didn't found matches; set
{ // custom ellipsoid parameters.
#ifdef DEBUG
CPLDebug("OSR_USGS",
"Ellipsoid \"%s\" unsupported by USGS GCTP. "
Expand Down
20 changes: 10 additions & 10 deletions ogr/ogr_xerces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct LimitationStruct
};
} // namespace

static CPLMutex *hMutex = nullptr;
static CPLMutex *hOGRXercesMutex = nullptr;
static int nCounter = 0;
static bool bXercesWasAlreadyInitializedBeforeUs = false;
static OGRXercesStandardMemoryManager *gpExceptionMemoryManager = nullptr;
Expand Down Expand Up @@ -165,7 +165,7 @@ void *OGRXercesInstrumentedMemoryManager::allocate(XMLSize_t size)

LimitationStruct *pLimitation = nullptr;
{
CPLMutexHolderD(&hMutex);
CPLMutexHolderD(&hOGRXercesMutex);

if (gpoMapThreadTimeout)
{
Expand Down Expand Up @@ -258,7 +258,7 @@ void OGRXercesInstrumentedMemoryManager::deallocate(void *p)

LimitationStruct *pLimitation = nullptr;
{
CPLMutexHolderD(&hMutex);
CPLMutexHolderD(&hOGRXercesMutex);

if (gpoMapThreadTimeout)
{
Expand Down Expand Up @@ -293,7 +293,7 @@ void OGRStartXercesLimitsForThisThread(size_t nMaxMemAlloc,
double dfTimeoutSecond,
const char *pszMsgTimeout)
{
CPLMutexHolderD(&hMutex);
CPLMutexHolderD(&hOGRXercesMutex);
if (gpoMapThreadTimeout == nullptr)
{
gpoMapThreadTimeout = new std::map<GIntBig, LimitationStruct>();
Expand All @@ -314,7 +314,7 @@ void OGRStartXercesLimitsForThisThread(size_t nMaxMemAlloc,

void OGRStopXercesLimitsForThisThread()
{
CPLMutexHolderD(&hMutex);
CPLMutexHolderD(&hOGRXercesMutex);
(*gpoMapThreadTimeout).erase(CPLGetPID());
if (gpoMapThreadTimeout->empty())
{
Expand Down Expand Up @@ -394,7 +394,7 @@ OGRXercesNetAccessor::makeNew(const XMLURL &urlSource,

bool OGRInitializeXerces()
{
CPLMutexHolderD(&hMutex);
CPLMutexHolderD(&hOGRXercesMutex);

if (nCounter > 0)
{
Expand Down Expand Up @@ -451,7 +451,7 @@ bool OGRInitializeXerces()

void OGRDeinitializeXerces()
{
CPLMutexHolderD(&hMutex);
CPLMutexHolderD(&hOGRXercesMutex);
if (nCounter == 0)
{
CPLError(CE_Failure, CPLE_AppDefined,
Expand Down Expand Up @@ -481,9 +481,9 @@ void OGRDeinitializeXerces()

void OGRCleanupXercesMutex()
{
if (hMutex != nullptr)
CPLDestroyMutex(hMutex);
hMutex = nullptr;
if (hOGRXercesMutex != nullptr)
CPLDestroyMutex(hOGRXercesMutex);
hOGRXercesMutex = nullptr;
}

namespace OGR
Expand Down
Loading

0 comments on commit b9938e0

Please sign in to comment.