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()
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With