Grantlee Gems: Customizing plugin build output directory

I wanted to be able to to run all the Grantlee unit tests from the build directory without having to go through the install step. As the whole system is plugin based though, the plugins need to be sought and found in specified directories following a certain pattern. The pattern is ${Something}/grantlee/${version}/pluginname.so. For example, the default plugin in version 0.1 would be searched for in ${Something}/grantlee/0.1/default_tags.so for each value of ${Something} in the list QCoreApplication::libraryPaths.

That’s fine for running the tests against installed plugins. Well known library paths are searched for plugins. However, the output build directory for the tests is ${CMAKE_BINARY_DIR}/tests, and the output build directory for plugins is something like ${CMAKE_BINARY_DIR}/pluginname/pluginname.so. That doesn’t match the pattern /grantlee/${version}/pluginname.so, so my initial solution was to use the CMake install() command to install the plugins to a location inside the build directory. That unfortunately caused problems with packaging tools when testing with the OpenSUSE build service, and it wasn’t really an elegant solution.

The correct solution is to specify the directory the plugins should be built in. Instead of building the plugin to ${CMAKE_BINARY_DIR}/pluginname/pluginname.so, it should be built to ${CMAKE_BINARY_DIR}/grantlee/${version}/pluginname.so.

The magic to do that is to specify the ${LIBRARY_OUTPUT_DIRECTORY}. On Windows it’s ${RUNTIME_OUTPUT_DIRECTORY} in the set_target_properties command.

set_target_properties(${pluginname}
    LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/grantlee/${Grantlee_VERSION_MAJOR}.${Grantlee_VERSION_MINOR}"
    RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/grantlee/${Grantlee_VERSION_MAJOR}.${Grantlee_VERSION_MINOR}"
  )

Easy.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: