Changeset View
Changeset View
Standalone View
Standalone View
build_files/cmake/Modules/GTestTesting.cmake
| #============================================================================= | #============================================================================= | ||||
| # Copyright 2014 Blender Foundation. | # Copyright 2014 Blender Foundation. | ||||
| # | # | ||||
| # Distributed under the OSI-approved BSD License (the "License"); | # Distributed under the OSI-approved BSD License (the "License"); | ||||
| # see accompanying file Copyright.txt for details. | # see accompanying file Copyright.txt for details. | ||||
| # | # | ||||
| # This software is distributed WITHOUT ANY WARRANTY; without even the | # This software is distributed WITHOUT ANY WARRANTY; without even the | ||||
| # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||
| # See the License for more information. | # See the License for more information. | ||||
| # | # | ||||
| # Inspired on the Testing.cmake from Libmv | # Inspired on the Testing.cmake from Libmv | ||||
| # | # | ||||
| #============================================================================= | #============================================================================= | ||||
| macro(BLENDER_SRC_GTEST_EX NAME SRC EXTRA_LIBS DO_ADD_TEST) | macro(BLENDER_SRC_GTEST_EX) | ||||
| if(WITH_GTESTS) | if(WITH_GTESTS) | ||||
| set(TARGET_NAME ${NAME}_test) | # See https://cmake.org/cmake/help/v3.5/command/cmake_parse_arguments.html | ||||
| set(options SKIP_ADD_TEST) | |||||
| set(oneValueArgs NAME EXTRA_CLI) | |||||
| set(multiValueArgs SRC EXTRA_LIBS) | |||||
| cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} ) | |||||
| set(TARGET_NAME ${ARG_NAME}_test) | |||||
| get_property(_current_include_directories | get_property(_current_include_directories | ||||
| DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} | ||||
| PROPERTY INCLUDE_DIRECTORIES) | PROPERTY INCLUDE_DIRECTORIES) | ||||
| set(TEST_INC | set(TEST_INC | ||||
| ${_current_include_directories} | ${_current_include_directories} | ||||
| ${CMAKE_SOURCE_DIR}/tests/gtests | ${CMAKE_SOURCE_DIR}/tests/gtests | ||||
| ) | ) | ||||
| set(TEST_INC_SYS | set(TEST_INC_SYS | ||||
| ${GLOG_INCLUDE_DIRS} | ${GLOG_INCLUDE_DIRS} | ||||
| ${GFLAGS_INCLUDE_DIRS} | ${GFLAGS_INCLUDE_DIRS} | ||||
| ${CMAKE_SOURCE_DIR}/extern/gtest/include | ${CMAKE_SOURCE_DIR}/extern/gtest/include | ||||
| ${CMAKE_SOURCE_DIR}/extern/gmock/include | ${CMAKE_SOURCE_DIR}/extern/gmock/include | ||||
| ) | ) | ||||
| unset(_current_include_directories) | unset(_current_include_directories) | ||||
| add_executable(${TARGET_NAME} ${SRC}) | add_executable(${TARGET_NAME} ${ARG_SRC}) | ||||
| target_include_directories(${TARGET_NAME} PUBLIC "${TEST_INC}") | target_include_directories(${TARGET_NAME} PUBLIC "${TEST_INC}") | ||||
| target_include_directories(${TARGET_NAME} SYSTEM PUBLIC "${TEST_INC_SYS}") | target_include_directories(${TARGET_NAME} SYSTEM PUBLIC "${TEST_INC_SYS}") | ||||
| target_link_libraries(${TARGET_NAME} | target_link_libraries(${TARGET_NAME} | ||||
| ${EXTRA_LIBS} | ${ARG_EXTRA_LIBS} | ||||
| ${PLATFORM_LINKLIBS} | ${PLATFORM_LINKLIBS} | ||||
| bf_testing_main | bf_testing_main | ||||
| bf_intern_eigen | bf_intern_eigen | ||||
| bf_intern_guardedalloc | bf_intern_guardedalloc | ||||
| extern_gtest | extern_gtest | ||||
| extern_gmock | extern_gmock | ||||
| # needed for glog | # needed for glog | ||||
| ${PTHREADS_LIBRARIES} | ${PTHREADS_LIBRARIES} | ||||
| Show All 9 Lines | if(WITH_GTESTS) | ||||
| else() | else() | ||||
| string(REPLACE "\${BUILD_TYPE}" "" TEST_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}) | string(REPLACE "\${BUILD_TYPE}" "" TEST_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}) | ||||
| endif() | endif() | ||||
| set_target_properties(${TARGET_NAME} PROPERTIES | set_target_properties(${TARGET_NAME} PROPERTIES | ||||
| RUNTIME_OUTPUT_DIRECTORY "${TESTS_OUTPUT_DIR}" | RUNTIME_OUTPUT_DIRECTORY "${TESTS_OUTPUT_DIR}" | ||||
| RUNTIME_OUTPUT_DIRECTORY_RELEASE "${TESTS_OUTPUT_DIR}" | RUNTIME_OUTPUT_DIRECTORY_RELEASE "${TESTS_OUTPUT_DIR}" | ||||
| RUNTIME_OUTPUT_DIRECTORY_DEBUG "${TESTS_OUTPUT_DIR}") | RUNTIME_OUTPUT_DIRECTORY_DEBUG "${TESTS_OUTPUT_DIR}") | ||||
| if(${DO_ADD_TEST}) | if(NOT ARG_SKIP_ADD_TEST) | ||||
| add_test(NAME ${TARGET_NAME} COMMAND ${TESTS_OUTPUT_DIR}/${TARGET_NAME} WORKING_DIRECTORY ${TEST_INSTALL_DIR}) | add_test( | ||||
| NAME ${TARGET_NAME} | |||||
| COMMAND ${TESTS_OUTPUT_DIR}/${TARGET_NAME} ${EXTRA_CLI} | |||||
| WORKING_DIRECTORY ${TEST_INSTALL_DIR}) | |||||
| # Don't fail tests on leaks since these often happen in external libraries | # Don't fail tests on leaks since these often happen in external libraries | ||||
| # that we can't fix. | # that we can't fix. | ||||
| set_tests_properties(${TARGET_NAME} PROPERTIES ENVIRONMENT LSAN_OPTIONS=exitcode=0) | set_tests_properties(${TARGET_NAME} PROPERTIES ENVIRONMENT LSAN_OPTIONS=exitcode=0) | ||||
| endif() | endif() | ||||
| unset(TEST_INC) | unset(TEST_INC) | ||||
| unset(TEST_INC_SYS) | unset(TEST_INC_SYS) | ||||
| unset(TARGET_NAME) | unset(TARGET_NAME) | ||||
| endif() | endif() | ||||
| endmacro() | endmacro() | ||||
| macro(BLENDER_SRC_GTEST NAME SRC EXTRA_LIBS) | macro(BLENDER_SRC_GTEST NAME SRC EXTRA_LIBS) | ||||
| BLENDER_SRC_GTEST_EX("${NAME}" "${SRC}" "${EXTRA_LIBS}" "TRUE") | BLENDER_SRC_GTEST_EX( | ||||
| NAME "${NAME}" | |||||
| SRC "${SRC}" | |||||
| EXTRA_LIBS "${EXTRA_LIBS}") | |||||
| endmacro() | endmacro() | ||||
| macro(BLENDER_TEST NAME EXTRA_LIBS) | macro(BLENDER_TEST NAME EXTRA_LIBS) | ||||
| BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "TRUE") | BLENDER_SRC_GTEST_EX( | ||||
| NAME "${NAME}" | |||||
| SRC "${NAME}_test.cc" | |||||
| EXTRA_LIBS "${EXTRA_LIBS}") | |||||
| endmacro() | endmacro() | ||||
| macro(BLENDER_TEST_PERFORMANCE NAME EXTRA_LIBS) | macro(BLENDER_TEST_PERFORMANCE NAME EXTRA_LIBS) | ||||
| BLENDER_SRC_GTEST_EX("${NAME}" "${NAME}_test.cc" "${EXTRA_LIBS}" "FALSE") | BLENDER_SRC_GTEST_EX( | ||||
| NAME "${NAME}" | |||||
| SRC "${NAME}_test.cc" | |||||
| EXTRA_LIBS "${EXTRA_LIBS}" | |||||
| SKIP_ADD_TEST) | |||||
| endmacro() | endmacro() | ||||