myx/MyxCMake/lib/macro/GTest.cmake

31 lines
865 B
CMake
Raw Normal View History

2022-11-28 04:13:09 +00:00
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})
2024-03-18 21:16:53 +00:00
foreach(iter IN LISTS oneValueArgs multiValueArgs)
unset(ARG_${iter})
2022-11-28 04:13:09 +00:00
endforeach()
unset(ARG_UNPARSED_ARGUMENTS)
unset(multiValueArgs)
unset(oneValueArgs)
unset(options)
endmacro()