CMakeLists.txt 1.39 KB
Newer Older
Baptiste Esteban's avatar
Baptiste Esteban committed
1
2
3
4
5
6
7
pybind11_find_import(numpy REQUIRED)

# Python module for testing
set(PYTHON_PYLENE_SRC ${CMAKE_SOURCE_DIR}/pylene-python/src)
pybind11_add_module(pylena_test pylena_test.cpp
                                ${PYTHON_PYLENE_SRC}/core/image_cast.cpp
                                ${PYTHON_PYLENE_SRC}/core/numpy_format.cpp)
8
target_link_libraries(pylena_test PRIVATE Pylene)
Baptiste Esteban's avatar
Baptiste Esteban committed
9
target_include_directories(pylena_test PRIVATE ${CMAKE_SOURCE_DIR}/pylene-python/include)
10
11
12
13
14
15
16
17
18
19
20

# Sanitizer (clang linked statically asan by default unlike gcc)
if ((SANITIZE_ADDRESS OR SANITIZE_UNDEFINED OR SANITIZE_MEMORY OR SANITIZE_THREAD))
    if (CMAKE_CXX_COMPILER_ID STREQUAL Clang)
        target_compile_options(pylena_test PRIVATE -shared-libasan)
        target_link_options(pylena_test PRIVATE -shared-libasan)
    endif()
    add_sanitizers(pylena_test)
    file(COPY asan-pylena-test DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
    set(SANITIZE_SCRIPT asan-pylena-test)
endif()
21
add_dependencies(build-tests pylena_test)
Baptiste Esteban's avatar
Baptiste Esteban committed
22

23
24
25
26
27
28
29
30
function(add_python_test filename)
    file(COPY ${filename} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endfunction(add_python_test)

# PYTHON FILES TO MOVE HERE
add_python_test(test_pylena_numpy.py)

add_test(NAME test_python
31
32
        COMMAND ${SANITIZE_SCRIPT} ${PYTHON_EXECUTABLE} -m unittest discover
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
33
set_tests_properties(test_python PROPERTIES LABELS UnitTests)