CMake CPU detect
These CMake functions detect the CPU arch for Intel CPUs on Linux, MacOS and Windows.
We focused on Intel CPUs since the Intel compilers (including Intel oneAPI) don't currently have automatic CPU detection.
To use -march=
features of Intel compilers, -march=native
is undocumented and does not actually detect the CPU arch.
For CMake with Intel compilers these functions help yield better runtime performance by enabling the features of the Host CPU.
The same technique could be used for AMD, ARM, CUDA, etc. in the future.
Result variables
The variable HOST_ARCH
is set in the parent scope.
HOST_ARCH
is empty if CPU arch is not known.
Demo
cmake -B build
will print the CPU family e.g. "icelake-client".