CMake: Add option to build against system-wide Glog
[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                         ${GLOG_INCLUDE_DIRS}
24                         ${GFLAGS_INCLUDE_DIRS}
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                                       ${GLOG_LIBRARIES}
41                                       ${GFLAGS_LIBRARIES})
42                 if(WITH_OPENMP_STATIC)
43                         target_link_libraries(${NAME}_test ${OpenMP_LIBRARIES})
44                 endif()
45                 set_target_properties(${NAME}_test PROPERTIES
46                                       RUNTIME_OUTPUT_DIRECTORY         "${TESTS_OUTPUT_DIR}"
47                                       RUNTIME_OUTPUT_DIRECTORY_RELEASE "${TESTS_OUTPUT_DIR}"
48                                       RUNTIME_OUTPUT_DIRECTORY_DEBUG   "${TESTS_OUTPUT_DIR}"
49                                       INCLUDE_DIRECTORIES              "${TEST_INC}")
50                 if(${DO_ADD_TEST})
51                         add_test(NAME ${NAME}_test COMMAND ${TESTS_OUTPUT_DIR}/${NAME}_test WORKING_DIRECTORY $<TARGET_FILE_DIR:blender>)
52                 endif()
53         endif()
54 endmacro()
55
56 macro(BLENDER_SRC_GTEST NAME SRC EXTRA_LIBS)
57         BLENDER_SRC_GTEST_EX("${NAME}" "${SRC}" "${EXTRA_LIBS}" "TRUE")
58 endmacro()
59
60 macro(BLENDER_TEST NAME EXTRA_LIBS)
61         BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "TRUE")
62 endmacro()
63
64 macro(BLENDER_TEST_PERFORMANCE NAME EXTRA_LIBS)
65         BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "FALSE")
66 endmacro()