[CMake] set_property() scope qualifier question...

Sean Chittenden sean at chittenden.org
Sat May 30 12:23:55 EDT 2009


Hello.

I'm incorporating an external library in to our source tree and would  
like to run the external library's regression tests.  The library is  
C, however, and the convention for doing this is:

/* Lib contents above */
#ifdef TESTING
int main(int argc, char* argv[]) {
   /* Do tests
}
#endif

Where I'm having my problem is in layering two source files like this  
that are interdependent.  In the following example, both foo.c and  
foo_bar.c have #ifdef TESTING sections.  In CMakeLists.txt, I have  
something like:

add_executable(foo_test foo.c)
add_test(foo_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/foo_test)
set_property(TARGET foo_test APPEND PROPERTY COMPILE_FLAGS "-DTESTING")

add_executable(foo_bar_test foo_bar.c foo.c)
add_test(foo_bar_test ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/foo_bar_test)
set_property(TARGET foo_bar_test APPEND PROPERTY COMPILE_FLAGS "- 
DTESTING")


Which obviously doesn't work when building foo_bar_test because there  
are two main() functions now (foo_test works just fine).  I've tried  
various SCOPE qualifiers such as SOURCE, TARGET and TEST with no  
luck.  Having read the docs a few dozen times, the behavior of SCOPE  
for set_property is vague.

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.  :)

I'm very biased towards the inclusive AND for set_property().


That said, is there an alternative approach that's more correct?  -sc

--
Sean Chittenden
sean at chittenden.org





More information about the CMake mailing list