<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 11 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><o:SmartTagType
namespaceuri="urn:schemas-microsoft-com:office:smarttags" name="PersonName"/>
<!--[if !mso]>
<style>
st1\:*{behavior:url(#default#ieooui) }
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:"Courier New \;";
        panose-1:0 0 0 0 0 0 0 0 0 0;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman";
        color:black;}
a:link, span.MsoHyperlink
        {color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {color:purple;
        text-decoration:underline;}
code
        {font-family:"Courier New";}
pre
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:Arial;
        color:windowtext;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:Arial;
        color:navy;}
@page Section1
        {size:8.5in 11.0in;
        margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor=white lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>Hi Fraser,<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>That’s a great suggestion! Thank you for
the script. It appears that CMake has support for GTESTS in CMake 2.8.2
which uses a macro, very similar to yours.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face=Arial><span style='font-size:
12.0pt;font-family:Arial'><a
href="http://public.kitware.com/cgibin/viewcvs.cgi/Modules/FindGTest.cmake?revision=1.4&root=CMake&view=markup">http://public.kitware.com/cgibin/viewcvs.cgi/Modules/FindGTest.cmake?revision=1.4&root=CMake&view=markup</a></span></font><font
size=2 color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'><o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 color=navy face=Arial><span style='font-size:
10.0pt;font-family:Arial;color:navy'><o:p> </o:p></span></font></p>
<p class=MsoNormal style='margin-left:.5in;text-indent:-.5in'><font size=2
color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>Thanks again!<o:p></o:p></span></font></p>
<p class=MsoNormal style='margin-left:.5in;text-indent:-.5in'><font size=2
color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'>Neelima<o:p></o:p></span></font></p>
<p class=MsoNormal style='margin-left:.5in;text-indent:-.5in'><font size=2
color=navy face=Arial><span style='font-size:10.0pt;font-family:Arial;
color:navy'><o:p> </o:p></span></font></p>
<div>
<div class=MsoNormal align=center style='text-align:center'><font size=3
color=black face="Times New Roman"><span style='font-size:12.0pt;color:windowtext'>
<hr size=2 width="100%" align=center tabindex=-1>
</span></font></div>
<p class=MsoNormal><b><font size=2 color=black face=Tahoma><span
style='font-size:10.0pt;font-family:Tahoma;color:windowtext;font-weight:bold'>From:</span></font></b><font
size=2 color=black face=Tahoma><span style='font-size:10.0pt;font-family:Tahoma;
color:windowtext'> Fraser Hutchison [mailto:fraser.hutchison@googlemail.com] <br>
<b><span style='font-weight:bold'>Sent:</span></b> Thursday, August 26, 2010
2:28 AM<br>
<b><span style='font-weight:bold'>To:</span></b> <st1:PersonName w:st="on">Neelima
Mehdiratta</st1:PersonName><br>
<b><span style='font-weight:bold'>Cc:</span></b> <st1:PersonName w:st="on">cmake@cmake.org</st1:PersonName><br>
<b><span style='font-weight:bold'>Subject:</span></b> Re: [CMake] CMake and
CTest for Google tests</span></font><font color=black><span style='color:windowtext'><o:p></o:p></span></font></p>
</div>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
style='font-size:12.0pt'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=3 color=black face="Times New Roman"><span
style='font-size:12.0pt'>Hi Neelima,<br>
<br>
If you're building the test executable(s) using CMake already and assuming you
have a variable like ${GTEST_SOURCE_FILES} which is a list of all your test
source files, you could probably get away without using a script to generate a
list of names by doing something like:<br>
<br>
</span></font><code><font size=2 face="Courier New"><span style='font-size:
10.0pt'>FOREACH(GTEST_SOURCE_FILE ${GTEST_SOURCE_FILES})</span></font></code><font
size=2 face="Courier New"><span style='font-size:10.0pt;font-family:"Courier New"'><br>
<code><font face="Courier New"> FILE(STRINGS ${GTEST_SOURCE_FILE}
GTEST_NAMES REGEX ^TEST)</font></code><br>
<code><font face="Courier New"> FOREACH(GTEST_NAME ${GTEST_NAMES})</font></code><br>
<code><font face="Courier New"> STRING(REGEX REPLACE
["\) \(,"] ";" GTEST_NAME ${GTEST_NAME})</font></code><br>
<code><font face="Courier New"> LIST(GET GTEST_NAME 1
GTEST_GROUP_NAME)</font></code><br>
<code><font face="Courier New"> LIST(GET GTEST_NAME 3
GTEST_NAME)</font></code><br>
<code><font face="Courier New">
ADD_TEST(${GTEST_GROUP_NAME}.${GTEST_NAME}
${EXECUTABLE_OUTPUT_PATH}/${BIN_NAME}
--gtest_filter=${GTEST_GROUP_NAME}.${GTEST_NAME})</font></code><br>
<code><font face="Courier New"> ENDFOREACH()</font></code><br>
<code><font face="Courier New">ENDFOREACH()</font></code><br>
<br>
</span></font>This relies on the tests each being defined by the Gtest macro
TEST(test fixture, test name) or TEST_F(test fixture, test name) in the source
files, but it would avoid the need to have the test executable built before
running the ADD_TEST command.<br>
<br>
Cheers,<br>
<br>
Fraser.<br>
<br>
<br>
<br>
<br>
On 25/08/2010 11:17 PM, <st1:PersonName w:st="on">Neelima Mehdiratta</st1:PersonName>
wrote: <o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><!--[if gte mso 9]><xml>
<u1:shapedefaults u2:ext="edit" spidmax="1026"/>
</xml><![endif]--><!--[if gte mso 9]><xml>
<u3:shapelayout u4:ext="edit">
<u3:idmap u4:ext="edit" data="1"/>
</u3:shapelayout>
</xml><![endif]-->I am using Google Tests to create unit tests for our
software. We are using CMake (version 4.6-patch 2) for building the
unit tests executable. Since the list of unit tests is expected to grow
to thousands of tests, I am looking for a way to automate creating a file (say
testlist) on the fly that will contain the list of all our unit tests specified
using the CTest ADD_TEST command. My thought was to use INCLUDE(testlist) to
read in the list of tests at the appropriate point in the CMakeLists.txt
file(i.e, just after calling ENABLE_TESTING().<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u5:p> </u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>I have a shell (bash) script (addtestscrpt) that
needs to run the unit tests executable to get the list of all unit tests and
then put ADD_TEST for each of those tests into a file which would look like
this:<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u5:p> </u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>ADD_TEST(DDSCfgTest.ctr
${EXECUTABLE_OUTPUT_PATH}/${BIN_NAME} --gtest_filter=DDSCfgTest.ctr)<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>ADD_TEST(DDSCfgTest.ReadBool
${EXECUTABLE_OUTPUT_PATH}/${BIN_NAME} --gtest_filter=DDSCfgTest.ReadBool)<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>ADD_TEST(DDSCfgTest.ReadInt
${EXECUTABLE_OUTPUT_PATH}/${BIN_NAME} --gtest_filter=DDSCfgTest.ReadInt)<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u5:p> </u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>The problem that I'm having is that I need the unit
tests executable to generate the list of all tests and then INCLUDE the list in
a CMakeList.txt file after the unit tests executable is built. <u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u5:p> </u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>I tried using ADD_CUSTOM_COMMAND with POST_BUILD to
run my shell script (COMMAND ./addtestscript) which runs and creates the list
of ADD_TEST() commands and puts them in a file. But I don't know how to include
this file in the ADD_CUSTOM_COMMAND<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u5:p> </u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>The closest I got was:<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u5:p> </u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face="Courier New ;"><span
style='font-size:10.0pt;font-family:"Courier New \;"'>ADD_CUSTOM_COMMAND(TARGET
${BIN_NAME}<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face="Courier New ;"><span
style='font-size:10.0pt;font-family:"Courier New \;"'>
POST_BUILD<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face="Courier New ;"><span
style='font-size:10.0pt;font-family:"Courier New \;"'>
WORKING_DIRECTORY ${SRC_DIR}<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face="Courier New ;"><span
style='font-size:10.0pt;font-family:"Courier New \;"'>
COMMAND bash ./addtestscrpt<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face="Courier New ;"><span
style='font-size:10.0pt;font-family:"Courier New \;"'>
COMMAND ${CMAKE_COMMAND} ${SRC_DIR}/DDSCommonTests/CMakeLists.txt<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face="Courier New ;"><span
style='font-size:10.0pt;font-family:"Courier New \;"'>)<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>where </span></font><font size=2 face="Courier New"><span
style='font-size:10.0pt;font-family:"Courier New"'>${SRC_DIR}/DDSCommonTests/CMakeLists.txt<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face="Courier New ;"><span
style='font-size:10.0pt;font-family:"Courier New \;"'>contains<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face="Courier New ;"><span
style='font-size:10.0pt;font-family:"Courier New \;"'>ENABLE_TESTING()</span></font><o:p></o:p></p>
<u5:p></u5:p>
<p class=MsoNormal><font size=2 color=black face="Courier New ;"><span
style='font-size:10.0pt;font-family:"Courier New \;"'>INCLUDE(${SRC_DIR)/testlist)<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u5:p> </u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>but this doesn’t work presumably because CTest
needs to know about the CTestTestfile.cmake in this directory, again in the
post_build step.<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u5:p> </u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>Is there any way to a) Add the INCLUDE(testlist) to
the ADD_CUSTOM_COMMAND or b) tell CTest to read the CTestTestfile.cmake from
that directory or c) Any other way of solving this?<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u5:p> </u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'>Thanks.<u5:p></u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u5:p> </u5:p></span></font><o:p></o:p></p>
<p class=MsoNormal><font size=2 color=black face=Arial><span style='font-size:
10.0pt;font-family:Arial'><u5:p> </u5:p></span></font><o:p></o:p></p>
<pre wrap=""><font size=2 color=black face="Courier New"><span
style='font-size:10.0pt'><o:p> </o:p></span></font></pre><pre><fieldset class="mimeAttachmentHeader"></fieldset><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p> </o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>_______________________________________________<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Powered by <a
href="http://www.kitware.com">www.kitware.com</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p> </o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Visit other Kitware open-source projects at <a
href="http://www.kitware.com/opensource/opensource.html">http://www.kitware.com/opensource/opensource.html</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p> </o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Please keep messages on-topic and check the CMake FAQ at: <a
href="http://www.cmake.org/Wiki/CMake_FAQ">http://www.cmake.org/Wiki/CMake_FAQ</a><o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><o:p> </o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'>Follow this link to subscribe/unsubscribe:<o:p></o:p></span></font></pre><pre><font
size=2 color=black face="Courier New"><span style='font-size:10.0pt'><a
href="http://www.cmake.org/mailman/listinfo/cmake">http://www.cmake.org/mailman/listinfo/cmake</a><o:p></o:p></span></font></pre></div>
</body>
</html>