Skip to content

Commit

Permalink
Only use -march=native if it's available
Browse files Browse the repository at this point in the history
Not all architecture support this flag, e.g. gcc on ppc64le doesn't support this
flag.
  • Loading branch information
serge-sans-paille committed Oct 7, 2020
1 parent 5df857c commit cf84096
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ include(CheckCXXCompilerFlag)
string(TOUPPER "${CMAKE_BUILD_TYPE}" U_CMAKE_BUILD_TYPE)

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Intel")
if(NOT CMAKE_CXX_FLAGS MATCHES "-march")
CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported)
if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -g -Wunused-parameter -Wextra -Wreorder")
Expand Down
3 changes: 2 additions & 1 deletion docs/source/build-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ anything, the system will do its best to enable the most recent supported instru
Linux/OSX
~~~~~~~~~

Whether you enabled ``XTENSOR_USE_XSIMD`` or not, it is highly recommended to build with ``-march=native`` option:
Whether you enabled ``XTENSOR_USE_XSIMD`` or not, it is highly recommended to build with ``-march=native`` option,
if your compiler supports it:

.. code:: cmake
Expand Down
2 changes: 1 addition & 1 deletion docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ The following minimal ``CMakeLists.txt`` is enough to build the first example:
target_link_libraries(... xtensor::optimize)
set the following compiler flags:
set the following compiler flags, if supported by the target compiler:

* Unix: ``-march=native``;
* Windows: ``/EHsc /MP /bigobj``.
Expand Down
6 changes: 4 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ if(NOT _cxx_std_flag)
endif()

if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND NOT WIN32))
if(NOT CMAKE_CXX_FLAGS MATCHES "-march")
CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported)
if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion")
Expand All @@ -83,7 +84,8 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(NOT WIN32)
if(NOT CMAKE_CXX_FLAGS MATCHES "-march")
CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported)
if(arch_native_supported AND NOT CMAKE_CXX_FLAGS MATCHES "-march")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_cxx_std_flag} -Wunused-parameter -Wextra -Wreorder -Wconversion -Wsign-conversion")
Expand Down
5 changes: 4 additions & 1 deletion xtensorConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION} VERSION_GREATER_EQUAL 3.11)
target_compile_options(xtensor::optimize INTERFACE /EHsc /MP /bigobj)
# gcc, clang, ...
else()
target_compile_options(xtensor::optimize INTERFACE -march=native)
CHECK_CXX_COMPILER_FLAG(-march=native arch_native_supported)
if(arch_native_supported)
target_compile_options(xtensor::optimize INTERFACE -march=native)
endif()
endif()
endif()

Expand Down

0 comments on commit cf84096

Please sign in to comment.