summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt44
1 files changed, 43 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 542f151d..8cd5bae6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -429,7 +429,49 @@ install_module(toxcore DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/tox)
429 429
430################################################################################ 430################################################################################
431# 431#
432# :: Automated regression tests 432# :: Unit tests: no networking, just pure function calls.
433#
434################################################################################
435
436# Compile the GTest library.
437#
438if(EXISTS "/usr/src/gtest/src/gtest-all.cc")
439 add_library(gtest
440 /usr/src/gtest/src/gtest-all.cc
441 /usr/src/gtest/src/gtest_main.cc)
442 target_include_directories(gtest PRIVATE /usr/src/gtest)
443 check_cxx_compiler_flag("-w" HAVE_CXX_W QUIET)
444 check_cxx_compiler_flag("-Wno-global-constructors" HAVE_CXX_W_NO_GLOBAL_CONSTRUCTORS QUIET)
445 check_cxx_compiler_flag("-Wno-zero-as-null-pointer-constant" HAVE_CXX_W_NO_ZERO_AS_NULL_POINTER_CONSTANT QUIET)
446 if(HAVE_CXX_W)
447 set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w")
448 endif()
449 set(HAVE_GTEST TRUE)
450endif()
451
452function(unit_test subdir target)
453 if(HAVE_GTEST)
454 add_executable(unit_${target}_test ${subdir}/${target}_test.cpp)
455 target_link_modules(unit_${target}_test ${toxcore_SUBLIBS} gtest)
456 set(gtest_CFLAGS "")
457 if(HAVE_CXX_W_NO_GLOBAL_CONSTRUCTORS)
458 set(gtest_CFLAGS "${gtest_CFLAGS} -Wno-global-constructors")
459 endif()
460 if(HAVE_CXX_W_NO_ZERO_AS_NULL_POINTER_CONSTANT)
461 set(gtest_CFLAGS "${gtest_CFLAGS} -Wno-zero-as-null-pointer-constant")
462 endif()
463 set_target_properties(unit_${target}_test PROPERTIES COMPILE_FLAGS "${gtest_CFLAGS}")
464 add_test(NAME ${target} COMMAND ${CROSSCOMPILING_EMULATOR} unit_${target}_test)
465 endif()
466endfunction()
467
468# The actual unit tests follow.
469#
470unit_test(toxcore crypto_core)
471
472################################################################################
473#
474# :: Automated regression tests: create a tox network and run integration tests
433# 475#
434################################################################################ 476################################################################################
435 477