[CMake] Export a target that must be built in the import environment

Miller Henry MillerHenry at JohnDeere.com
Mon Mar 30 16:10:35 EDT 2015


I develop a shared library that gets imported into a number of applications (scattered across a number of different repositories).  To aid in testing we provide some mocks and fakes, made available by a cmake export files.

This works okay, but it isn't right: google mock doesn't guarantee binary compatibility if compile flags are not exactly the same, and less so if the version is different between our library and the application. There are a couple new features in google mock that I'd like to use, but I cannot upgrade without also upgrading all the users of the library at the same time: this is a difficult task (both technically and politically)

I know I'm going to have to face the technical and political issue, but I'd like to solve this problem completely so I don't hit it again. The solution I'd like to install the .cpp files, and have cmake add those files to the build, but only build the ones that are actually used in the project.  The actually used is somewhat important as building the library for the mocks is fairly expensive.

That is in the main CMakeLists.txt
      Find_package(MyLibrary)
Then in a test someplace
      Target_link_libraries(SomeTest, MyLibraryMock)

I'm stuck though, I can't think of any way to actually implement this.  Can anyone offer some suggestions, or a different way to accomplish this?

The idea of putting the functions inline in the header will not work: we have benchmark data showing that doing this adds significantly to the compile time of the project when doing an incremental build (the TDD cycle becomes too long).



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150330/70c96658/attachment.html>


More information about the CMake mailing list