CMake is a unified, cross-platform, open-source build system that enables developers to build, test and package software by specifying build parameters in simple, portable text files. It works in a compiler-independent manner and the build process works in conjunction with native build environments, such as Make, Apple‘s Xcode and Microsoft Visual Studio. It also has minimal dependencies, C++ only. CMake is open source software and is developed by Kitware(taken from Wikipedia)

But you already know that because CMake is the build system we use in KDE 🙂

When I started to use CMake at work to port a large project from Windows to Linux, I needed to write a lot of modules (“finders”). Those modules had to work on Windows and Linux, and sometimes with different versions of some of the third-party dependencies. Parsing header files, Windows registry entries, etc was often required.

If you have ever parsed text, you know you powerful regular expressions are. If you use old software, you know how great Perl Compatible Regular Expressions (PCRE) are because you do not have them available :-).

Regular Expressions are available in CMake but the implementation is not PCRE but just POSIX Extended Regular Expressions, which are not as good.

A few years ago, I started to add PCRE support to CMake, using the canonical solution for this: the PCRE library by Philip Hazel. Back then, I implemented support for PCRE for the CMake “string” command; it worked but I didn’t finish the implementation because it required some important changes in CMake and back then (they were still using CVS!) contributing was difficult.

My wish for today: implement PCRE support for CMake.

These are the commands and macros you’ll need to touch:

If you want my source code, just ask me.

The implementation itself is relatively easy, especially if you use Google’s C++ wrapper to PCRE, which is part of PCRE itself. Essentially, you need to write a wrapper to cmsys::RegularExpression and pcrecpp::RE and use that wrapper where cmsys::RegularExpression is currently being used. The reason you need this wrapper is cmsys::RegularExpression supports some operations pcrecpp::RE doesn’t, such as going from a match to the previous or next match. The mapping from newRegexWrapper to cmsys::RegularExpression is direct, the mapping from newRegexWrapper to pcrecpp::RE requires some code and state tracking but not a lot.

Given that CMake now uses git for development, it should be much much easier to keep up to pace with development and contribute.

CMake is not in Google Summer of Code as a mentoring organization, but VTK (another project by Kitware, which also uses CMake) is. It might be possible to apply for CMake development through VTK 😕

Update 20110430 Debajyoti Datta will be implementing this in Season of KDE 2011, I will be the mentor He failed.

 

6 Thoughts on “A wish a day 11: Perl Compatible Regular Expressions in CMake

  1. How would you select the regex format in the CMake syntax?

  2. Probably with the use of the policy mechanism. You set the policy to TRUE and regexes are interpreted as pcre rather than the default.

    This feature would most likely involve adding a copy of libpcre to the cmake repository (fully external dependencies are a no-no) with the option to use the system copy.

    Also, don’t forget unit tests. This would never be accepted without those (both to ensure that the old behavior still works, the policy works as expected, and that the regexes are hooked up properly).

  3. @Nicolas

    How? Very easily! Currently you do:

    string( REGEX MATCH | MATCHALL | REPLACE | … )

    I added:

    string( PCRE MATCH | MATCHALL | REPLACE … )

    (same for the other commands)

    I. e. both mechanisms would be kept and you would be able to use both on your project. No need to complicate this with policies 🙂

  4. @Ben

    Yes, a copy of libpcre would be added. That was OK’d by CMake developers back then. Another possibility is to use Google’s re2, but back then it didn’t work well on Windows.

    As for unit tests: of course. When you are going to contribute to a project, you have to abide by the rules.

  5. I think you could apply for this through KDE too, as an umbrella organization, or perhaps through VTK as another heavy user of CMake. If there are students out there thinking of putting a proposal together we would be receptive.

  6. Pingback: About me! « dbdatta

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Post Navigation