try_run with Visual C++ Build Tools cause missing ucrtbased.dll
Consider the following CMakeLists.txt
cmake_minimum_required (VERSION 3.1)
project (Foo)
add_executable (Foo main.cpp)
include(CheckCXXSourceRuns)
check_cxx_source_runs( "int main() { return 0; }" ALL_GOOD )
if ( NOT ALL_GOOD )
MESSAGE ( FATAL_ERROR "What." )
endif ()
When using the Visual C++ Build Tools, the check_cxx_source_runs() command fails! You get a dialog saying ucrtbased.dll is missing from my computer. In fact, ucrtbased.dll is not in c:\Windows\System32 or SysWOW64, although it is in c:\Program Files (x86)\Windows Kits\10\bin*\ucrt and also c:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs\Microsoft.UniversalCRT.Debug....
The release version, ucrtbase.dll is in c:\Windows\System32 and SysWOW64, so the code does work in release mode. So at this point you might be thinking "Ok that is what I would expect."
Except! If you remove all the Check... stuff, main.cpp (which also contains "int main() { return 0; }") builds and runs fine. Checking in depends.exe it doesn't depend on ucrtbase.dll or ucrtbased.dll. I haven't been able to look at the binary built by check_cxx_source_runs() because it always immediately deletes everything.
Anyway something is clearly wrong here. If you simply copy the ucrtbased.dll files to c:\Windows\System32 you get the error "The application failed to start correctly." instead.