3

I'm using an open source library that comes with gtest in my own project. Since I am using gmock for my own library there seems to be problems with compiling gmock when including gtest from the other open source library.

Is there a way to not include a child directory from that library?

In the open source library's include directory there are two folders:

include/
  gtest   MRT

I only want to include the folder "MRT" (If I use include_directories { path_to_os_lib/include/MRT } compilation will fail because the library internally uses include statements like "#include "MRT/foo/bar.hpp" ")

Stefan Weiser
  • 2,264
  • 16
  • 25
user1443778
  • 581
  • 1
  • 5
  • 20
  • 1
    how about this: http://stackoverflow.com/questions/17894736/how-to-enable-cmake-to-exclude-a-subdirectory-from-install – rahman Aug 06 '14 at 10:13
  • @rahman: This linked question about preventing a subdirectory from being installed. This user wants to know, how to prevent gtest from interfering with his own gtest directory. – Stefan Weiser Aug 06 '14 at 10:43

1 Answers1

3

You could "install" (simply copy) the MRT directory into another part of the repo and add this to the INCLUDE_DIRECTORIES. Assuming you have the MRT repo in a subdirectory subrepo:

MESSAGE("Copying MRT directory...")
EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/subrepo/MRT" "${CMAKE_CURRENT_SOURCE_DIR}/include/MRT")
INCLUDE_DIRECTORIES(SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/include")

Don't use any shell/batch commands, because they are not portable. For this cmake supports by -E a number of commands.

Stefan Weiser
  • 2,264
  • 16
  • 25
  • Also, you should prefer the more robust [`CMAKE_COMMAND`](http://www.cmake.org/cmake/help/v3.0/variable/CMAKE_COMMAND.html) variable instead of the hardcoded `cmake` for the execute command. – ComicSansMS Aug 06 '14 at 11:07
  • Thx. I would also shorten the directories involved into that copy construct. – Stefan Weiser Aug 06 '14 at 11:33