Skip to content

Commit 4f46903

Browse files
committed
add CMake flag USE_NATIVE_CPU_ARCH for -march=native
1 parent ca28558 commit 4f46903

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set_property(CACHE BUILD_OPENGL PROPERTY STRINGS AUTO ON OFF)
88
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
99
option(CMAKE_CUDA_ARCHITECTURES "CUDA architectures to build for (needs CMake 3.18)" OFF)
1010
option(ENABLE_FPNGE "Enable fpnge - requires c++ and sse4" OFF)
11+
option(USE_NATIVE_CPU_ARCH "Use -march=native for compilation (Linux only)" OFF)
1112
option(HUFFMAN_GPU_CONST_TABLES "Enable Huffman GPU decoder quick const tables" OFF)
1213
set(OPENGL_CONTEXT AUTO CACHE STRING "Use specifiedn OpenGL context creation, options are: AUTO GLX GLFW NONE")
1314
set_property(CACHE OPENGL_CONTEXT PROPERTY STRINGS AUTO GLX GLFW NONE)
@@ -78,6 +79,12 @@ if(ENABLE_FPNGE)
7879
file(GLOB_RECURSE CXX_FILES src/*.cc src/*.cpp)
7980
endif()
8081
82+
if(USE_NATIVE_CPU_ARCH)
83+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
84+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
85+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler -march=native")
86+
endif()
87+
8188
# allow passing <PackageName>_ROOT to find_package()
8289
if(POLICY CMP0074)
8390
cmake_policy(SET CMP0074 NEW)

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,9 @@ files are placed) and run `cmake` command:
191191
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_CUDA_ARCHITECTURES=native -Bbuild .
192192
cmake --build build --config Release
193193

194+
In Linux, you may also consider `-DUSE_NATIVE_CPU_ARCH=ON` for optimized
195+
CPU code build (`-march=native` added to compiler flags).
196+
194197
In Linux, you can also use **autotools** to create a build recipe for
195198
the library and the application or a plain old _Makefile.bkp_. However,
196199
_cmake_ is recommended.

0 commit comments

Comments
 (0)