CMakeLists.txt 1.74 KB
Newer Older
Baptiste Esteban's avatar
Baptiste Esteban committed
1
# Python module for testing
2
pybind11_add_module(pylena_test pylena_test.cpp)
Baptiste Esteban's avatar
Baptiste Esteban committed
3
target_link_libraries(pylena_test PRIVATE Pylene Pylena_numpy)
Baptiste Esteban's avatar
Baptiste Esteban committed
4
target_include_directories(pylena_test PRIVATE ${CONAN_INCLUDE_DIRS_PYBIND11} ${PYTHON_INCLUDE_DIRS}) # TO REMOVE WHEN cmake_find_package FOR PYBIND11 WILL BE FIXED
5
add_dependencies(build-tests pylena_test)
6

Baptiste Esteban's avatar
Baptiste Esteban committed
7
8
# Dummy extension for testing
pybind11_add_module(pylena_extension extension_pylena_numpy.cpp)
Baptiste Esteban's avatar
Baptiste Esteban committed
9
target_link_libraries(pylena_extension PRIVATE Pylene Pylena_numpy)
Baptiste Esteban's avatar
Baptiste Esteban committed
10
target_include_directories(pylena_extension PRIVATE ${CONAN_INCLUDE_DIRS_PYBIND11} ${PYTHON_INCLUDE_DIRS}) # TO REMOVE WHEN cmake_find_package FOR PYBIND11 WILL BE FIXED
11
add_dependencies(build-tests pylena_extension)
Baptiste Esteban's avatar
Baptiste Esteban committed
12

13
14
15
16
17
18
19
# 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)
Baptiste Esteban's avatar
Baptiste Esteban committed
20
21
22
    if (SANITIZE_ADDRESS)
        target_compile_options(pylena_test PRIVATE "-fsanitize-recover=address")
    endif(SANITIZE_ADDRESS)
23
24
25
    file(COPY asan-pylena-test DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
    set(SANITIZE_SCRIPT asan-pylena-test)
endif()
Baptiste Esteban's avatar
Baptiste Esteban committed
26

27
28
29
30
31
32
33
34
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
35
36
        COMMAND ${SANITIZE_SCRIPT} ${PYTHON_EXECUTABLE} -m unittest discover
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
37
set_tests_properties(test_python PROPERTIES LABELS UnitTests)