Introduce interface for strict build and coverage (#6207)
author오형석/On-Device Lab(SR)/Staff Engineer/삼성전자 <hseok82.oh@samsung.com>
Mon, 5 Aug 2019 07:53:58 +0000 (16:53 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Mon, 5 Aug 2019 07:53:58 +0000 (16:53 +0900)
Introduce interface nnfw_common and nnfw_coverage in nnfw cmake script
Introduce cmake option variable for strict build and variable setting for coverage build

Signed-off-by: Hyeongseok Oh <hseok82.oh@samsung.com>
infra/nnfw/CMakeLists.txt
infra/nnfw/cmake/CfgOptionFlags.cmake

index 2b76616..1a93d03 100644 (file)
@@ -57,6 +57,36 @@ include("cmake/CfgOptionFlags.cmake")
 
 nnfw_find_package(GTest QUIET)
 
+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})
+
+if(NOT DEFINED ENABLE_COVERAGE)
+  set(ENABLE_COVERAGE FALSE)
+endif(NOT DEFINED ENABLE_COVERAGE)
+
+if(${ENABLE_COVERAGE} AND NOT ${ENABLE_TEST})
+  message(FATAL_ERROR "Test should be enabled to measure test coverage")
+endif(${ENABLE_COVERAGE} AND NOT ${ENABLE_TEST})
+
+add_library(nnfw_common INTERFACE)
+if(ENABLE_STRICT_BUILD)
+  target_compile_options(nnfw_common INTERFACE -Werror -Wall -Wextra)
+endif(ENABLE_STRICT_BUILD)
+
+# TODO Replace using default build option setting in cmake/buildtool/config/config_linux.cmake
+#      to link nnfw_coverage on each module which want to check coverage
+add_library(nnfw_coverage INTERFACE)
+if(ENABLE_COVERAGE)
+  target_compile_options(nnfw_coverage INTERFACE -g -O1 -fprofile-arcs -ftest-coverage)
+  target_link_libraries(nncc_coverage INTERFACE gcov)
+endif(ENABLE_COVERAGE)
+
 nnfw_include(ExtendCMakeFunction)
 
 set(NNFW_SOURCE_ROOT "${CMAKE_SOURCE_DIR}/../..")
index c95cad7..4cc3c94 100644 (file)
@@ -57,3 +57,4 @@ option(BUILD_BOOST "Build boost source" OFF)
 # GTest support
 #
 option(BUILD_GTEST "Download and build Google Test" ON)
+option(ENABLE_STRICT_BUILD "Treat warning as error" ON)