I'm using CMake to build my application and CUnit to test it. And I was wondering if there is a way to avoid including the production source files directly from the test code by name (#include ../src/foo.c strikes me as awfully ad-hoc).

I have heard of collecting the production code into a library and adding it to the CMake project, and then linking that against your production and test code. But this approach doesn't sit well with me because it makes my CMake setup that much less straightforward. So I was wondering if there is A Better Way™

  • I've never used cmake for a production project, but I don't understand why it would be difficult to set up a library and both a program and the tests using that library. From what I can see reading the documentation, it would just require two extra lines for your main program, plus two lines for your unit tests. Why is this such a problem? – Jules Jul 22 '17 at 7:17
  • @Jules Could you post relevant documentation/examples as an answer? Assuming that OP has read the same thing you have and also assuming that they have rejected it is not helpful. – l0b0 Jul 22 '17 at 9:04

Like Jules says, its normal to dynamically link to your compiled code rather than statically link to your source.

my c is a bit rusty, but I think that means using LoadLibrary rather than #include.

You still need a filename, but the file is in the test code rather than your app code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.