<html><head></head><body><div>On Tue, 2018-12-18 at 06:14 -0500, frodak17 wrote:</div><blockquote type="cite"><div dir="ltr"><div dir="ltr">What first cross my mind with '"utilities" needed for build' is when you have to build the cross-compiler in the first place before you build anything for the target.<br>If so how do you handle verification of the tool-chain can build a working executable or library?<br>Normally that is done at the time before project files are generated but it has to either be skipped or delayed because the toolchain doesn't even exist because it has to be built first by the host tools. For tool-chains that already exist on the host machine then add_toolchain() command is when you can test and verify its functionality?<br></div></div></blockquote><div><br></div><div>Yes, add_toolchain() would do all the same checks that happen on the "main" toolchain when CMake starts up. The process would be:</div><div><br></div><div>1) add_toolchain() gets called with a FILE argument</div><div>2) the file gets loaded the same way CMAKE_TOOLCHAIN_FILE does on startup</div><div>3) CMake performs all the same checks that it did with the "main" toolchain</div><div>4) add_toolchain() returns and script execution resumes</div><div><br></div><div>So you could build the cross toolchain during configure-time and then add it with add_toolchain(). However, I would recommend having the toolchain build and the actual project be separate CMake projects in order to maintain separation of responsibilities. At the very least, I'd recommend that the cross-compiled project be a subdirectory of the superbuild via add_subdirectory(), and the toolchain would be built in the top directory.</div><div><br></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div>Do these targets automatically get separate binary directories so that the outputs don't overwrite each other?</div></div></div></blockquote><div><br></div><div>No. In this feature, each target would get one toolchain, and *only* one toolchain. If you want to build the same target with multiple toolchains, you would build them as separate targets. Example:</div><div><br></div><div>add_executable(foo-arm foo.c bar.c TOOLCHAIN ArmToolchain)</div><div>add_executable(foo-x86_64 foo.c bar.c TOOLCHAIN x86_64Toolchain)</div><div><br></div><div>This could of course be abstracted away with a function():</div><div><br></div><div>function(make_foo toolchain)</div><div>  add_executable(foo-${toolchain} foo.c bar.c TOOLCHAIN ${toolchain})</div><div>endfunction()</div><div><br></div><div>make_foo(arm)</div><div>make_foo(x86_64)</div><div><br></div><div>My reasoning for this is that each .c/.cxx file has to be built multiple times (once for each toolchain) anyway, so why bother trying to make them part of the same target? Just make them separate targets.</div><div><b></b></div><blockquote type="cite"><div dir="ltr"><div dir="ltr"><div><div>I assume this feature is limited only to ninja or makefile generators?</div></div></div></div></blockquote><div><br></div><div>If Visual Studio and/or Xcode support multiple toolchains (I don't know if they do) then it could work for them too. If not then they would unfortunately be out of luck for multi-toolchain projects.</div><div><br></div><div>Kyle</div></body></html>