I'm building an installer/downloader that detects the architecture and downloads the version of the main executable compiled with that architecture. If it doesn't exist yet, it'll be compiled on the server on the fly.
I can easily get the CPU name, e.g. "Intel(R) Core(TM) i9-10900KF CPU @ 3.70GHz", but how do I convert this to the correct string for the -march and -mtune settings for MinGW?
I cannot rely on any dependencies, it need to be able to determine this using a standalone script or executable that can be run by the installer to determine the correct string. Or I could use a massive list of all CPU names converted to -march strings, but where would I find that?
EDIT: I cannot use -march=native because the compiler is not on the client machine. What I'm doing is detecting the architecture on the client machine by an installer, then compiling for their architecture on the server. So I cannot use -march=native.
If you can distribute MinGW's gcc.exe
compiler driver (just that small file and the libraries it depends on, without the multi-megabyte language front-ends cc1.exe
, cc1plus.exe
, etc) then you can run it on the client machine with the -###
option like this:
gcc.exe -### -xc - -E -march=native
and take the various -m
and --param
options from the cc1.exe
line in the output.
To learn how -march=native
works, have a look at driver-i386.cc and common/config/i386 in GCC source code. If you copy from there, I'd suggest to make the result a standalone tool that you can distribute under the GPL, respecting the original licensing of those files.