[CMake] Check TensorFlow version (#3373)
author채성우/On-Device Lab(SR)/Engineer/삼성전자 <sw4670.chae@samsung.com>
Mon, 13 May 2019 09:13:14 +0000 (18:13 +0900)
committer박종현/On-Device Lab(SR)/Staff Engineer/삼성전자 <jh1302.park@samsung.com>
Mon, 13 May 2019 09:13:14 +0000 (18:13 +0900)
* [CMake] Check TensorFlow version

This commit introduce check of tensorflow version.

Signed-off-by: seongwoo <sw4670.chae@samsung.com>
* This commit introduce .FORMATCHECKED

Signed-off-by: seongwoo <sw4670.chae@samsung.com>
* This commit apply format.patch

Signed-off-by: seongwoo <sw4670.chae@samsung.com>
* This commit make code safe.

Signed-off-by: seongwoo <sw4670.chae@samsung.com>
* This commit remove modification of 'format'

Signed-off-by: seongwoo <sw4670.chae@samsung.com>
cmake/packages/.FORMATCHECKED [new file with mode: 0644]
cmake/packages/TensorFlowConfig.cmake
cmake/packages/TensorFlowVersionChecker.c [new file with mode: 0644]

diff --git a/cmake/packages/.FORMATCHECKED b/cmake/packages/.FORMATCHECKED
new file mode 100644 (file)
index 0000000..e69de29
index 025b551..ea76380 100644 (file)
@@ -1,4 +1,5 @@
 set(TENSORFLOW_PREFIX "/usr" CACHE PATH "The location of pre-installed TensorFlow library")
+set(TENSORFLOW_VERSION_REQUIRED "1.12.0")
 
 # TODO Build TensorFlow from the (downloaded) source
 
@@ -7,7 +8,6 @@ function(_TensorFlow_import)
   find_library(TensorFlow_LIB NAMES tensorflow PATHS "${TENSORFLOW_PREFIX}/lib")
   find_path(TensorFlow_INCLUDE_DIR NAMES tensorflow/c/c_api.h PATHS "${TENSORFLOW_PREFIX}/include")
 
-  # TODO Check TensorFlow version (if possible)
   if(NOT TensorFlow_LIB OR NOT TensorFlow_INCLUDE_DIR)
     message(STATUS "Found TensorFlow: FALSE")
 
@@ -15,6 +15,21 @@ function(_TensorFlow_import)
     return()
   endif(NOT TensorFlow_LIB OR NOT TensorFlow_INCLUDE_DIR)
 
+  # Check TensorFlow version
+  try_run(RUN_RESULT_VAR COMPILE_RESULT_VAR
+    ${CMAKE_BINARY_DIR}
+    ${CMAKE_CURRENT_LIST_DIR}/TensorFlowVersionChecker.c
+    COMPILE_DEFINITIONS -I${TensorFlow_INCLUDE_DIR}
+    LINK_LIBRARIES ${TensorFlow_LIB}
+    ARGS ${TENSORFLOW_VERSION_REQUIRED})
+
+  if(NOT RUN_RESULT_VAR EQUAL 0)
+    message(STATUS "you need tensorflow version ${TENSORFLOW_VERSION_REQUIRED}")
+    message(STATUS "Found TensorFlow: FALSE")
+    set(TensorFlow_FOUND FALSE PARENT_SCOPE)
+    return()
+  endif(NOT RUN_RESULT_VAR EQUAL 0)
+
   # Add tensorflow target (if necessary)
   if(NOT TARGET tensorflow)
     message(STATUS "Found TensorFlow (include: ${TensorFlow_INCLUDE_DIR}, library: ${TensorFlow_LIB})")
diff --git a/cmake/packages/TensorFlowVersionChecker.c b/cmake/packages/TensorFlowVersionChecker.c
new file mode 100644 (file)
index 0000000..6161ef7
--- /dev/null
@@ -0,0 +1,9 @@
+#include <string.h>
+#include <tensorflow/c/c_api.h>
+
+int main(int argc, char **argv)
+{
+  if (argc >= 2 && !strcmp(argv[1], TF_Version()))
+    return 0;
+  return 255;
+}