CMakeLists.txt 1.63 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Copy a script to launch ASAN for python extensions
set(SANITIZE_SCRIPT "")
if (UNIX AND NOT CYGWIN)
    string(FIND "${CMAKE_CXX_FLAGS}" "-fsanitize=address" USE_SANITIZER)
    if (USE_SANITIZER GREATER -1)
        set(SANITIZE_SCRIPT "asan-pylena-test")
        file(COPY ${SANITIZE_SCRIPT} DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
        if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
            add_compile_options("-shared-libasan")
            add_link_options("-shared-libasan")
        endif()
    endif()
endif()

Baptiste Esteban's avatar
Baptiste Esteban committed
15
# Python module for testing
16
pybind11_add_module(pylena_test pylena_test.cpp)
17
target_link_libraries(pylena_test PRIVATE Pylene Pylene-numpy)
Baptiste Esteban's avatar
Baptiste Esteban committed
18
target_include_directories(pylena_test PRIVATE ${CONAN_INCLUDE_DIRS_PYBIND11} ${PYTHON_INCLUDE_DIRS}) # TO REMOVE WHEN cmake_find_package FOR PYBIND11 WILL BE FIXED
19
add_dependencies(build-tests pylena_test)
20

Baptiste Esteban's avatar
Baptiste Esteban committed
21
22
# Dummy extension for testing
pybind11_add_module(pylena_extension extension_pylena_numpy.cpp)
23
target_link_libraries(pylena_extension PRIVATE Pylene Pylene-numpy)
Baptiste Esteban's avatar
Baptiste Esteban committed
24
target_include_directories(pylena_extension PRIVATE ${CONAN_INCLUDE_DIRS_PYBIND11} ${PYTHON_INCLUDE_DIRS}) # TO REMOVE WHEN cmake_find_package FOR PYBIND11 WILL BE FIXED
25
add_dependencies(build-tests pylena_extension)
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)