Skip to content

Commit

Permalink
cmake: Add a convenience macro for gtest based unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfonseca committed Aug 14, 2015
1 parent 3ff3f99 commit 1ee5efd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Expand Up @@ -481,6 +481,14 @@ target_link_libraries (gtest ${CMAKE_THREAD_LIBS_INIT})
enable_testing ()
add_custom_target (check COMMAND ${CMAKE_CTEST_COMMAND})

# Convenience macro for adding unit tests
macro (add_gtest)
add_executable (${ARGV})
target_link_libraries (${ARGV0} gtest)
add_dependencies (check ${ARGV0})
add_test (NAME ${ARGV0} COMMAND $<TARGET_FILE:${ARGV0}>)
endmacro ()


##############################################################################
# Common libraries / utilities
Expand Down
6 changes: 2 additions & 4 deletions gui/CMakeLists.txt
Expand Up @@ -9,10 +9,8 @@ add_library (qubjson STATIC
qubjson.cpp
)

add_executable (qubjson_test qubjson_test.cpp)
target_link_libraries (qubjson_test qubjson gtest)
add_dependencies (check qubjson_test)
add_test (NAME qubjson_test COMMAND $<TARGET_FILE:qubjson_test>)
add_gtest (qubjson_test qubjson_test.cpp)
target_link_libraries (qubjson_test qubjson)

set(qapitrace_SRCS
androiddevicedialog.cpp
Expand Down
6 changes: 2 additions & 4 deletions guids/CMakeLists.txt
Expand Up @@ -2,7 +2,5 @@ add_library (guids STATIC
guids.cpp
)

add_executable (guids_test guids_test.cpp)
target_link_libraries (guids_test guids gtest)
add_dependencies (check guids_test)
add_test (NAME guids_test COMMAND $<TARGET_FILE:guids_test>)
add_gtest (guids_test guids_test.cpp)
target_link_libraries (guids_test guids)

0 comments on commit 1ee5efd

Please sign in to comment.