[CMake] Boost.Test, cmake, and visual studio

Iain Hull Iain.Hull at cr2.com
Fri Aug 31 13:22:58 EDT 2007


Hi Steve,

I currently use Boost.Test, cmake and visual studio.

I have added a macro to define unit test.  I cannot remember if I found
this on the web or wrote it myself, chances are I found it on this list.
It is a long time ago so I cannot quite remember what the perpose of the
string replacement is.

In a top level CMakeLists.txt:
===============================
##
## AddUnitTest - Register specified project as a unit test
##
##   project        - the name of the project to register
##
MACRO( AddUnitTest project )
	GET_TARGET_PROPERTY( testExecutable ${project} LOCATION )

	STRING(REGEX REPLACE "\\$\\(.*\\)"
"\${CTEST_CONFIGURATION_TYPE}"
			testExecutable "${testExecutable}")
	ADD_TEST( ${project} ${testExecutable} )
ENDMACRO( AddUnitTest )


# .....

ENABLE_TESTING()


============================

Then in test directory

============================
PROJECT( test )

SET( testSrc ... )

ADD_EXECUTABLE( test ${testSrc} )

AddUnitTest( testSrc )

=================================



I hope this is useful,

Iain.



-----Original Message-----
From: cmake-bounces+iain.hull=cr2.com at cmake.org
[mailto:cmake-bounces+iain.hull=cr2.com at cmake.org] On Behalf Of Steve M.
Robbins
Sent: 30 August 2007 22:59
To: cmake at cmake.org
Subject: Re: [CMake] Boost.Test, cmake, and visual studio

Hi again,

I found the answer to my problem in the CMake FAQ.  Hurray!


On Wed, Aug 29, 2007 at 09:19:51AM -0500, Steve M. Robbins wrote:

> Reluctantly, I gave up and went back to ADD_CUSTOM_TARGET.  The 
> following gives me exactly what I want:

  [...]

The clue I needed was GET_TARGET_PROPERTY.  The following does just what
I want, including the dependency.


ADD_EXECUTABLE( testSuite ${testSuite_SRCS} )

GET_TARGET_PROPERTY( testSuite_EXE testSuite LOCATION )

ADD_CUSTOM_TARGET( RUN_TESTS
  ${testSuite_EXE} --report_level=no
  DEPENDS testSuite
)

Cheers,
-Steve


More information about the CMake mailing list