Compiling lensfun-0.3.95 on Debian Buster

Lensfun provides lens distoration correction for Darktable and other raw processing applications. Version 0.3.95 provides ability to use the Adobe Camera Model, and hence use Adobe lens profiles (lcp files). However, lensfun 0.3.95 is not packaged for Debian Buster. Also Darktable won’t compile against the latest git version of Lensfun, so you must compile and install specifically version 0.3.95 to get ACM support.

We begin by downloading and extracting Lensfun 0.3.95. Lensfun 0.3.95 is not tagged in git, so we have to download the release directly from SourceForge. The release is not available from the GitHub repository.

$ wget
$ tar -xvf lensfun-0.3.95.tar.gz
$ cd lensfun-0.3.95/

Lensfun uses CMake for building and has also has CPack enabled. We can use it to build a deb package and install it. This allows easier integration and uninstallation in the future.

$ mkdir build
$ cd build
$ make -j`nproc` && make package
$ sudo apt install ./liblensfun2_0.3.95.0_amd64.deb

Enabling C++11 (C++0x) in CMake

Going over some CMakeLists.txt files I’ve written, I came across the following snippet:

	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
        message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")

Various compiler versions of gcc and clang use different flags to specify C++11 support, namely older ones accept -std=c++0x and newer one -std=c++11. The above snippets detects which is the right one for the compiler being used and adds the flag to the CXX_FLAGS.

Vim: Creating .clang_complete using CMake

The clang_complete plugin for Vim, offers superior code completion. If your project is anything but trivial, it will only do so if you provide .clang_compelete file with the right compilation argument. The easy way to do so is by using the script that comes with it to record the options directly into the .clang_compelete file. Usually one does

make CXX='~/.vim/bin/ clang++'

However, the makefile generated by CMake doesn’t support the CXX configuration.

The solution is to call CMake with the CXX environment variable set:

CXX="$HOME/.vim/bin/ clang++" cmake ..

Note that this will create the clang_complete file in the build directory (I’ve assumed out-of-place build), so just copy over the file to the working dir of your vim so it can find it. You’ll need to re-run cmake again (without the CXX, to disable re-creating the .clang_complete file each time.

While looking for this solution, I’ve first tried solving it by setting the CMAKE_CXX_COMPILER variable in CMake, however for some strange reason it didn’t like it, saying that the compiler wasn’t found (it shuns command line arguments given in the compiler command).

The more I use clang_compelete the more awesome I find it. It has it quirks but nonetheless it’s much simpler and better than manually creating tag files for each library.

Updated 6/1/2014: When setting CXX use $HOME instead of ~ (fix issues with newer versions of CMake).

Auto-Detect Dependencies when Building .debs Using CMake

CMake (via CPack) as a great feature that allows you to automatically generate Debian/Ubuntu (.deb) packages. One of the annoying things to do when you create a package is listing its dependencies. CMake asks you do it via the CPACK_DEBIAN_PACKAGE_DEPENDS variable. For example:

set (CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>=2.7-18)")

But what happens when you work on a more complex project? Keeping track of all the dependencies by hand is a tedious task. Debian provides a tool named dpkg-shlibdeps which makes this task easier by updating the debian/control file with dependencies extracted from the dynamic libraries needed by a given executable. Luckily since CMake 2.8.3, CMake also supports running this tool automatically to figure out the required dependencies. The documentation is sparse, and I had hard time finding how to do so (I actually found it via a bug report and a commit message, but afterwards I’ve seen it the official documentation too). To enable it, you need to add the following line to your CMakeLists.txt file:

# autogenerate dependency information