Skip to content

Commit

Permalink
Updating implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
tdegeus authored and JohanMabille committed Dec 8, 2019
1 parent 30b8233 commit 047b89b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 26 deletions.
19 changes: 12 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ OPTION(XTENSOR_USE_TBB "enable parallelization using intel TBB" OFF)
OPTION(XTENSOR_USE_OPENMP "enable parallelization using OpenMP" OFF)
if(XTENSOR_USE_TBB AND XTENSOR_USE_OPENMP)
message(
FATAL
FATAL
"XTENSOR_USE_TBB and XTENSOR_USE_OPENMP cannot both be active at once"
)
endif()
Expand Down Expand Up @@ -71,16 +71,16 @@ if(XTENSOR_USE_OPENMP)
find_package(Threads REQUIRED)
add_library(OpenMP::OpenMP_CXX_xtensor IMPORTED INTERFACE)
set_property(
TARGET
TARGET
OpenMP::OpenMP_CXX_xtensor
PROPERTY
PROPERTY
INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS}
)
# Only works if the same flag is passed to the linker; use CMake 3.9+ otherwise (Intel, AppleClang)
set_property(
TARGET
TARGET
OpenMP::OpenMP_CXX_xtensor
PROPERTY
PROPERTY
INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads)

message(STATUS "OpenMP Found")
Expand Down Expand Up @@ -159,8 +159,13 @@ set(XTENSOR_HEADERS
)

add_library(xtensor INTERFACE)
target_include_directories(xtensor INTERFACE $<BUILD_INTERFACE:${XTENSOR_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)

target_include_directories(xtensor INTERFACE
$<BUILD_INTERFACE:${XTENSOR_INCLUDE_DIR}>
$<INSTALL_INTERFACE:include>)

target_compile_features(xtensor INTERFACE cxx_std_14)

target_link_libraries(xtensor INTERFACE xtl)

OPTION(XTENSOR_ENABLE_ASSERT "xtensor bound check" OFF)
Expand Down
4 changes: 2 additions & 2 deletions docs/source/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ The following minimal ``CMakeLists.txt`` is enough to build the first example:
set(CMAKE_EXE_LINKER_FLAGS /MANIFEST:NO)
endif()
target_link_libraries(first_example xtensor xtensor::optimize xtensor::xsimd)
target_link_libraries(first_example xtensor xtensor::optimize xtensor::use_xsimd)
.. note::

Expand All @@ -107,7 +107,7 @@ The following minimal ``CMakeLists.txt`` is enough to build the first example:

.. code:: cmake
target_link_libraries(... xtensor::xsimd)
target_link_libraries(... xtensor::use_xsimd)
enables `xsimd <https://github.com/xtensor-stack/xsimd>`_: an optional dependency of xtensor that enables simd acceleration,
i.e. executing a same operation on a batch of data in a single CPU instruction.
Expand Down
52 changes: 35 additions & 17 deletions xtensorConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,32 @@ find_dependency(xtl @xtl_REQUIRED_VERSION@)
if(NOT TARGET @PROJECT_NAME@)
include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
get_target_property(@PROJECT_NAME@_INCLUDE_DIRS @PROJECT_NAME@ INTERFACE_INCLUDE_DIRECTORIES)
if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.8)
target_compile_features(@PROJECT_NAME@ INTERFACE cxx_std_14)
endif()
endif()

if(XTENSOR_USE_XSIMD AND XTENSOR_USE_TBB)
find_dependency(xsimd @xsimd_REQUIRED_VERSION@)
find_dependency(TBB)
target_compile_definitions(@PROJECT_NAME@ INTERFACE XTENSOR_USE_XSIMD XTENSOR_USE_TBB)
elseif(XTENSOR_USE_XSIMD)
get_target_property(_@PROJECT_NAME@_libs @PROJECT_NAME@ INTERFACE_LINK_LIBRARIES)
set(_@PROJECT_NAME@_defines "")

if(XTENSOR_USE_XSIMD)
find_dependency(xsimd @xsimd_REQUIRED_VERSION@)
target_compile_definitions(@PROJECT_NAME@ INTERFACE XTENSOR_USE_XSIMD)
target_link_libraries(@PROJECT_NAME@ INTERFACE xsimd)
elseif(XTENSOR_USE_TBB)
get_target_property(_@PROJECT_NAME@_tmp @PROJECT_NAME@ INTERFACE_COMPILE_DEFINITIONS)
set(_@PROJECT_NAME@_defines "${_@PROJECT_NAME@_defines}" XTENSOR_USE_XSIMD)
set(_@PROJECT_NAME@_libs "${_@PROJECT_NAME@_libs}" xsimd)
endif()

if(XTENSOR_USE_TBB)
find_dependency(TBB)
target_compile_definitions(@PROJECT_NAME@ INTERFACE XTENSOR_USE_TBB)
get_target_property(_@PROJECT_NAME@_tmp @PROJECT_NAME@ INTERFACE_COMPILE_DEFINITIONS)
set(_@PROJECT_NAME@_defines "${_@PROJECT_NAME@_defines}" XTENSOR_USE_TBB)
endif()

if(XTENSOR_USE_XSIMD OR XTENSOR_USE_TBB)
set_target_properties(@PROJECT_NAME@ PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${_@PROJECT_NAME@_defines}")
endif()

if(XTENSOR_USE_XSIMD)
set_target_properties(@PROJECT_NAME@ PROPERTIES
INTERFACE_LINK_LIBRARIES "${_@PROJECT_NAME@_libs}")
endif()

if(NOT TARGET xtensor::optimize)
Expand All @@ -51,12 +61,20 @@ if(NOT TARGET xtensor::optimize)
endif()
endif()

if(NOT TARGET xtensor::xsimd)
find_dependency(xsimd @xsimd_REQUIRED_VERSION@ QUIET)
if(NOT TARGET xtensor::use_xsimd)
find_package(xsimd QUIET)
if (xsimd_FOUND)
add_library(xtensor::xsimd INTERFACE IMPORTED)
target_link_libraries(xtensor::xsimd INTERFACE xsimd)
target_compile_definitions(xtensor::xsimd INTERFACE XTENSOR_USE_XSIMD)
add_library(xtensor::use_xsimd INTERFACE IMPORTED)
target_link_libraries(xtensor::use_xsimd INTERFACE xsimd)
target_compile_definitions(xtensor::use_xsimd INTERFACE XTENSOR_USE_XSIMD)
endif()
endif()

if(NOT TARGET xtensor::use_TBB)
find_package(TBB QUIET)
if (TBB_FOUND)
add_library(xtensor::use_TBB INTERFACE IMPORTED)
target_compile_definitions(xtensor::use_TBB INTERFACE XTENSOR_USE_TBB)
endif()
endif()

0 comments on commit 047b89b

Please sign in to comment.