openmicroscopy/bioformats — pull request #1436 by rleigh-dundee (2014-11-24 20:06:53+00:00)
Title: cpp: compat: Add path type lookups to module

This extends the work in #1427 to allow introspection of specific path types, i.e. the bin dir, lib dir, various data directories etc. It adds bio-formats-specific paths for general data, schemas, transforms and icons.

The changes are needed to allow correct location of data, programs and libraries at runtime given that we know from configuration with cmake where they have been installed. The overriding with environment variables serves several purposes:

1. To allow relocation even when using fixed install paths
2. To allow testing in a staging directory by setting BIOFORMATS_HOME
3. To allow testing in the build tree, by setting individual BIOFORMATS_* variables to use their paths in the build tree (since the build tree layout does not match the install tree layout).

--------

Testing, similar to #1427. Firstly, add this patch to allow installation of the module test for testing in the install tree:

```
diff --git a/cpp/test/ome-compat/CMakeLists.txt b/cpp/test/ome-compat/CMakeLists.txt
index 03e2b5e..62a0445 100644
--- a/cpp/test/ome-compat/CMakeLists.txt
+++ b/cpp/test/ome-compat/CMakeLists.txt
@@ -109,4 +109,10 @@ if(BUILD_TESTS)

add_test(ome-compat/variant variant)

+ install(TARGETS module RUNTIME
+ DESTINATION ${CMAKE_INSTALL_FULL_BINDIR}
+ PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
+ GROUP_READ GROUP_EXECUTE
+ WORLD_READ WORLD_EXECUTE)
+
endif(BUILD_TESTS)
```

1. Configure with a fixed install prefix:

```
mkdir /tmp/b1
cd /tmp/b1
cmake -DCMAKE_INSTALL_PREFIX=/tmp/test1 ~/code/bioformats
make

BIOFORMATS_TEST_VERBOSE=true ./cpp/test/ome-compat/module
[ you should see exception messages for all the first set of tests ]

BIOFORMATS_SCHEMADIR=~/code/bioformats/components/specification/released-schema BIOFORMATS_TEST_VERBOSE=true ./cpp/test/ome-compat/module
[ schemadir should be valid now ]

make install DESTDIR=/tmp/test2
BIOFORMATS_HOME=/tmp/test2 BIOFORMATS_TEST_VERBOSE=true ./cpp/test/ome-compat/module
[ some tests should now pass, e.g. for datadir, schemadir, bindir ]

make install
BIOFORMATS_TEST_VERBOSE=true ./cpp/test/ome-compat/module
[ some tests should now pass, e.g. for datadir, schemadir, bindir ]

bin/module should run without problems in the install tree as above after install.
Similar use of BIOFORMATS_SCHEMADIR and BIOFORMATS_HOME should also work in the /tmp/test1 install tree.
```

2. Configure without an install prefix:

```
mkdir /tmp/b2
cd /tmp/b2
cmake -DCMAKE_INSTALL_PREFIX= ~/code/bioformats
make

BIOFORMATS_TEST_VERBOSE=true ./cpp/test/ome-compat/module
[ you should see exception messages for all the first set of tests ]

BIOFORMATS_SCHEMADIR=~/code/bioformats/components/specification/released-schema BIOFORMATS_TEST_VERBOSE=true ./cpp/test/ome-compat/module
[ schemadir should be valid now ]

make install DESTDIR=/tmp/test3
BIOFORMATS_HOME=/tmp/test3 BIOFORMATS_TEST_VERBOSE=true ./cpp/test/ome-compat/module
[ some tests should now pass, e.g. for datadir, schemadir, bindir ]

make install DESTDIR=/tmp/test4
cd /tmp/test4
DYLD_LIBRARY_PATH=/tmp/test4/lib:/tmp/b2/cpp/ext/gtest-1.7.0 BIOFORMATS_TEST_VERBOSE=true ./bin/module
[ some tests should now pass, e.g. for datadir, schemadir, bindir ]
Similar use of BIOFORMATS_SCHEMADIR and BIOFORMATS_HOME should also work in the /tmp/test4 install tree, e.g. pointing to the /tmp/test3 tree:
DYLD_LIBRARY_PATH=/tmp/test4/lib:/tmp/b2/cpp/ext/gtest-1.7.0 BIOFORMATS_HOME=/tmp/test3 BIOFORMATS_TEST_VERBOSE=true ./bin/module
[ all valid paths in /tmp/test3 ]
DYLD_LIBRARY_PATH=/tmp/test4/lib:/tmp/b2/cpp/ext/gtest-1.7.0 BIOFORMATS_SCHEMADIR=/tmp/test3/share/xml BIOFORMATS_TEST_VERBOSE=true ./bin/module
[ all valid paths in /tmp/test4 with the exception of schemadir which is in /tmp/test3 ]
```