Introduce GTestSource package (#3136)
author박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Thu, 28 Mar 2019 08:18:55 +0000 (17:18 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Thu, 28 Mar 2019 08:18:55 +0000 (17:18 +0900)
This commit extracts GTestSource package from GTest package.

Signed-off-by: Jonghyun Park <jh1302.park@samsung.com>
CMakeLists.txt
cmake/packages/GTestConfig.cmake
cmake/packages/GTestSourceConfig.cmake [new file with mode: 0644]

index ec8c75d..3fdb021 100644 (file)
@@ -53,7 +53,8 @@ option(DOWNLOAD_PYTORCH "Download Pytorch source" ON)
 option(DOWNLOAD_ONNX "Download ONNX source" ON)
 option(DOWNLOAD_ABSEIL "Download Abseil-cpp source" ON)
 
-option(BUILD_GTEST "Download and build Google Test" ON)
+option(DOWNLOAD_GTEST "Download Google Test source" ON)
+option(BUILD_GTEST "Build Google Test from the downloaded source" ON)
 
 nncc_find_package(GTest QUIET)
 
index fa649d4..c10ebd7 100644 (file)
@@ -3,12 +3,11 @@ if(${BUILD_GTEST})
   nncc_include(ExternalProjectTools)
   nncc_include(OptionTools)
 
-  envoption(GTEST_URL https://github.com/google/googletest/archive/release-1.8.0.tar.gz)
-
-  ExternalSource_Download(GTEST ${GTEST_URL})
+  # TODO Check this later
+  nncc_find_package(GTestSource REQUIRED)
 
   if(NOT TARGET gtest_main)
-    add_extdirectory(${GTEST_SOURCE_DIR} gtest)
+    add_extdirectory(${GTestSource_DIR} gtest)
   endif(NOT TARGET gtest_main)
 
   set(GTest_FOUND TRUE)
diff --git a/cmake/packages/GTestSourceConfig.cmake b/cmake/packages/GTestSourceConfig.cmake
new file mode 100644 (file)
index 0000000..d7c9d53
--- /dev/null
@@ -0,0 +1,18 @@
+function(_GTestSource_import)
+  if(NOT DOWNLOAD_GTEST)
+    set(GTestSource_FOUND FALSE PARENT_SCOPE)
+    return()
+  endif(NOT DOWNLOAD_GTEST)
+
+  nncc_include(ExternalSourceTools)
+  nncc_include(OptionTools)
+
+  envoption(GTEST_URL https://github.com/google/googletest/archive/release-1.8.0.tar.gz)
+
+  ExternalSource_Download(GTEST ${GTEST_URL})
+
+  set(GTestSource_DIR ${GTEST_SOURCE_DIR} PARENT_SCOPE)
+  set(GTestSource_FOUND TRUE PARENT_SCOPE)
+endfunction(_GTestSource_import)
+
+_GTestSource_import()