RWTH-HPC / CMake-codecov

CMake module for code coverage
BSD 3-Clause "New" or "Revised" License
89 stars 34 forks source link

get_filename_component doesn't cover .t.cpp #18

Closed giacomini closed 4 years ago

giacomini commented 5 years ago

Some source code layout guidelines suggest to name test source files with the combined extension .t.cpp. Unfortunately the use of get_filename_component at https://github.com/RWTH-HPC/CMake-codecov/blob/9a24e83a901e4acee01786ff2c75559f580bb772/cmake/Findcodecov.cmake#L136 is not adequate in such a situation, because it extracts the maximal extension .t.cpp instead of just .cpp, which makes the source file not recognizable.

An alternative would be the use of a regular expression, i.e. instead of:

get_filename_component(FILE_EXT "${FILE}" EXT)
string(TOLOWER "${FILE_EXT}" FILE_EXT)
string(SUBSTRING "${FILE_EXT}" 1 -1 FILE_EXT)

one could use

string(REGEX REPLACE "^.*\\.([^\\.]+)$" "\\1" FILE_EXT "${FILE}")
string(TOLOWER "${FILE_EXT}" FILE_EXT)
Twon commented 4 years ago

I've also just run into this issue. Actually get_filename_component() supports the parameter LAST_EXT which will then correctly return just the ".cpp" component of the filename (no need to a regex): https://cmake.org/cmake/help/latest/command/get_filename_component.html

This is just a one-line fix so I'll submit a pull request for this shortly.

Twon commented 4 years ago

Pull request submitted with a fix here: https://github.com/RWTH-HPC/CMake-codecov/pull/19

alehaa commented 4 years ago

Merged #19.

giacomini commented 4 years ago

Be careful, though, that LAST_EXT is available only in recent versions of CMake (3.14, I think).

alehaa commented 4 years ago

This has been fixed in ea06ae7c840195e30563b0c71b8a11766b338a14.

giacomini commented 4 years ago

Ok, fine with me, I can upgrade.