3

This is my current directory structure:

projectFolder/CMakeLists.txt
projectFolder/src       /* holds all project .cpp files */
projectFolder/include   /* holds all header files*/
projectFolder/test      /* holds all test .cpp files*/
projectFolder/ext/gtest /* holds all files associated with googletest, 
                           including it's CMakeLists.txt file */

What currently works is:

  1. build files in projectFolder/ext/gtest with cmake and ninja
  2. build files in projectFolder with cmake and ninja

The disatvantage is that googletest is in a subdirectory of my project, which means I would have to duplicate its source files for every project

What I would like to do is remove the source files of googletest from the project directory tree and move it to a 3rdParty folder. I then want to be able to compile google test whenever I use cmake and ninja from inside a projects build folder, effectively creating separate binaries for each project I have, without having to have the source files in the project's diretory tree (binaries would be created new in a sub-directory of the project's build folder.)

When I move the gtest out of the project folder, I get the following error:

When specifying an out-of-tree source a binary directory 
must be explicitly specified.

When I specify a binary directory with add_subdirectory(${EXT_PROJECTS_DIR}/gtest ${CMAKE_CURRENT_BINARY_DIR}/gtest) I get

ninja: error: 
    'gtest/src/googletest-build/libgtest.a', needed by 
    'google-test-examples_test', missing and no known rule to make it

I have tried to link googletest with find_package, but cmake doesn't find googletest. Also, I am not sure that when I use find_package the binaries get recompiled for each project, could someone verify or refute this?

I am on a Mac running lion

DudeOnRock
  • 3,685
  • 3
  • 27
  • 58
  • 1
    I haven't tested [this answer](http://stackoverflow.com/a/9695234/2556117) on a Mac, but you could look at using `ExternalProject_Add` to just pull the gtest sources down to your build tree every time. – Fraser Sep 10 '13 at 19:50
  • Since I haven't found anything that is more straight-forward, I am intrigued, I'll give that a shot. – DudeOnRock Sep 10 '13 at 19:56
  • 1
    If your only concern is to stop duplicating google-test sources why don't use symlink? It seems that Mac supports them. Then you can just `add_subdirectory` as you probably do now. – zaquest Sep 10 '13 at 19:58
  • @Fraser: when compiling with ninja I get `ThirdParty does not contain a CMakeLists.txt file.` Cmake creates some folders, but never starts to actually pull the sources. – DudeOnRock Sep 10 '13 at 20:11
  • @zaquest: I am hesitant to just symlink googletest, since all the sites I have scoured are full of warnings that each project should compile googletest itself (possibly different compiler flags and other issues that are a nightmare to debug) – DudeOnRock Sep 10 '13 at 20:14
  • @DudeOnRock Sorry - I don't have access to a Mac. I've just tested on Ubuntu with Clang and GCC and it works (after a few modifications), but that probably isn't much help to you. – Fraser Sep 10 '13 at 21:38

0 Answers0