filipdutescu / modern-cpp-template

A template for modern C++ projects using CMake, Clang-Format, CI, unit testing and more, with support for downstream inclusion.
The Unlicense
1.69k stars 214 forks source link

[BUG] CMakeLists.txt source files and header files do not print as list #29

Closed nhanders closed 2 years ago

nhanders commented 2 years ago

Describe the bug In the projects CMakeLists.txt, there are calls to:

where the variables are lists set in SourcesAndHeaders.cmake.

However, when the messages are displayed in the console, only the first file is displayed in the list. E.g. if you have multiple sources, only the first file will be displayed.

To Reproduce Steps to reproduce the behavior:

  1. Add multiple source files or header files
  2. Build

Expected behavior Should display all the values in a list.

nhanders commented 2 years ago

Here are some possible solutions:

Solution 1

I found a pretty trivial solution on SO.

Instead of: verbose_message(${sources}) Enclose the variable in inverted commas: verbose_message("${sources}")

This isn't perfect since it doesn't print with delimiters (despite what the SO post says), but instead prints it as one long string.

Solution 2

Print each item in the list with a foreach statement:

foreach(source IN LISTS headers)
  verbose_message("* ${source}")
endforeach()

I'm in favour of solution 2. It is verbose, but since I'm using the verbose_message command, I'm wanting a verbose output.

I will create a PR for this when I get a moment this week.

filipdutescu commented 2 years ago

Hello! Thank you a lot for submitting this issue. I was also working with the second solution, as, for me, it seems like the better of the two. With a check before so we don't go through the foreach loop if verbose messaging is toggled off.

I would also like to extend my gratitude for your kindness of wishing to submit a PR. Since I have some free time at the moment, I will make the fix now, but, please, feel free to submit any PRs you would wish and I will look over them. Once I push the commit I will let you know, so you can confirm it fixes it on your end as well.

filipdutescu commented 2 years ago

Done, pushed the fix. Please confirm it works, whenever you can, or reopen if it doesn't. Thanks again!