Skip to content

Commit

Permalink
Update examples CMakeList configuration to allow for standalone build
Browse files Browse the repository at this point in the history
  • Loading branch information
selimnairb committed Nov 1, 2023
1 parent 00488a8 commit 7ae9fbc
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 52 deletions.
8 changes: 8 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
80 changes: 80 additions & 0 deletions examples/CMakeModules/FindBAG.cmake
Original file line number Diff line number Diff line change
@@ -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
)
42 changes: 42 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -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.
52 changes: 0 additions & 52 deletions examples/Readme.txt

This file was deleted.

0 comments on commit 7ae9fbc

Please sign in to comment.