On Thu, Jun 18, 2015 at 1:57 AM, Dan Liew <d...@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?
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to