Hi Fraser,
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. http://public.kitware.com/cgibin/viewcvs.cgi/Modules/FindGTest.cmake?rev ision=1.4&root=CMake&view=markup Thanks again! Neelima ________________________________ From: Fraser Hutchison [mailto:fraser.hutchi...@googlemail.com] Sent: Thursday, August 26, 2010 2:28 AM To: Neelima Mehdiratta Cc: cmake@cmake.org Subject: Re: [CMake] CMake and CTest for Google tests Hi Neelima, 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: FOREACH(GTEST_SOURCE_FILE ${GTEST_SOURCE_FILES}) FILE(STRINGS ${GTEST_SOURCE_FILE} GTEST_NAMES REGEX ^TEST) FOREACH(GTEST_NAME ${GTEST_NAMES}) STRING(REGEX REPLACE ["\) \(,"] ";" GTEST_NAME ${GTEST_NAME}) LIST(GET GTEST_NAME 1 GTEST_GROUP_NAME) LIST(GET GTEST_NAME 3 GTEST_NAME) ADD_TEST(${GTEST_GROUP_NAME}.${GTEST_NAME} ${EXECUTABLE_OUTPUT_PATH}/${BIN_NAME} --gtest_filter=${GTEST_GROUP_NAME}.${GTEST_NAME}) ENDFOREACH() ENDFOREACH() 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. Cheers, Fraser. On 25/08/2010 11:17 PM, Neelima Mehdiratta wrote: 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(). 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: ADD_TEST(DDSCfgTest.ctr ${EXECUTABLE_OUTPUT_PATH}/${BIN_NAME} --gtest_filter=DDSCfgTest.ctr) ADD_TEST(DDSCfgTest.ReadBool ${EXECUTABLE_OUTPUT_PATH}/${BIN_NAME} --gtest_filter=DDSCfgTest.ReadBool) ADD_TEST(DDSCfgTest.ReadInt ${EXECUTABLE_OUTPUT_PATH}/${BIN_NAME} --gtest_filter=DDSCfgTest.ReadInt) 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. 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 The closest I got was: ADD_CUSTOM_COMMAND(TARGET ${BIN_NAME} POST_BUILD WORKING_DIRECTORY ${SRC_DIR} COMMAND bash ./addtestscrpt COMMAND ${CMAKE_COMMAND} ${SRC_DIR}/DDSCommonTests/CMakeLists.txt ) where ${SRC_DIR}/DDSCommonTests/CMakeLists.txt contains ENABLE_TESTING() INCLUDE(${SRC_DIR)/testlist) but this doesn't work presumably because CTest needs to know about the CTestTestfile.cmake in this directory, again in the post_build step. 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? Thanks. _______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake
_______________________________________________ Powered by www.kitware.com Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Follow this link to subscribe/unsubscribe: http://www.cmake.org/mailman/listinfo/cmake