0

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 WayTM

asked Jul 22, 2017 at 6:03
2
  • 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? Commented Jul 22, 2017 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. Commented Jul 22, 2017 at 9:04

1 Answer 1

0

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

answered Jul 24, 2017 at 12:17

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.