Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake march hardware

Tags:

What is the CMake way to enable the equivalent of GCC's -march=, particularly -march=native? Is there really nothing better than CHECK_CXX_COMPILER_FLAG, such as:

include(CheckCXXCompilerFlag) CHECK_CXX_COMPILER_FLAG("-march=native" COMPILER_SUPPORTS_MARCH_NATIVE) if(COMPILER_SUPPORTS_MARCH_NATIVE)     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native") endif() 
like image 645
Levi Morrison Avatar asked Oct 13 '17 07:10

Levi Morrison


1 Answers

Yes, this feature test is an appropriate way to apply the argument to CMAKE_CXX_FLAGS.

Perhaps an improvement might be to hide this behind an option, as @LeviMorrison suggests.

option(OPTIMIZE_FOR_NATIVE "Build with -march=native" OFF) 
like image 148
Brian Cain Avatar answered Sep 16 '22 18:09

Brian Cain