Skip to content

Commit

Permalink
Add README
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsta committed Jan 10, 2021
1 parent 804b13b commit 5548e03
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions README.md
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).

0 comments on commit 5548e03

Please sign in to comment.