[Cycles/MSVC/Testing] Fix broken test code.
[blender.git] / build_files / cmake / Modules / GTestTesting.cmake
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
15 macro(BLENDER_SRC_GTEST_EX NAME SRC EXTRA_LIBS DO_ADD_TEST)
16         if(WITH_GTESTS)
17                 get_property(_current_include_directories
18                              DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
19                              PROPERTY INCLUDE_DIRECTORIES)
20                 set(TEST_INC
21                         ${_current_include_directories}
22                         ${CMAKE_SOURCE_DIR}/tests/gtests
23                         ${CMAKE_SOURCE_DIR}/extern/glog/src
24                         ${CMAKE_SOURCE_DIR}/extern/gflags/src
25                         ${CMAKE_SOURCE_DIR}/extern/gtest/include
26                         ${CMAKE_SOURCE_DIR}/extern/gmock/include
27                 )
28                 unset(_current_include_directories)
29
30                 add_executable(${NAME}_test ${SRC})
31                 target_link_libraries(${NAME}_test
32                                       ${EXTRA_LIBS}
33                                       ${PLATFORM_LINKLIBS}
34                                       bf_testing_main
35                                       bf_intern_guardedalloc
36                                       extern_gtest
37                                       extern_gmock
38                                       # needed for glog
39                                       ${PTHREADS_LIBRARIES}
40                                       extern_glog
41                                       extern_gflags)
42                 set_target_properties(${NAME}_test PROPERTIES
43                                       RUNTIME_OUTPUT_DIRECTORY         "${TESTS_OUTPUT_DIR}"
44                                       RUNTIME_OUTPUT_DIRECTORY_RELEASE "${TESTS_OUTPUT_DIR}"
45                                       RUNTIME_OUTPUT_DIRECTORY_DEBUG   "${TESTS_OUTPUT_DIR}"
46                                       INCLUDE_DIRECTORIES              "${TEST_INC}")
47                 if(${DO_ADD_TEST})
48                         add_test(NAME ${NAME}_test COMMAND ${TESTS_OUTPUT_DIR}/${NAME}_test WORKING_DIRECTORY $<TARGET_FILE_DIR:blender>)
49                 endif()
50         endif()
51 endmacro()
52
53 macro(BLENDER_SRC_GTEST NAME SRC EXTRA_LIBS)
54         BLENDER_SRC_GTEST_EX("${NAME}" "${SRC}" "${EXTRA_LIBS}" "TRUE")
55 endmacro()
56
57 macro(BLENDER_TEST NAME EXTRA_LIBS)
58         BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "TRUE")
59 endmacro()
60
61 macro(BLENDER_TEST_PERFORMANCE NAME EXTRA_LIBS)
62         BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "FALSE")
63 endmacro()