CMake: COPY_PLUGIN_AFTER_BUILD fails because of wrong path

When enabling COPY_PLUGIN_AFTER_BUILD TRUE on a CMake plugin JUCE target, building fails with:

CMake Error at _deps/juce-src/extras/Build/CMake/copyDir.cmake:24 (file):
  file INSTALL cannot find
  "/Users/username/dev/plugin/cmake-build-debug/Plugin_artefacts/Debug/AAX/Plugin.aaxplugin":
  No such file or directory.

And CMake is right because the products get placed in "/Users/username/dev/plugin/cmake-build-debug/lib

So it looks like the toplevel CMake and the JUCE CMake don’t agree on the CMAKE_BINARY_DIR

In this case I’m showing CLion output, but the same behaviour happens when using cmake from the command line.

JUCE version is 6.0.4

Note to self and potential others who run into this:

The problem was caused by including cmake-conan before creating the JUCE CMake targets. Apparently cmake-conan changes the binary output directories.

Conan CMake has a configuration facility to prevent the output directory from being changed: