zint_add_test.cmake 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2021-2024 Robin Stuart <rstuart114@gmail.com>
  2. # Adapted from qrencode/tests/CMakeLists.txt
  3. # Copyright (C) 2006-2017 Kentaro Fukuchi <kentaro@fukuchi.org>
  4. # vim: set ts=4 sw=4 et :
  5. macro(zint_add_test test_name test_command)
  6. set(ADDITIONAL_LIBS "${ARGN}" ${LIBRARY_FLAGS})
  7. if(ZINT_SHARED)
  8. add_executable(${test_command} ${test_command}.c)
  9. target_link_libraries(${test_command} testcommon ${ADDITIONAL_LIBS})
  10. if(NOT (ZINT_USE_PNG AND PNG_FOUND))
  11. target_compile_definitions(${test_command} PRIVATE ZINT_NO_PNG)
  12. endif()
  13. add_test(${test_name} ${test_command})
  14. if(MSVC)
  15. set_tests_properties(${test_name} PROPERTIES ENVIRONMENT
  16. "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR};PATH=${CMAKE_BINARY_DIR}/backend/${CMAKE_BUILD_TYPE}\;${CMAKE_BINARY_DIR}/frontend/${CMAKE_BUILD_TYPE}\;$ENV{PATH}")
  17. else()
  18. set_tests_properties(${test_name} PROPERTIES ENVIRONMENT
  19. "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR};LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/backend;PATH=${CMAKE_BINARY_DIR}/frontend:$ENV{PATH}")
  20. endif()
  21. endif()
  22. if(ZINT_STATIC)
  23. add_executable(${test_command}-static ${test_command}.c)
  24. target_link_libraries(${test_command}-static testcommon-static ${ADDITIONAL_LIBS})
  25. if(NOT (ZINT_USE_PNG AND PNG_FOUND))
  26. target_compile_definitions(${test_command}-static PRIVATE ZINT_NO_PNG)
  27. endif()
  28. add_test(${test_name}-static ${test_command}-static)
  29. if(MSVC)
  30. set_tests_properties(${test_name}-static PROPERTIES ENVIRONMENT
  31. "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR};PATH=${CMAKE_BINARY_DIR}/backend/${CMAKE_BUILD_TYPE}\;${CMAKE_BINARY_DIR}/frontend/${CMAKE_BUILD_TYPE}\;$ENV{PATH}")
  32. else()
  33. set_tests_properties(${test_name}-static PROPERTIES ENVIRONMENT
  34. "CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR};LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/backend;PATH=${CMAKE_BINARY_DIR}/frontend:$ENV{PATH}")
  35. endif()
  36. endif()
  37. endmacro()