GTestTesting.cmake 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #=============================================================================
  2. # Copyright 2014 Blender Foundation.
  3. #
  4. # Distributed under the OSI-approved BSD License (the "License");
  5. # see accompanying file Copyright.txt for details.
  6. #
  7. # This software is distributed WITHOUT ANY WARRANTY; without even the
  8. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. # See the License for more information.
  10. #
  11. # Inspired on the Testing.cmake from Libmv
  12. #
  13. #=============================================================================
  14. macro(BLENDER_SRC_GTEST_EX NAME SRC EXTRA_LIBS DO_ADD_TEST)
  15. if(WITH_GTESTS)
  16. get_property(_current_include_directories
  17. DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  18. PROPERTY INCLUDE_DIRECTORIES)
  19. set(TEST_INC
  20. ${_current_include_directories}
  21. ${CMAKE_SOURCE_DIR}/tests/gtests
  22. ${GLOG_INCLUDE_DIRS}
  23. ${GFLAGS_INCLUDE_DIRS}
  24. ${CMAKE_SOURCE_DIR}/extern/gtest/include
  25. ${CMAKE_SOURCE_DIR}/extern/gmock/include
  26. )
  27. unset(_current_include_directories)
  28. add_executable(${NAME}_test ${SRC})
  29. target_link_libraries(${NAME}_test
  30. ${EXTRA_LIBS}
  31. ${PLATFORM_LINKLIBS}
  32. bf_testing_main
  33. bf_intern_guardedalloc
  34. extern_gtest
  35. extern_gmock
  36. # needed for glog
  37. ${PTHREADS_LIBRARIES}
  38. ${GLOG_LIBRARIES}
  39. ${GFLAGS_LIBRARIES})
  40. if(WITH_OPENMP_STATIC)
  41. target_link_libraries(${NAME}_test ${OpenMP_LIBRARIES})
  42. endif()
  43. set_target_properties(${NAME}_test PROPERTIES
  44. RUNTIME_OUTPUT_DIRECTORY "${TESTS_OUTPUT_DIR}"
  45. RUNTIME_OUTPUT_DIRECTORY_RELEASE "${TESTS_OUTPUT_DIR}"
  46. RUNTIME_OUTPUT_DIRECTORY_DEBUG "${TESTS_OUTPUT_DIR}"
  47. INCLUDE_DIRECTORIES "${TEST_INC}")
  48. if(${DO_ADD_TEST})
  49. add_test(NAME ${NAME}_test COMMAND ${TESTS_OUTPUT_DIR}/${NAME}_test WORKING_DIRECTORY $<TARGET_FILE_DIR:blender>)
  50. endif()
  51. endif()
  52. endmacro()
  53. macro(BLENDER_SRC_GTEST NAME SRC EXTRA_LIBS)
  54. BLENDER_SRC_GTEST_EX("${NAME}" "${SRC}" "${EXTRA_LIBS}" "TRUE")
  55. endmacro()
  56. macro(BLENDER_TEST NAME EXTRA_LIBS)
  57. BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "TRUE")
  58. endmacro()
  59. macro(BLENDER_TEST_PERFORMANCE NAME EXTRA_LIBS)
  60. BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "FALSE")
  61. endmacro()