Skip to content

Accept multi-line 'project(..)' in 'CMakeLists.txt'

When loading and parsing a CMakeLists.txt file to extract the project's name from the CMake command project(..), do not assume that the project command spans only over a single line, e.g. like project(myfancyapp)

It is totally fine for CMake to format the command to span several lines like this: project( myfancyapp )

This commit solves this issue by reading the CMakeLists.txt file completely instead line-by-line, then performs a multi-line regular expression match to identify the project command.

As a side bonus, the updated regular expression also ignores project commands in comments, i.e. requires that a found project command is not prefixed by '#'.

Edited by Adriaan de Groot

Merge request reports