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:
- build files in
projectFolder/ext/gtest
with cmake and ninja - 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