Skip to content

Commit 7d10096

Browse files
authored
Merge pull request xtensor-stack#133 from JohanMabille/cmake
Cmake
2 parents a1fbdde + baf818b commit 7d10096

File tree

5 files changed

+26
-14
lines changed

5 files changed

+26
-14
lines changed

.appveyor.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ install:
2323
- conda update -q conda
2424
- conda info -a
2525
- conda install gtest cmake -c conda-forge
26-
- conda install xtensor==0.15.0 pytest numpy pybind11==2.2.1 -c conda-forge
26+
- conda install pytest numpy pybind11==2.2.1 -c conda-forge
27+
- conda install xtensor==0.15.1 -c QuantStack
2728
- "set PYTHONHOME=%MINICONDA%"
2829
- cmake -G "NMake Makefiles" -D CMAKE_INSTALL_PREFIX=%MINICONDA%\\Library -D BUILD_TESTS=ON -D PYTHON_EXECUTABLE=%MINICONDA%\\python.exe .
2930
- nmake test_xtensor_python

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ install:
9595
- conda update -q conda
9696
# Useful for debugging any issues with conda
9797
- conda info -a
98-
- conda install xtensor==0.15.0 pytest numpy pybind11==2.2.1 -c conda-forge
98+
- conda install pytest numpy pybind11==2.2.1 -c conda-forge
9999
- conda install cmake gtest -c conda-forge
100+
- conda install xtensor==0.15.1 -c QuantStack
100101
- cmake -D BUILD_TESTS=ON -D CMAKE_INSTALL_PREFIX=$HOME/miniconda .
101102
- make -j2 test_xtensor_python
102103
- make install

CMakeLists.txt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ set(XTENSOR_PYTHON_HEADERS
5353
${XTENSOR_PYTHON_INCLUDE_DIR}/xtensor-python/xtensor_type_caster_base.hpp
5454
)
5555

56+
add_library(xtensor-python INTERFACE)
57+
target_include_directories(xtensor-python INTERFACE $<BUILD_INTERFACE:${XTENSOR_PYTHON_INCLUDE_DIR}>
58+
$<BUILD_INTERFACE:${pybind11_INCLUDE_DIRS}>
59+
$<BUILD_INTERFACE:${NUMPY_INCLUDE_DIRS}>
60+
$<INSTALL_INTERFACE:include>)
61+
target_link_libraries(xtensor-python INTERFACE xtensor)
62+
get_target_property(inc_dir xtensor-python INTERFACE_INCLUDE_DIRECTORIES)
63+
message(STATUS "${inc_dir}")
64+
5665
OPTION(BUILD_TESTS "xtensor test suite" OFF)
5766
OPTION(DOWNLOAD_GTEST "build gtest from downloaded sources" OFF)
5867

@@ -61,12 +70,6 @@ if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
6170
endif()
6271

6372
if(BUILD_TESTS)
64-
include_directories(${XTENSOR_PYTHON_INCLUDE_DIR})
65-
include_directories(${xtl_INCLUDE_DIRS})
66-
include_directories(${xtensor_INCLUDE_DIRS})
67-
include_directories(${NUMPY_INCLUDE_DIRS})
68-
include_directories(${pybind11_INCLUDE_DIRS})
69-
7073
if(MSVC)
7174
set(PYTHON_MODULE_EXTENSION ".pyd")
7275
else()
@@ -83,6 +86,13 @@ endif()
8386
include(GNUInstallDirs)
8487
include(CMakePackageConfigHelpers)
8588

89+
install(TARGETS xtensor-python
90+
EXPORT ${PROJECT_NAME}-targets)
91+
92+
# Makes the project importable from the build directory
93+
export(EXPORT ${PROJECT_NAME}-targets
94+
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
95+
8696
install(FILES ${XTENSOR_PYTHON_HEADERS}
8797
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/xtensor-python)
8898

@@ -105,4 +115,7 @@ set(CMAKE_SIZEOF_VOID_P ${_XTENSOR_CMAKE_SIZEOF_VOID_P})
105115
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
106116
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
107117
DESTINATION ${XTENSOR_PYTHON_CMAKECONFIG_INSTALL_DIR})
118+
install(EXPORT ${PROJECT_NAME}-targets
119+
FILE ${PROJECT_NAME}Targets.cmake
120+
DESTINATION ${XTENSOR_PYTHON_CMAKECONFIG_INSTALL_DIR})
108121

include/xtensor-python/pycontainer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ namespace xt
345345
throw std::runtime_error("Cannot reshape with unknown layout_type.");
346346
}
347347

348-
PyArray_Dims dims({reinterpret_cast<npy_intp*>(shape.data()), static_cast<int>(shape.size())});
348+
PyArray_Dims dims = {reinterpret_cast<npy_intp*>(shape.data()), static_cast<int>(shape.size())};
349349
auto new_ptr = PyArray_Newshape((PyArrayObject*) this->ptr(), &dims, npy_layout);
350350
auto old_ptr = this->ptr();
351351
this->ptr() = new_ptr;

test/CMakeLists.txt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ endif()
7878

7979
find_package(Threads)
8080

81-
include_directories(${XTENSOR_INCLUDE_DIR})
82-
include_directories(${XTENSOR_PYTHON_INCLUDE_DIR})
8381
include_directories(${GTEST_INCLUDE_DIRS})
84-
include_directories(${PYBIND11_INCLUDE_DIR})
8582

8683
set(XTENSOR_PYTHON_TESTS
8784
main.cpp
@@ -91,8 +88,8 @@ set(XTENSOR_PYTHON_TESTS
9188
)
9289

9390
set(XTENSOR_PYTHON_TARGET test_xtensor_python)
94-
add_executable(${XTENSOR_PYTHON_TARGET} ${XTENSOR_PYTHON_TESTS} ${XTENSOR_PYTHON_HEADERS} ${XTENSOR_HEADERS})
95-
target_link_libraries(${XTENSOR_PYTHON_TARGET} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${PYTHON_LIBRARIES})
91+
add_executable(${XTENSOR_PYTHON_TARGET} ${XTENSOR_PYTHON_TESTS} ${XTENSOR_PYTHON_HEADERS})
92+
target_link_libraries(${XTENSOR_PYTHON_TARGET} xtensor-python ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${PYTHON_LIBRARIES})
9693

9794
if(DOWNLOAD_GTEST OR GTEST_SRC_DIR)
9895
add_dependencies(${XTENSOR_PYTHON_TARGET} gtest_main)

0 commit comments

Comments
 (0)