[CMake] Recursively include target include directories only

Robert Dailey rcdailey.lists at gmail.com
Thu Jun 18 11:50:40 EDT 2015


On Thu, Jun 18, 2015 at 1:57 AM, Dan Liew <dan at su-root.co.uk> wrote:
>> The reason I'm asking this question is because of how I handle unit
>> tests in CMake right now. Instead of just defining an executable
>> target for the test and then adding a link dependency on the library
>> containing the class or set of classes to be tested, I am manually
>> pulling in the CPP and H file into the test target and building them
>> inline with the test code. This is to support mocking (I can't mock
>> objects already compiled into a static library). As such, I need the
>> transitive includes and defines, but I do not want the transitive link
>> libraries.
>
> Okay with that context what I suggested isn't going to completely
> solve the problem.
>
> It is actually possible to link with your static library and a mock
> implementation by making the symbols that you want mock in the library
> weak. Then when you link the linker will choose the strong (the mock)
> implementation in preference to the weak implementation. It probably
> isn't desirable to have weak symbols in a shipping library just to
> make unit testing easier so you could build two versions of the
> library (one with weak symbols and one without).
> This would allow to use target_link_libraries() but not get link
> conflicts between your mock implementation and the real
> implementation.
>
> However Petr's suggestion also sounds good (although I haven't tested it).


Can you explain what you mean by "strong" and "weak" symbols?


More information about the CMake mailing list