<div class="gmail_quote">On Sat, May 30, 2009 at 4:48 PM, Sean Chittenden <span dir="ltr"><<a href="mailto:sean@chittenden.org">sean@chittenden.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Is set_property(TEST foo_bar_test SOURCE foo_bar.c APPEND PROPERTY COMPILE_FLAGS "-DTESTING") an an inclusive AND of the test requirements (for property to be set we must be building the TEST foo_bar_test *and* the SOURCE foo_bar.c) or is it an OR (for property to be set we must be building either TEST foo_bar_test *or* the SOURCE foo_bar.c). I can't use set_source_file_property() because there isn't a scope qualifier and I've got my own main() functions elsewhere. :)<br>
<br>
I'm not familiar with set_property(TEST foo_bar_test SOURCE foo_bar.c APPEND PROPERTY COMPILE_FLAGS "-DTESTING")<br>
<br>
Have you considered just putting an<br>
<br>
#ifndef TESTING<br>
int main()<br>
{<br>
...<br>
}<br>
#endif<br>
<br>
around foo.c. Or simply refactoring the code so whatever code that's in foo.c that foo_bar_test needs just goes into a separate source file. That way foo.c and foo_bar.c each have only a main() function in them?<br>
</blockquote>
<br></div>
Well, right now I've gone the `patch -p0 < ...` route, but it's less than elegant. *grin*<br>
<br>
<br>
The issue is it's not my code, but it is my build infrastructure. Here's a mostly complete example that shows what the situation is and what I'd like to see happen:<br>
<br>
// BEGIN foo.h<br>
int foo(int a);<br>
// END foo.h<br>
<br>
// BEGIN foo.c<br>
#include "foo.h"<br>
int foo(int a) { return a + 1; }<br>
<br>
#ifdef TESTING<br>
int main(void) { assert(foo(1) == 2); return 0; }<br>
#endif<br>
// END foo.c<br>
<br>
// BEGIN bar.c<br>
#include "foo.h"<br>
int bar(int b) { return foo(1) + 1; }<br>
<br>
#ifdef TESTING<br>
int main(void) { assert(bar(1) == 2); return 0; }<br>
#endif<br>
<br>
<br>
<br>
// CMakeLists.txt<div class="im"><br>
add_executable(foo_test foo.c)<br>
add_test(foo_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/foo_test)<br>
set_property(TARGET foo_test APPEND PROPERTY COMPILE_FLAGS "-DTESTING")<br>
<br></div>
add_executable(bar_test foo.c bar.c)<br>
add_test(bar_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/bar_test)<br>
set_property(TARGET bar_test APPEND PROPERTY COMPILE_FLAGS "-DTESTING")<br>
<br>
// Elsewhere I use:<br>
add_executable(my_app my_app.c foo.c bar.c)<br>
<br>
<br>
Ideally I'd like to see cmake(1) be able to issue the following commands:<br>
<br>
// Create foo_test<br>
gcc -o foo.o -c foo.c -DTESTING<br>
gcc -o foo_test foo.o<br>
<br>
// Create bar_test<br>
gcc -o foo.o -c foo.c<br>
gcc -o bar.o -c bar.c -DTESTING<br>
gcc -o bar_test foo.o bar.o<br>
<br>
<br>
That help clarify? set_target_property() still defines TESTING for both foo.c and bar.c and the bar_test case would break. Ideally I'd like to set a source property in the bar_test case, but don't know how to do that. I thought the scope property would do it. Can I somehow finagle this using an if() ?</blockquote>
<div><br>Not that I know of.<br><br>How about<br>set_property(TARGET foo_test APPEND PROPERTY COMPILE_FLAGS "-DTESTING_FOO")<br>set_property(TARGET bar_test APPEND PROPERTY COMPILE_FLAGS "-DTESTING_BAR")<br>
</div></div><br><br>-- <br>Philip Lowman<br>