-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add CPU detection * Tweak script * Remove unused vars
- Loading branch information
Showing
2 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
set(CPU_VENDOR) | ||
set(CPU_FAMILY) | ||
set(CPU_MODEL) | ||
set(CPU_PROPS) | ||
|
||
file(READ "/proc/cpuinfo" _cpuinfo) | ||
string(REGEX REPLACE ".*vendor_id[ \t]*:[ \t]+([a-zA-Z0-9_-]+).*" "\\1" | ||
CPU_VENDOR "${_cpuinfo}") | ||
string(REGEX REPLACE ".*cpu family[ \t]*:[ \t]+([a-zA-Z0-9_-]+).*" "\\1" | ||
CPU_FAMILY "${_cpuinfo}") | ||
string(REGEX REPLACE ".*model[ \t]*:[ \t]+([a-zA-Z0-9_-]+).*" "\\1" | ||
CPU_MODEL "${_cpuinfo}") | ||
string(REGEX REPLACE ".*flags[ \t]*:[ \t]+([^\n]+).*" "\\1" | ||
CPU_PROPS "${_cpuinfo}") | ||
|
||
message("Found CPU: Vendor = ${CPU_VENDOR} Family = ${CPU_FAMILY} Model = ${CPU_MODEL} Props = ${CPU_PROPS}") | ||
|
||
# See this file for an example of extending this list: | ||
# https://github.com/VcDevel/Vc/blob/1.4/cmake/OptimizeForArchitecture.cmake | ||
# See the LLVM source for list of supported arch, e.g. this test: | ||
# https://github.com/llvm/llvm-project/blob/main/clang/test/Driver/x86-march.c | ||
|
||
set(CPU_COMPILE_FLAGS) | ||
if(CPU_VENDOR STREQUAL "GenuineIntel") | ||
if(CPU_FAMILY EQUAL 6) | ||
if(CPU_MODEL EQUAL 78 OR CPU_MODEL EQUAL 94) | ||
# Skylake | ||
set(CPU_COMPILE_FLAGS -march=skylake -mtune=skylake) | ||
elseif(CPU_MODEL EQUAL 58 OR CPU_MODEL EQUAL 62) | ||
# Ivy bridge | ||
set(CPU_COMPILE_FLAGS -march=ivybridge -mtune=ivybridge) | ||
endif() | ||
endif() | ||
endif() | ||
|
||
if(CPU_COMPILE_FLAGS) | ||
message("Setting following CPU-specific compile flags: ${CPU_COMPILE_FLAGS}") | ||
add_compile_options(${CPU_COMPILE_FLAGS}) | ||
else() | ||
message("Could not provide any CPU-specific compile flags") | ||
endif() |