myx/MyxCMake/lib/macro/GTest.cmake
2022-11-28 07:13:09 +03:00

31 lines
869 B
CMake

include_guard(GLOBAL)
macro(myx_add_gtest TARGET_NAME)
set(options)
set(oneValueArgs)
set(multiValueArgs)
cmake_parse_arguments(ARG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
add_executable(${TARGET_NAME} ${ARG_UNPARSED_ARGUMENTS})
find_package(GTest)
if(GTest_FOUND)
target_link_libraries(${TARGET_NAME} PRIVATE GTest::GTest GTest::Main)
else()
if((NOT TARGET gtest) AND (NOT TARGET gtest_main))
add_subdirectory(/usr/src/googletest/googletest ${CMAKE_BINARY_DIR}/gtest)
endif()
target_link_libraries(${TARGET_NAME} PRIVATE gtest gtest_main)
endif()
add_test(NAME ${TARGET_NAME} COMMAND ${TARGET_NAME})
foreach(__iter IN LISTS oneValueArgs multiValueArgs)
unset(ARG_${__iter})
endforeach()
unset(ARG_UNPARSED_ARGUMENTS)
unset(multiValueArgs)
unset(oneValueArgs)
unset(options)
endmacro()