[CMake] Best way to write add_test that depends on shared objects

Hickel, Kelly Kelly_Hickel at bmc.com
Fri Jun 11 11:09:27 EDT 2010


> -----Original Message-----
> From: Michael Wild [mailto:themiwi at gmail.com]
> Sent: Friday, June 11, 2010 10:06 AM
> To: Hickel, Kelly
> Cc: cmake at cmake.org
> Subject: Re: [CMake] Best way to write add_test that depends on shared
> objects
> 
> 
> On 11. Jun, 2010, at 16:58 , Hickel, Kelly wrote:
> 
> > I'm using CMake 2.8.1 and I want to write a simple test for one of
> the executable targets, but it failes because the shared libraries
> aren't in the directory or on the path.
> >
> > So, with something like the below, where bar and baz are shared
> objects built by CMakeLists.txt files in other directories (building
> foo works just fine, BTW), how can I modify the test so that baz.dll
> and bar.dll are either in the same directory as foo.exe, or on the path
> (that was windows specific, but I want it to work everywhere):
> >
> > add_executable( foo foo.c )
> > target_link_libraries( foo bar baz )
> > add_test( NAME foo-simple COMMAND foo "--simple" )
> >
> > I was going to try setting that PATH environment var for the test,
> but haven't been able to come up with a get_target_property line that
> gets the correct directory where each dll file will be.
> >
> > I suppose I could invoke cmake to copy the binaries, but that doesn't
> seem ideal (and I still have to figure out where to copy from), I'd
> like not to leave extra dll copies lying around....
> >
> > Thanks,
> > Kelly Hickel
> >
> > BMC Software
> 
> 
> Either set CMAKE_RUNTIME_OUTPUT_DIRECTORY or the target property
> RUNTIME_OUTPUT_DIRECTORY to e.g. ${CMAKE_BINARY_DIR}/bin. This will
> cause all the files that are required during runtime to be created in
> the specified directory. For other kinds of files, there are similarly-
> named variables and properties.
> 
> HTH
> 
> Michael

Thanks Michael, but for various reasons, I really don't want all the targets ending up in the same bin directory.  If that's the only way to solve it, then I guess I'll do commands to copy the binaries for a test to a test only directory.

I've tried looking at the target property RUNTIME_OUTPUT_DIRECTORY for the bar and baz targets, but it always somes back as -NOTFOUND, even in the CMakeLists.txts for those targets.  Presumably because I didn't set it in the first place, it just has no value?

-Kelly



More information about the CMake mailing list