[CMake] ctest and cppunit
Brad King
brad.king at kitware.com
Thu Jan 26 13:10:28 EST 2006
Mike Talbot wrote:
> Hello,
>
> I am trying to use cmake and ctest to run unit tests using cppunit. The
> unit tests are built as shared libraries and then passed to the cppunit
> test harness (DllPlugInTesterd_dll.exe) to run them. My CMakeLists.txt
> looks like this:
>
> ADD_LIBRARY(MyUnitTest SHARED MyUnitTest.cpp)
> TARGET_LINK_LIBRARIES(MyUnitTest ${CPPUNIT_LIBRARY})
>
> GET_TARGET_PROPERTY(MyUnitTestTarget MyUnitTest LOCATION)
> ADD_TEST(MyUnitTest DllPlugInTesterd_dll.exe ${MyUnitTestTarget})
>
> Unfortunately, when I use the Visual Studio 7 generator, cmake fails
> because ${MyUnitTestTarget} is expanded (correctly) to
> D:/build/lib/$(OutDir)/MyUnitTest.dll but ctest does not expand
> $(OutDir) to the build config (e.g. "Debug"). Am I missing something or
> is this a bug?
>
> [I am using cmake version 2.2-patch 3 on Windows XP]
The LOCATION property was only intended for use in ADD_CUSTOM_COMMAND
and other things that configure *build*-time stuff.
Creating a test that has a different command line on a per-configuration
basis requires the CTEST_CONFIGURATION_TYPE variable. This is set by
ctest when it is running the tests. Try this for example:
ADD_TEST(mytest echo "testing \${CTEST_CONFIGURATION_TYPE}")
Escaping the $ with a backslash prevents the variable from being
expanded immediately. It then appears in the test command line and is
expanded by ctest when running the test.
The missing feature is the one that gives you the LOCATION property with
a value suitable for use at *test*-time. You can create a feature
request here:
http://www.cmake.org/Bug
but for now you can work around the problem by fixing the path yourself.
For example:
ADD_LIBRARY(MyUnitTest SHARED MyUnitTest.cpp)
TARGET_LINK_LIBRARIES(MyUnitTest ${CPPUNIT_LIBRARY})
GET_TARGET_PROPERTY(MyUnitTestTarget MyUnitTest LOCATION)
STRING(REGEX REPLACE "\\$\\(.*\\)" "\${CTEST_CONFIGURATION_TYPE}"
MyUnitTestTarget "${MyUnitTestTarget}")
ADD_TEST(MyUnitTest DllPlugInTesterd_dll.exe ${MyUnitTestTarget})
This will replace the "$(IntDir)", "$(OutDir)", or "$(CONFIGURATION)"
depending on the generator being used with the test-time variable. In
builds that do not have multiple configuration types the regex will not
match anything and no replacement will be made.
-Brad
More information about the CMake
mailing list