codeExplorer wrote:since I'm using CMake as a build system,
Well there's your problem. A tool that does not allow you to do what needs to be done is not a tool worth using. Even just POSIX make has no issue with this task whatsoever, so don't hobble yourself with this crutch.
FYI: I just use a shell script to generate a build.ninja file for ninja-build. Another tool that has no issue with using multiple compilers.
codeExplorer wrote:I can also link it without libgcc, and just fix the code whenever it complains (for example, not really using operations between int64_t types in the loader), but that also just doesn't seem ideal.
I am not using libgcc for the simple reason that I am compiling kernel code, and libgcc might not know that. For instance, there are versions of libgcc using vector registers for integer operations. But a kernel cannot do that (using SSE in kernel, when you're building a higher-half kernel, would mean saving FPU on every kernel entry, not just on every context switch). So I write the code in assembler in a way that works for the kernel.
Mind you, my 32-bit code stub works with 64-bit values to set up paging, and I have not yet had to implement any libgcc function.
codeExplorer wrote:I guess the best solution is to indeed have two different compilers, and just use one or the other depending on what you're compiling. Though, for that, I think I'd better go back to good old Make, which I was trying to avoid. Oh well
Expand your horizon, young Padawan. There are more options than make and cmake out there. ninja-build I already mentioned, and the shell script works shockingly well. Also a good way to generate POSIX make files, if that were requested. Or, on the subject of shell scripts, you could just use a build script and always rebuild everything. When you compare the added build time with the removed headaches from dependency tracking, it seems very alluring. I once created such a build script at my day job, just as experiment, and the 500,000 lines of code were compiled in 1 minute. And that was just because of Cygwin. Imagine how fast it would have been on Linux! Don't discount the simple options!