I'm using CTest in my project. I added simple script to run tests as POST_BUILD
. Everything works fine when i build project with make
.
The interesting part starts when I'm building package with dpkg-buildpackage
. CTest seems to look for libraries in system directories instead of using a currently built one. Is there a way to tell CTest
or dpkg-buildpackage
to use a currently built library while executing tests?
CMake macro i use:
add_executable(example tests/example.cpp)
target_link_libraries(example my_lib)
enable_testing()
macro(add_unit_test target test)
list(APPEND tests ${test})
add_test(${target} ${test})
endmacro(add_unit_test)
add_unit_test(test_example example)
add_custom_target(all_tests ALL DEPENDS ${tests})
add_custom_command(
TARGET all_tests
COMMENT "Run tests"
POST_BUILD COMMAND ctest ARGS --output-on-failure
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
)
Okay, so i've figured it out.
Because my lib compiles in CMAKE_BINARY_DIR
, all i needed is to add
LD_LIBRARY_PATH
prorerty to every test in project.
So macro now looks like this:
macro(add_unit_test target test)
list(APPEND tests ${test})
add_test(${target} ${test})
set_property(TEST ${target} PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}")
endmacro(add_unit_test)