forked from mattsta/cmake-cpu-detect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Automatic CMake CPU Feature Detection | ||
===================================== | ||
|
||
## Usage | ||
|
||
Copy `CPUFeatureDetect.cmake` to your project directory. | ||
|
||
Add to your `CMakeLists.txt`: | ||
|
||
```haskell | ||
include(${PROJECT_SOURCE_DIR}/CPUFeatureDetect.cmake) | ||
``` | ||
|
||
Call `genCPUFeatures(namespace)` to generate variables describing the current build environment's CPU capabilities. | ||
|
||
```haskell | ||
genCPUFeatures(MyProject) | ||
if(MyProject_FEATURE_AVX2) | ||
message(STATUS "[MyProject] Building with AVX2...") | ||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2") | ||
else() | ||
message(STATUS "[MyProject] AVX2 not found!") | ||
endif() | ||
``` | ||
|
||
## How It Works | ||
|
||
We parse the llvm compiler CPU feature list (see `./generateCPUDetailsToFeatures.py`) | ||
for all possible CPU features to generate `CPUFeatureDetect.cmake`, then when you run the | ||
`genCPUFeatures()` CMake function, we call potentially dozens of `check_c_source_compiles()` checks | ||
against all the compile feature flags to determine which CPU features are available given | ||
your current `CFLAGS` configuration. | ||
|
||
If you don't have `-march=` specified or you request `-march=native`, | ||
we run all the CPU check test programs to determine your capability. If you do specify a `-march=` | ||
option, we use the CPU architecture name to determine which feature are available _without_ running | ||
any test programs (for cross compiling, etc). |