ExternalProject_Add creates wrong folder

In my project’s CMakeLists.txt I’m adding external projects like this:

externalproject_add(xxx GIT_REPOSITORY xxxrepo SOURCE_DIR ../../../3rdParty/xxx/src BUILD_DIR ../../../3rdParty/xxx/build)
externalproject_add(yyy GIT_REPOSITORY yyyrepo SOURCE_DIR ../../../3rdParty/yyy/src BUILD_DIR ../../../3rdParty/yyy/build)

The (out of tree) “3rdParty” folder already exists and has some other content. I would like CMake to add the folders “xxx” and “yyy” to this “3rdParty” folder. However, when I configure my project, what happens is that within the “3rdParty” folder, another “3rdParty” folder is created (perhaps because it already exists?). So the files end up in “…/…/…/3rdParty/3rdParty/xxx/src” and “…/…/…/3rdParty/3rdParty/yyy/src” etc instead of “…/…/…/3rdParty/xxx/src” and “…/…/…/3rdParty/yyy/src”.

I tried to create the folders before calling externalproject_add using file(MAKE_DIRECTORY …), which does work as expected. Now the folders are created correctly, but externalproject_add still creates its own 3rdParty/3Party folder puts everything there.

Am I doing something wrong or is this a bug? I would like to know how to fix it. Thanks in advance!

Edit: I’m running CMake 3.17.1 (cmake-gui) on Windows 10.

My guess is that things like STAMP_DIR and such are still using some other prefix. Are things fixed if you move STAMP_DIR, TMP_DIR, and any others mentioned in the docs?

I recommend using absolute paths in these kinds of things anyways, but I don’t think that’s related to the behavior at hand.

Ok, so I found my -rather stupid- mistake. I was using BUILD_DIR instead of BINARY_DIR in externalproject_add.