<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang=FR link=blue vlink="#954F72"><div class=WordSection1><p class=MsoNormal>OK so I ended up doing the following :</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Use a cmake script to detect coverage support and set up a new build type</p><p class=MsoNormal>+</p><p class=MsoNormal>Let CTest run GCov for me</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Final result can be seen here : <a href="https://github.com/Lectem/cpp-boilerplate">https://github.com/Lectem/cpp-boilerplate</a></p><p class=MsoNormal>link to the Coverage setup script : <a href="https://github.com/Lectem/cpp-boilerplate/blob/master/cmake/Coverage.cmake">https://github.com/Lectem/cpp-boilerplate/blob/master/cmake/Coverage.cmake</a><o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>This seems to be the best way to do it, it is non-intrusive (no CMAKE_<LANG>_FLAGS clobbering), plus it really does check that it is supported by the compiler, not assuming versions or anything.<o:p></o:p></p><p class=MsoNormal>If the user wants to build with coverage support, he only needs to use the Coverage build type, and can change the flags from the cache if needed, just as he would do with any build type.<o:p></o:p></p><p class=MsoNormal>Also not that since the codecov.io script runs GCov by default, using CTest is facultative. (but you need to make sure the gcov version matches the compiler used).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><div style='mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal style='border:none;padding:0cm'><b>De : </b><a href="mailto:annulen@yandex.ru">Konstantin Tokarev</a><br><b>Envoyé le :</b>lundi 7 août 2017 19:52<br><b>À : </b><a href="mailto:lectem@gmail.com">Clément Gregoire</a>; <a href="mailto:eike@sf-mail.de">Rolf Eike Beer</a><br><b>Cc : </b><a href="mailto:cmake@cmake.org">Cmake Mailing List</a><br><b>Objet :</b>Re: [CMake] Coverage support</p></div><p class=MsoNormal><o:p> </o:p></p><div><p class=MsoNormal> </p></div><div><p class=MsoNormal> </p></div><div><p class=MsoNormal>07.08.2017, 20:50, "Clément Gregoire" <lectem@gmail.com>:<o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p>This is mainly why I started this thread, I want to know the best way to do this without using those variables.<br>CMAKE_lang_FLAGS is a pain as soon as someone wants to use add_subdirectory (be it to add an external project or your project being used in another) or a user wants to change the value. Those variables should really only be set by the toolchain file or from the command-line.</p></blockquote><div><p class=MsoNormal><br>There's ExternalProject for this purpose</p></div><div><p class=MsoNormal> <o:p></o:p></p></div><blockquote style='margin-top:5.0pt;margin-bottom:5.0pt'><p>Other solutions were mentioned in my first mail, the easiest one being to add a new build type.<br>The other option is to uses something like a special script that will set those variables before your Cmakelists.txt (ie a toolchain file).<br><br> </p><p class=MsoNormal> </p><div><div><p class=MsoNormal>Le lun. 7 août 2017 à 17:22, Konstantin Tokarev <<a href="mailto:annulen@yandex.ru">annulen@yandex.ru</a>> a écrit :</p></div><p class=MsoNormal> </p><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm'><p class=MsoNormal>07.08.2017, 17:24, "Clément Gregoire" <<a href="mailto:lectem@gmail.com" target="_blank">lectem@gmail.com</a>>:<br>>> I usually stop reading Cmakelists.txt as soon as I see this<br>>><br>>> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -pthread -g -O0<br>>> -fprofile-arcs -ftest-coverage")<br>>><br>>> The pthread thing there is likely wrong anyway, and the -Wall is entirely optional. The other things are needed, otherwise gcov will not produce any useful output.<br>><br>> I don't have an issue with the flags per se, but with the usage of set(CMAKE_CXX_FLAGS). Setting flags like that should be banned from modern cmake scripts.<br><br>How can one set global compiler flags without use of CMAKE_CXX_FLAGS or setting flags for each individual target?<br><br>><br>>> Also you need to use the SETUP_TARGET_FOR_COVERAGE for every single test<br>>> target, which seems to be a difficult to scale on big projects<br>>><br>>> No, you don't. It's entirely fine if you just run "make test" as I do in OSM2go.<br>> From what I saw in the documentation of the script :<br>><br>>> # Param _testrunner The name of the target which runs the tests<br>><br>> It seems to call directly the command named _testrunner, which is somehow confirmed from the cmakelists :<br>><br>>> # src/CMakelists.txt<br>>> add_executable(tests ${TEST_FILES})<br>>><br>>> # Linking up all libraries<br>>><br>>> target_link_libraries(tests complex)<br>>><br>>> add_test(NAME example_test COMMAND tests)<br>>> # CMakelists.txt<br>>> setup_target_for_coverage(${PROJECT_NAME}_coverage tests coverage)<br>> From this I deduce that you need to call setup_target_for_coverage for each different test executable.<br>><br>> 2017-08-07 13:37 GMT+02:00 Rolf Eike Beer <<a href="mailto:eike@sf-mail.de" target="_blank">eike@sf-mail.de</a>>:<br>>> Am 2017-08-07 11:06, schrieb Clément Gregoire:<br>>> I usually stop reading Cmakelists.txt as soon as I see this<br>>><br>>> set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -pthread -g -O0<br>>> -fprofile-arcs -ftest-coverage")<br>>><br>>> The pthread thing there is likely wrong anyway, and the -Wall is entirely optional. The other things are needed, otherwise gcov will not produce any useful output.<br>>><br>>> Also you need to use the SETUP_TARGET_FOR_COVERAGE for every single test<br>>> target, which seems to be a difficult to scale on big projects<br>>><br>>> No, you don't. It's entirely fine if you just run "make test" as I do in OSM2go.<br>>><br>>> Eike<br>>> --<br>>><br>>> Powered by <a href="http://www.kitware.com/" target="_blank">www.kitware.com</a><br>>><br>>> Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>>><br>>> Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>>><br>>> CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/support.html</a><br>>> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>>> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</a><br>>><br>>> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>>><br>>> Follow this link to subscribe/unsubscribe:<br>>> <a href="http://public.kitware.com/mailman/listinfo/cmake" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br>> ,--<br>><br>> Powered by <a href="http://www.kitware.com/" target="_blank">www.kitware.com</a><br>><br>> Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>><br>> Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>><br>> CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/support.html</a><br>> CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>> CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</a><br>><br>> Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>><br>> Follow this link to subscribe/unsubscribe:<br>> <a href="http://public.kitware.com/mailman/listinfo/cmake" target="_blank">http://public.kitware.com/mailman/listinfo/cmake</a><br><br><br>-- <br>Regards,<br>Konstantin</p></blockquote></div></blockquote><div><p class=MsoNormal> </p></div><div><p class=MsoNormal> </p></div><div><p class=MsoNormal>-- <br>Regards,</p></div><div><p class=MsoNormal>Konstantin</p></div><p class=MsoNormal> </p><p class=MsoNormal><o:p> </o:p></p></div></body></html>