It seems that ExternalProject_Add
doesn't like a binary directory inside the source one. From the ExternalProject documentation:
Note: If a download method is specified, any existing contents of the source directory may be deleted. Only the URL download method checks whether this directory is either missing or empty before initiating the download, stopping with an error if it is not empty. All other download methods silently discard any previous contents of the source directory.
Fortunatly, for the most projects a binary directory actually does not need to be inside the source one: the projects' READMEs give <src>/build
directory as just an example of build directory.
For binary directory outside of the source one, ExternalProject_Add
creates binary directory automatically.
One just need to make sure that BINARY_DIR
option comes before any option which depends on that directory setting:
ExternalProject_Add(my_ext_project
GIT_REPOSITORY repo...
SOURCE_DIR "project_src"
# Setting BINARY_DIR should come **before** CONFIGURE_COMMAND and BUILD_COMMAND
BINARY_DIR "project_bin"
# It is a way to refer to source directory in the ExternalProject_Add COMMAND.
CONFIGURE_COMMAND cmake <SOURCE_DIR>
BUILD_COMMAND make
)
Note, that such CONFIGURE and BUILD commands are default for ExternalProject_Add
, so you may omit them:
ExternalProject_Add(my_ext_project
GIT_REPOSITORY repo...
SOURCE_DIR "project_src"
BINARY_DIR "project_bin"
# "Standard" CMake project doesn't require to specify any COMMAND.
)