openmicroscopy/bioformats — pull request #1427 by rleigh-dundee (2014-11-20 00:28:29+00:00)
Title: C++: Path handling and installation location introspection

In order to load datafiles, modules, etc. it is necessary to know at runtime the location of the bioformats installation. This PR adds the necessary defines to the internal headers. It also adds the XML schema files to the installation using these paths. The main change is to add a module to the compat component which can introspect the installation. If configured using an absolute install prefix, this will be used. If configured without an install prefix e.g. on Windows or a relocatable binary build on Linux, it will introspect the library location, remove the library path to get the install root and check it's valid. This is overridable with the BIOFORMATS_HOME environment variable.

We will need to add the equivalent Windows logic once we have a Windows build; for now it's UNIX-only (all supported systems have dladdr(3)).

--------

Testing:

- Check the installed files to check the schema files are installed into $prefix/share/ome/bioformats/schema.
- Check the tests are passing.

Checking the module introspection works can be done by installing the ome-compat/module testcase (copy the install logic from showing) and add a print statement to log the installation prefix. This can then be tested in the build tree and install tree with and without an installation prefix (`-DCMAKE_INSTALL_PREFIX=`).

In cpp/test/ome-compat/CMakeLists.txt, append:

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

In cpp/test/ome-compat/module.cpp, replace the line in the try block with:

```
std::cout << "PREFIX=" << ome::compat::module_runtime_prefix() << '\n';
```

So basically, with these changes applied, you want to run these combinations:
- cmake with `-DCMAKE_INSTALL_PREFIX=` and "make install DESTDIR=/tmp/test1"
- cmake with `-DCMAKE_INSTALL_PREFIX=/tmp/test2` and "make install"
- For both of these, run cpp/test/ome-compat/test in the build tree and /install/path/bin/module
- For the install tree you'll need to set LD_LIBRARY_PATH=/install/path/lib[/...]:$buildtree/cpp/ext/gtest-1.7.0

You should see a sensible install path for both install trees. For the build tree it'll throw an exception (unless the install tree is present and you're using an absolute install path).

Because this is really only testable after installation, it's not possible to test this well with unit tests.