Target_compile_options
- Target_compile_options Fpic
- Target_compile_options C++
- Cmake Target Compile Options Example
- Cmake Target_compile_options
Configuration¶
xtensor
can be configured via macros which must be defined before includingany of its headers. This can be achieved the following ways:
Targetcompileoptions(gmockmain PRIVATE -w) I found that I have to append to the Clang Compile Flags of all of these targets. Maybe because I am using gtest1.7 and gmock1.7. 2016-06-05 at 19:35:50. John Lamp said: Ah, yes, CMake has been changing a lot since version 3 came out. I’ll admit I haven’t kept up with all of them, I. Targetcompileoptions(MyTarget PRIVATE '$:-my-flag') This is a newer, better way to add things than using specialized.DEBUG variables, and generalized to all the things generator expressions support.
either define them in the CMakeLists of your project, with
target_compile_definitions
cmake command.or create a header where you define all the macros you want and then include the headers youneed. Then include this header whenever you need
xtensor
in your project.


Target_compile_options Fpic
The following macros are already defined in xtensor
but can be overwritten:
XTENSOR_DEFAULT_DATA_CONTAINER(T,A)
: defines the type used as the default data container for tensors and arrays.T
is thevalue_type
of the container andA
itsallocator_type
.XTENSOR_DEFAULT_SHAPE_CONTAINER(T,EA,SA)
: defines the type used as the default shape container for tensors and arrays.T
is thevalue_type
of the data container,EA
itsallocator_type
, andSA
is theallocator_type
of the shape container.XTENSOR_DEFAULT_LAYOUT
: defines the default layout (row_major, column_major, dynamic) for tensors and arrays. We stronglydiscourage using this macro, which is provided for testing purpose. Prefer defining alias types on tensor and arraycontainers instead.XTENSOR_DEFAULT_TRAVERSAL
: defines the default traversal order (row_major, column_major) for algorithms and iterators on tensorsand arrays. We strongly discourage using this macro, which is provided for testing purpose.
The following macros are helpers for debugging, they are not defined by default:

XTENSOR_ENABLE_ASSERT
: enables assertions in xtensor, such as bound check.XTENSOR_ENABLE_CHECK_DIMENSION
: enables the dimensions check inxtensor
. Note that this option should not be turnedon if you expectoperator()
to perform broadcasting.
External dependencies¶
The last group of macros is for using external libraries to achieve maximum performance (see next section for additionalrequirements):
XTENSOR_USE_XSIMD
: enables SIMD acceleration inxtensor
. This requires that you have xsimd installedon your system.XTENSOR_USE_TBB
: enables parallel assignment loop. This requires that you have tbb installedon your system.XTENSOR_DISABLE_EXCEPTIONS
: disables c++ exceptions.XTENSOR_USE_OPENMP
: enables parallel assignment loop using OpenMP. This requires that OpenMP is available on your system.
Defining these macros in the CMakeLists of your project before searching for xtensor
will trigger automatic findingof dependencies, so you don’t have to include the find_package(xsimd)
and find_package(TBB)
commands in yourCMakeLists:
Build and optimization¶
Windows¶
Windows users must activate the /bigobj
flag, otherwise it’s almost certain that the compilation fails. More generally,the following options are recommended:
If you defined XTENSOR_USE_XSIMD
, you must also specify which instruction set you target:
Target_compile_options C++
If you build on an old system that does not support any of these instruction sets, you don’t have to specifyanything, the system will do its best to enable the most recent supported instruction set.
Linux/OSX¶
Whether you enabled XTENSOR_USE_XSIMD
or not, it is highly recommended to build with -march=native
option,if your compiler supports it:
Notice that this option prevents building on a machine and distributing the resulting binary on another machine witha different architecture (i.e. not supporting the same instruction set).
Cmake Target Compile Options Example
Cmake Target_compile_options
if(CMAKE_CXX_COMPILER_ID STREQUAL'GNU') |
# using GCC |
set(CMAKE_VERBOSE_MAKEFILE 1) |
set_target_properties(${PROJECT_NAME}PROPERTIESCOMPILE_DEFINITIONS'Bits64_;UNIX;_BOOL;LINUX;FUNCPROTO;_GNU_SOURCE;LINUX_64;REQUIRE_IOSTREAM') |
set(GCC_COMPILE_OPTIONS '-m64;-fPIC;-fno-strict-aliasing;-Wall;-Wno-multichar;-Wno-comment;-Wno-sign-compare;-funsigned-char;-pthread;-Wno-deprecated;-Wno-reorder;-ftemplate-depth-64;-fno-gnu-keywords;-std=c++0x;-Winline') |
set(GCC_COMPILE_DEBUG_OPTIONS '${GCC_COMPILE_OPTIONS};-ggdb;-O0') |
set(GCC_COMPILE_RELEASE_OPTIONS '${GCC_COMPILE_OPTIONS};-O3') |
target_compile_options(${PROJECT_NAME}PUBLIC'$<$<CONFIG:Debug>:${GCC_COMPILE_DEBUG_OPTIONS}>') |
target_compile_options(${PROJECT_NAME}PUBLIC'$<$<CONFIG:Release>:${GCC_COMPILE_RELEASE_OPTIONS}>') |
elseif (CMAKE_CXX_COMPILER_ID STREQUAL'MSVC') |
# using Visual Studio C++ |
set(MSVC_COMPILE_OPTIONS '/MP;/W3;/w34710;/Gy;/Zc:wchar_t;/nologo;/std:c++0x /EHsc') |
set(MSVC_COMPILE_DEBUG_OPTIONS '${MSVC_COMPILE_OPTIONS} /ZI /Od') |
set(MSVC_COMPILE_RELEASE_OPTIONS '${MSVC_COMPILE_OPTIONS} /O2') |
target_compile_options(${PROJECT_NAME}PUBLIC'$<$<CONFIG:Debug>:${MSVC_COMPILE_DEBUG_OPTIONS}>') |
target_compile_options(${PROJECT_NAME}PUBLIC'$<$<CONFIG:Release>:${MSVC_COMPILE_RELEASE_OPTIONS}>') |
endif() |