[Cmake] multiple compile of an object
Andy Cedilnik
andy.cedilnik at kitware.com
Mon May 19 10:05:10 EDT 2003
Hi Ken,
You can always write a macro that writes a file and creates executable.
For example, let say you have several classes per library. You would do
something like this:
MACRO(CREATE_TEST classname libname)
STRING(ASCII 35 POUND)
WRITE_FILE("${CMAKE_CURRENT_BINARY_DIR}/test_${classname}.cxx"
"${POUND}define ${classname}_MAIN_NEEDED\n${POUND}include
<${CLASSNAME}.h>")
ADD_EXECUTABLE(test_${classname}
"${CMAKE_CURRENT_BINARY_DIR}/test_${classname}.cxx")
TARGET_LINK_LIBRARIES(test_${classname} ${libname})
ENDMACRO(CREATE_TEST)
Sounds good?
Then you just do:
CREATE_TEST(class1 mylib1)
CREATE_TEST(class2 mylib1)
CREATE_TEST(class3 mylib2)
Andy
On Fri, 2003-05-16 at 11:47, Ken Weinert wrote:
> OK, I thought I had this one solved, but it turns out that it isn't
> quite right.
>
> My situation is this:
>
> I frequently write a little test program into my class
> definitions. That is, at the end of the file where all the methods
> have been defined you'll find something like this:
>
> #if defined(<CLASSNAME>_MAIN_NEEDED)
> int main()
> {
> // test code goes here
> }
> #endif
>
> And then I'll compile a small standalone test program and also
> compile the .o to be included in the main program.
>
> Is there a way to automate this in CMake? If so, a pointer to
> where it might be documented (or an idea of how to do it) would be
> appreciated.
More information about the CMake
mailing list