简体   繁体   中英

Add a cross-compile target to existing CMake project without using ExternalProject_Add

Ok, so I have an existing project that compiles code, creates executables, and everything works great (on both Linux and Windows).

Now... I want to add another executable to my project, but the difference is, I want to cross-compile that executable. We are using Clang for everything, so we can pass a --target as a compiler flag for this new target, and it works (ie, the code compiles for the target that I want).

The problem is with the linker. When I am on Windows, things get ugly because the target is x86_64-elf, and so obviously link.exe cannot use that. If we pass in -fuse-ld=lld, it is ignored as CMake already sets this to link.exe. CMake is also adding a bunch of Windows specific junk like libraries, and there doesn't seem to be a way to turn this stuff off.

Is there a way to add a target and give it s specific toolchain, or something like that with CMake without having to use ExternalProject_Add to support cross compiling a specific target. This is how we did it before, and it works great, but there are a lot of disadvantages to this approach. Figured I would ask.

You should consider using ninja as a build system in conjunction with cmake and clang. This might help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM