[CMake] How to locate clang-format

Michi Henning michi.henning at canonical.com
Thu Jan 2 19:53:58 EST 2014


On 2 Jan 2014, at 14:13 , Matt Wilbur <wilburm at gmail.com> wrote:

> I am a CMake newbie (like, just this week), and this is only a partial solution (I think I could probably flesh it out if we knew what the version string would look like in all situations), but maybe something like this:

find_package will always fail to find clang-format because there is no cmake module for this.

It turns out that there is fairly simple way to find it though:

find_program(CLANG_FORMAT NAMES clang-format clang-format-3.6 clang-format-3.5 clang-format-3.4)

This picks the first match in the list of names, which is just what I need. It's not totally generic because,
when a new version of clang-format is released, the command needs updating. But that's
acceptable for me.

Cheers,

Michi.


More information about the CMake mailing list