Enable build-time test (#76)
author박종현/동작제어Lab(SR)/Senior Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 12 Apr 2018 23:52:40 +0000 (08:52 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 12 Apr 2018 23:52:40 +0000 (08:52 +0900)
* Enable build-time test

This commit revises CMakeLists.txt to enable build-time testing based on
Google Test, introduces three helper functions for build library and tests.

With this commit, build-time test will be enabled by default only when google
test is available.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
* Insert 'add_test'

CMakeLists.txt

index c83ed40..bd8b2af 100644 (file)
@@ -2,6 +2,47 @@ cmake_minimum_required(VERSION 2.8)
 
 project(nncc)
 
+enable_testing()
+
+###
+### Configuration
+###
+find_package(GTest)
+
+if(NOT DEFINED ENABLE_TEST)
+  # Enable test by default
+  set(ENABLE_TEST ${GTEST_FOUND})
+endif(NOT DEFINED ENABLE_TEST)
+
+if(${ENABLE_TEST} AND NOT ${GTEST_FOUND})
+  message(FATAL_ERROR "Google Test is required to enable test")
+endif(${ENABLE_TEST} AND NOT ${GTEST_FOUND})
+
+###
+### Function
+###
+function(add_nncc_library)
+  add_library(${ARGV})
+endfunction(add_nncc_library)
+
+function(add_nncc_test)
+  if(ENABLE_TEST)
+    add_executable(${ARGV})
+    target_include_directories(${ARGV0} PRIVATE ${GTEST_INCLUDE_DIRS})
+    target_link_libraries(${ARGV0} ${GTEST_BOTH_LIBRARIES} pthread)
+    add_test(${ARGV0} ${ARGV0})
+  endif(ENABLE_TEST)
+endfunction(add_nncc_test)
+
+function(nncc_test_link_libraries)
+  if(ENABLE_TEST)
+    target_link_libraries(${ARGV})
+  endif(ENABLE_TEST)
+endfunction(nncc_test_link_libraries)
+
+###
+### Components
+###
 add_subdirectory(libs)
 add_subdirectory(tools)
 add_subdirectory(contrib)