Fix GTests compilations on Windows
[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                 )
27                 unset(_current_include_directories)
28
29                 add_executable(${NAME}_test ${SRC})
30                 target_link_libraries(${NAME}_test
31                                       ${EXTRA_LIBS}
32                                       ${PLATFORM_LINKLIBS}
33                                       bf_testing_main
34                                       bf_intern_guardedalloc
35                                       extern_gtest
36                                       # needed for glog
37                                       ${PTHREADS_LIBRARIES}
38                                       extern_glog
39                                       extern_gflags)
40                 set_target_properties(${NAME}_test PROPERTIES
41                                       RUNTIME_OUTPUT_DIRECTORY         "${TESTS_OUTPUT_DIR}"
42                                       RUNTIME_OUTPUT_DIRECTORY_RELEASE "${TESTS_OUTPUT_DIR}"
43                                       RUNTIME_OUTPUT_DIRECTORY_DEBUG   "${TESTS_OUTPUT_DIR}"
44                                       INCLUDE_DIRECTORIES              "${TEST_INC}")
45                 if(${DO_ADD_TEST})
46                         add_test(${NAME}_test ${TESTS_OUTPUT_DIR}/${NAME}_test)
47                 endif()
48         endif()
49 endmacro()
50
51 macro(BLENDER_SRC_GTEST NAME SRC EXTRA_LIBS)
52         BLENDER_SRC_GTEST_EX("${NAME}" "${SRC}" "${EXTRA_LIBS}" "TRUE")
53 endmacro()
54
55 macro(BLENDER_TEST NAME EXTRA_LIBS)
56         BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "TRUE")
57 endmacro()
58
59 macro(BLENDER_TEST_PERFORMANCE NAME EXTRA_LIBS)
60         BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "FALSE")
61 endmacro()