diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 3df05eedbe..2eb1667740 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,3 +1,11 @@ +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) + # Build examples as standalone project + cmake_minimum_required(VERSION 3.18) + project(bag-example LANGUAGES C CXX) + set(CMAKE_CXX_STANDARD 14) + set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules" ${CMAKE_MODULE_PATH}) +endif() + if(NOT BAG_BUILD_BAG_LIB) # Find installed BAGLIB as we did not build it find_package(BAG REQUIRED) diff --git a/examples/CMakeModules/FindBAG.cmake b/examples/CMakeModules/FindBAG.cmake new file mode 100644 index 0000000000..969d5109fb --- /dev/null +++ b/examples/CMakeModules/FindBAG.cmake @@ -0,0 +1,80 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See LICENSE +# file accompanying BAG source for details. + +#[=======================================================================[.rst: +FindBAG +------- + +Finds the BAG library. + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides the following imported targets, if found: + + The baglib library + +Result Variables +^^^^^^^^^^^^^^^^ + +This will define the following variables: + +``BAG_FOUND`` + True if the system has the BAG library. +``BAG_VERSION`` + The version of the BAG library which was found. +``BAG_INCLUDE_DIRS`` + Include directories needed to use BAG. +``BAG_LIBRARIES`` + Libraries needed to link to BAG. + +Cache Variables +^^^^^^^^^^^^^^^ + +The following cache variables may also be set: + +``BAG_INCLUDE_DIR`` + The directory containing ``bag_dataset.h``. +``BAG_LIBRARY`` + The path to the BAG library. + +#]=======================================================================] + +find_package(PkgConfig) +pkg_check_modules(PC_BAG QUIET BAG) + +find_path(BAG_INCLUDE_DIR + NAMES bag_dataset.h + PATHS ${PC_BAG_INCLUDE_DIRS} + PATH_SUFFIXES + include + include/bag + include/BAG + include/baglib +) +find_library(BAG_LIBRARY + NAMES baglib + PATHS ${PC_BAG_LIBRARY_DIRS} +) + +set(BAG_VERSION ${PC_BAG_VERSION}) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(BAG + FOUND_VAR BAG_FOUND + REQUIRED_VARS + BAG_LIBRARY + BAG_INCLUDE_DIR + VERSION_VAR BAG_VERSION +) + +if(BAG_FOUND) + set(BAG_LIBRARIES ${BAG_LIBRARY}) + set(BAG_INCLUDE_DIRS ${BAG_INCLUDE_DIR}) + set(BAG_DEFINITIONS ${PC_BAG_CFLAGS_OTHER}) +endif() + +mark_as_advanced( + BAG_INCLUDE_DIR + BAG_LIBRARY +) diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000000..1cdb8fd053 --- /dev/null +++ b/examples/README.md @@ -0,0 +1,42 @@ +# BAG C++ Sample Programs + +## Building standalone +First install libbaglib from the +[conda-forge](https://anaconda.org/conda-forge/libbaglib). + +Then install the following additional conda-forge packages: +```shell +conda install -c conda-forge ninja gcc gxx +``` + +Finally, build BAG examples (make sure you are in the `examples` sub-directory +when running these commands: +```shell +export CC=gcc # Windows: set CC=gcc +export CXX=g++ # Windows: set GXX=g++ +cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -B build -S . +cmake --build build +``` + +## sample-data +Contains a sample XML file and a prebuild BAG file as trivial +examples. + +## bag_read +A sample reading of a Bag file. See the readme.txt file inside +the sample-data directory for more information to test this +program. + +## bag_create +Creates a sample 10x10 row/column BAG file. See the readme.txt +file inside the sample-data directory for more information on +how to test this program. + +## bag_compoundlayer +Creates and reads a GeorefMetadataLayer. + +## bag_vr_create +Creates a variable resolution BAG. + +## bag_vr_read +Reads a variable resolution BAG. diff --git a/examples/Readme.txt b/examples/Readme.txt deleted file mode 100644 index 98eb2621a7..0000000000 --- a/examples/Readme.txt +++ /dev/null @@ -1,52 +0,0 @@ - -Overview of the C++ Sample Programs - -Environment -=========== - -Don't forget the requirement for BAG_HOME before trying the examples. - -On Linux/OS X: - -export BAG_HOME=$PWD/../configdata -setenv BAG_HOME $PWD/../configdata - -On Windows: - -set BAG_HOME=%CD%\..\configdata - - -sample-data ------------ - - Contains a sample XML file and a prebuild BAG file as trivial - examples. - -bag_read --------- - - A sample reading of a Bag file. See the readme.txt file inside - the sample-data directory for more information to test this - program. - -bag_create ----------- - - Creates a sample 10x10 row/column BAG file. See the readme.txt - file inside the sample-data directory for more information on - how to test this program. - -bag_compoundlayer ------------------ - - Creates and reads a GeorefMetadataLayer. - -bag_vr_create -------------- - - Creates a variable resolution BAG. - -bag_vr_read ------------ - - Reads a variable resolution BAG.