Skip to content

Commit

Permalink
Added a BuildConfig header that is generated by
Browse files Browse the repository at this point in the history
cmake to keep track of the OSGEARTH_HAVE_XXX
defines rather than passing in preprocessor.
This allows consuming applications to inspect
the build configuration when building their application.
  • Loading branch information
jasonbeverage committed Apr 1, 2024
1 parent 5709100 commit 683ff48
Show file tree
Hide file tree
Showing 13 changed files with 63 additions and 38 deletions.
44 changes: 28 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ find_package(OpenGL REQUIRED)
find_package(OSG REQUIRED)
find_package(CURL REQUIRED)
find_package(GDAL REQUIRED)
find_package(Sqlite3 REQUIRED)

# optional
find_package(GEOS)
find_package(Sqlite3)

find_package(Draco)
find_package(BASISU)
find_package(GLEW)
Expand All @@ -138,6 +139,27 @@ find_package(Blend2D)
find_package(Blosc)
find_package(spdlog)

# Configure OSGEARTH_HAVE_XXX variables for the BuildConfig
IF(Protobuf_FOUND AND Protobuf_PROTOC_EXECUTABLE)
SET(OSGEARTH_HAVE_MVT ON)
ENDIF()

if(SQLITE3_FOUND)
set(OSGEARTH_HAVE_MBTILES ON)
endif(SQLITE3_FOUND)

if(Protobuf_FOUND)
set(OSGEARTH_HAVE_PROTOBUF ON)
endif()

IF (GEOS_FOUND)
set(OSGEARTH_HAVE_GEOS ON)
ENDIF(GEOS_FOUND)

if(draco_FOUND)
set(OSGEARTH_HAVE_DRACO ON)
endif(draco_FOUND)

if(OSGEARTH_BUILD_CESIUM_NODEKIT)
find_package(CesiumNative)
endif()
Expand Down Expand Up @@ -174,20 +196,6 @@ if(spdlog_FOUND)
add_definitions(-DHAVE_SPDLOG)
endif()

# Sqlite enables the MBTiles format:
if(SQLITE3_FOUND)
ADD_DEFINITIONS(-DOSGEARTH_HAVE_MBTILES)
endif(SQLITE3_FOUND)

# DRACO enables geometry compression sometimes used in glTF:
if(draco_FOUND)
ADD_DEFINITIONS(-DOSGEARTH_HAVE_DRACO)
endif(draco_FOUND)

if(Protobuf_FOUND)
add_definitions(-DOSGEARTH_HAVE_PROTOBUF)
endif()

