ExternalProject_Add_Step only works from the same source directory
In the attached project I simulate the situation when ExternalProject_Add_Step is called from the different source directory. This generates an error:
CMake Error at /usr/share/cmake/Modules/ExternalProject.cmake:2289 (add_custom_command):
Attempt to APPEND to custom command with output
/xxx/build/sub_dir/CMakeFiles/external_proj-complete
which is not already a custom command output.
Call Stack (most recent call first):
sub_dir/CMakeLists.txt:3 (ExternalProject_Add_Step)
This happens because ExternalProject_Add calls add_custom_command and specifies the path to 'external_proj-complete' file in the ${CMAKE_CURRENT_BINARY_DIR}. When ExternalProject_Add_Step is called it tries to APPEND the step stamp file as dependency to the 'external_proj-complete' stamp file. But for sub-directories _ep_get_complete_stampfile returns the path based on sub_dir's '${CMAKE_CURRENT_BINARY_DIR}' which is different from the used when calling ExternalProject_Add. So add_custom_command(APPEND OUTPUT... reports that OUTPUT file doesn't exists.
I worked around this(in Qt) using the EXCLUDE_FROM_MAIN argument, but this works since we build own dependency chain that triggers steps from sub-directories.
If the functionality works as designed it would be nice to have an error explaining the problem, thrown by ExternalProject_Add_Step function.