[CMake] How can I export source code that needs to be built by downstream projects?

Miller Henry MillerHenry at JohnDeere.com
Wed Dec 16 11:26:02 EST 2015


I'm using cmake to build a set of libraries that then gets packaged and shipped to other groups that are also using cmake to use the library.  Since I use google mock to mock my libraries, and the downstreams also want to mock my library I just provide the mock header for their use.  This works, but there are some quirks of google mock that make it not work well.

It turns out the it takes a significant amount of time to build the constructor and destructor for a mock class.  So we have moved those to a separate .cpp file that is compiled and exported into another library to link against.
      INSTALL(FILES MyMock.h DESTINATION include/)
      INSTALL(TARGETS ${PROJECT_NAME} EXPORT my-target LIBRARY DESTINATION lib COMPONENT ${MY_COMPONENT})

Now I'm looking at upgrading the version of google mock I compile against, but I cannot force my down streams to upgrade (I expect that they will, but politically I cannot force it).   The new version is not binary compatible with the old version, even though the headers are source compatible.

What I want to do is
      INSTALL(FILES MyMock.h DESTINATION include/)
      INSTALL(FILES MyMock.cpp DESTINATION src/)
      INSTALL(TARGETS MyLibraryMock EXPORT my-target SOURCE_LIBRARY DESTINATION src COMPONENT ${MY_COMPONENT})
Then when the downstreams have
      TARGET_LINK_LIBRARIES(THEIR_PROJECT MyLibraryMock)
Cmake knows to build MyLibraryMock, but if they don't link to the mock (I none of their tests use it) don't build it.

Does anyone have any idea on how I might be able to achieve that?



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20151216/7162c64e/attachment.html>


More information about the CMake mailing list