# Tracy is a profiler
if(TRACY_FOUND AND OSGEARTH_ENABLE_PROFILING)
ADD_DEFINITIONS(-DOSGEARTH_PROFILING)
Expand All @@ -199,9 +207,13 @@ if(GLEW_FOUND AND EXISTS "${OSGEARTH_SOURCE_DIR}/src/third_party/imgui/imgui.cpp
endif()

if(OSGEARTH_ENABLE_GEOCODER)
add_definitions(-DOSGEARTH_HAVE_GEOCODER)
set(OSGEARTH_HAVE_GEOCODER ON)
endif()

IF(BLEND2D_FOUND)
set(OSGEARTH_HAVE_BLEND2D ON)
ENDIF()

if(OSGEARTH_ASSUME_SINGLE_GL_CONTEXT)
add_definitions(-DOSGEARTH_SINGLE_GL_CONTEXT)
endif()
Expand Down
4 changes: 0 additions & 4 deletions src/applications/osgearth_mvtindex/osgearth_mvtindex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/

// TODO: Reconfigure CMake to not require this.....
#define OSGEARTH_HAVE_MVT 1
#define OSGEARTH_HAVE_SQLITE3 1

#include <osgEarth/TileKey>
#include <osgEarth/FeatureSource>
#include <osgEarth/FeatureCursor>
Expand Down
13 changes: 13 additions & 0 deletions src/osgEarth/BuildConfig.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// BuildConfig - Generated by CMake
#ifndef OSGEARTH_BUILDCONFIG_H
#define OSGEARTH_BUILDCONFIG_H

#cmakedefine OSGEARTH_HAVE_MVT
#cmakedefine OSGEARTH_HAVE_MBTILES
#cmakedefine OSGEARTH_HAVE_PROTOBUF
#cmakedefine OSGEARTH_HAVE_GEOS
#cmakedefine OSGEARTH_HAVE_DRACO
#cmakedefine OSGEARTH_HAVE_GEOCODER
#cmakedefine OSGEARTH_HAVE_BLEND2D

#endif // OSGEARTH_BUILDCONFIG_H
11 changes: 5 additions & 6 deletions src/osgEarth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ set(OSGEARTH_VERSION_HEADER "${OSGEARTH_BUILDTIME_INCLUDE_DIR}/osgEarth/Version"
message(STATUS "Creating ${OSGEARTH_VERSION_HEADER}")
configure_file(Version.in ${OSGEARTH_VERSION_HEADER})

set(OSGEARTH_BUILDCONFIG_HEADER "${OSGEARTH_BUILDTIME_INCLUDE_DIR}/osgEarth/BuildConfig")
message(STATUS "Creating ${OSGEARTH_BUILDCONFIG_HEADER}")
configure_file(BuildConfig.in ${OSGEARTH_BUILDCONFIG_HEADER})

# Name all the library files
SET(LIB_NAME osgEarth)

Expand Down Expand Up @@ -920,19 +924,15 @@ ENDIF(BLOSC_FOUND)

# GEOS support?
IF (GEOS_FOUND)
ADD_DEFINITIONS(-DOSGEARTH_HAVE_GEOS)
INCLUDE_DIRECTORIES(${GEOS_INCLUDE_DIR})
LINK_WITH_VARIABLES(${LIB_NAME} GEOS_LIBRARY)
ENDIF(GEOS_FOUND)

# Protobuf/MVT?
IF(Protobuf_FOUND AND Protobuf_PROTOC_EXECUTABLE)

ADD_DEFINITIONS(-DOSGEARTH_HAVE_MVT)
IF(Protobuf_FOUND AND Protobuf_PROTOC_EXECUTABLE)
IF (PROTOBUF_USE_DLLS)
ADD_DEFINITIONS(-DPROTOBUF_USE_DLLS)
ENDIF()

LINK_WITH_VARIABLES(${LIB_NAME} Protobuf_LIBRARIES)
ENDIF()

Expand All @@ -944,7 +944,6 @@ IF(FILEGDB_FOUND)
ENDIF()

IF(BLEND2D_FOUND)
add_definitions(-DOSGEARTH_HAVE_BLEND2D)
include_directories(${BLEND2D_INCLUDES})
link_with_variables(${LIB_NAME} BLEND2D_LIBRARY)
ENDIF()
Expand Down
1 change: 1 addition & 0 deletions src/osgEarth/Common
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <osgEarth/Export>
#include <osgEarth/Notify>
#include <osgEarth/BuildConfig>
#include <osg/ref_ptr>
#include <osg/Referenced>
#include <memory>
Expand Down
1 change: 1 addition & 0 deletions src/osgEarth/FeatureRasterizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <osgEarth/FeatureSource>
#include <osgEarth/StyleSheet>
#include <osgText/String>
#include <osgEarth/BuildConfig>

using namespace osgEarth;

Expand Down
3 changes: 2 additions & 1 deletion src/osgEarth/GEOS
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
#ifndef OSGEARTHSYMBOLOGY_GEOS_H
#define OSGEARTHSYMBOLOGY_GEOS_H 1

#include <osgEarth/Common>

#ifdef OSGEARTH_HAVE_GEOS

#include <osgEarth/Common>
#include <osgEarth/Style>
#include <osgEarth/Geometry>

Expand Down
3 changes: 2 additions & 1 deletion src/osgEarth/GEOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#include <osgEarth/GEOS>

#ifdef OSGEARTH_HAVE_GEOS

#include <osgEarth/GEOS>
#include <osg/Notify>

using namespace osgEarth;
Expand Down
1 change: 1 addition & 0 deletions src/osgEarth/ImGui/ImGuiApp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "CameraGUI"
#include "RenderingGUI"
#include "AnnotationsGUI"
#include <osgEarth/BuildConfig>

#include <osgDB/ReadFile>

Expand Down
1 change: 1 addition & 0 deletions src/osgEarth/ImGui/LayersGUI
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#endif
#endif

#include <osgEarth/BuildConfig>
#include <osgEarth/Registry>
#include <osgEarth/XYZ>
#include <osgEarth/TMS>
Expand Down
12 changes: 6 additions & 6 deletions src/osgEarth/MVT
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
#ifndef OSGEARTH_FEATURES_MVT
#define OSGEARTH_FEATURES_MVT 1


#include <osgEarth/Common>
#include <osgEarth/FeatureSource>

#ifdef OSGEARTH_HAVE_MVT

#include <osgEarth/FeatureSource>

namespace osgEarth { namespace MVT
{
//! Reads features from an MVT stream for the specified tile.
Expand All @@ -48,8 +50,6 @@ namespace osgEarth { namespace MVT
} } // osgEarth::MVT


#ifdef OSGEARTH_HAVE_SQLITE3

namespace osgEarth
{
/**
Expand Down Expand Up @@ -116,9 +116,9 @@ namespace osgEarth

OSGEARTH_SPECIALIZE_CONFIG(osgEarth::MVTFeatureSource::Options);

#endif // OSGEARTH_HAVE_SQLITE3

#endif // OSGEARTH_HAVE_MVT
#else
#pragma message("osgEarth was not built with MVT support")
#endif

#endif // OSGEARTH_FEATURES_MVT

5 changes: 2 additions & 3 deletions src/osgEarth/MVT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#ifdef OSGEARTH_HAVE_MVT

#include <osgEarth/MVT>

#ifdef OSGEARTH_HAVE_MVT

#include <osgEarth/Registry>
#include <osgEarth/FileUtils>
#include <osgEarth/GeoData>
Expand All @@ -30,9 +31,7 @@
#include <stdlib.h>
#include "vector_tile.pb.h"

#ifdef OSGEARTH_HAVE_SQLITE3
#include <sqlite3.h>
#endif

using namespace osgEarth;
using namespace osgEarth::MVT;
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarth/MapboxGLImageLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void MapBoxGL::StyleSheet::Source::loadFeatureSource(const std::string& styleShe
}
else if (type() == "vector-mbtiles")
{
#if defined(OSGEARTH_HAVE_MVT) && defined(OSGEARTH_HAVE_SQLITE3)
#if defined(OSGEARTH_HAVE_MVT)
URI uri(url(), context);

osg::ref_ptr< MVTFeatureSource > featureSource = new MVTFeatureSource();
Expand Down

0 comments on commit 683ff48

Please sign in to comment.