add_custom_target: document behavior when COMMAND is not a usable target
Test case
CMakeLists.txt:
project(add_custom_target_bug)
cmake_minimum_required(VERSION 3.10)
add_executable(target foo.cpp)
add_custom_target(run target DEPENDS target VERBATIM)
foo.cpp:
#include <iostream>
int main()
{
std::cout << "Hello World.\n";
return 0;
}
toolchain-arm-linux.cmake:
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_PROCESSOR arm)
This works
mkdir native
cd native
cmake ..
make VERBOSE=1 run
This fails
mkdir aarch64
cd aarch64
cmake -DCMAKE_TOOLCHAIN_FILE=toolchain-arm-linux.cmake ..
make VERBOSE=1 run
but this works (via binfmt calling qemu):
./target
Instead of calling ./target
as the "native" version did, it calls target
. Since the CWD isn't in the PATH, this can't work.
Discussion
It seems, cmake assumes cross compiled targets to not be executable on the host system. Due to binfmt support this assumption is incorrect. If necessary, the assumption should be trivially testable: Compile int main() {}
and test whether it runs successfully.