Skip to content

Commit

Permalink
Add example external project to test osgEarthConfig.cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Apr 3, 2024
1 parent 5b5e66a commit ea4e757
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
9 changes: 9 additions & 0 deletions share/ExternalProject/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.20)

project(ExternalExample)

find_package(osgEarth CONFIG REQUIRED)

add_executable(ExternalExample main.cpp)

target_link_libraries(ExternalExample PRIVATE osgEarth)
10 changes: 10 additions & 0 deletions share/ExternalProject/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# External Project Example
This is a simple example to test the `osgEarthConfig.cmake` packaging configuration file for CMake.

These line in your `CMakeLists.txt` will tell CMake to look for `osgEarthConfig.cmake` and use it to resolve osgEarth and its public-facing dependencies:
```
find_package(osgEarth CONFIG REQUIRED)
...
target_link_libraries(my_project PRIVATE osgEarth)
```
You may need to update your `CMAKE_PREFIX_PATH` to include the location of `osgEarthConfig.cmake`.
24 changes: 24 additions & 0 deletions share/ExternalProject/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <osgEarth/MapNode>
#include <osgEarth/TMS>
#include <osgEarth/EarthManipulator>
#include <osgViewer/Viewer>

int main(int argc, char** argv)
{
osg::ArgumentParser args(&argc, argv);
osgViewer::Viewer viewer(args);

osgEarth::initialize();
osgEarth::setNotifyLevel(osg::INFO);

auto layer = new osgEarth::TMSImageLayer();
layer->setURL("https://readymap.org/readymap/tiles/1.0.0/7/");

auto mapNode = new osgEarth::MapNode();
mapNode->getMap()->addLayer(layer);

viewer.setCameraManipulator(new osgEarth::Util::EarthManipulator());

viewer.setSceneData(mapNode);
return viewer.run();
}

0 comments on commit ea4e757

Please sign in to comment.