CMake Error: “add_subdirectory not given a binary directory”

The error message is clear – you should also specify build directory for googletest.

# This will build googletest under build/ subdirectory in the project's build tree
add_subdirectory( ${GOOGLETEST_PROJECT_LOCATION} build)

When you give relative path (as a source directory) to add_subdirectory call, CMake automatically uses the same relative path for the build directory.

But in case of absolute source path (and when this path isn’t in your source tree), CMake cannot guess build directory, and you need to provide it explicitly:

See also documentation for add_subdirectory command.

Leave a Comment