From c1be7595d7d0cbd42d36893c0f68933d4aef6013 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=EC=B1=84=EC=84=B1=EC=9A=B0/On-Device=20Lab=28SR=29/Enginee?= =?utf8?q?r/=EC=82=BC=EC=84=B1=EC=A0=84=EC=9E=90?= Date: Mon, 13 May 2019 18:13:14 +0900 Subject: [PATCH] [CMake] Check TensorFlow version (#3373) * [CMake] Check TensorFlow version This commit introduce check of tensorflow version. Signed-off-by: seongwoo * This commit introduce .FORMATCHECKED Signed-off-by: seongwoo * This commit apply format.patch Signed-off-by: seongwoo * This commit make code safe. Signed-off-by: seongwoo * This commit remove modification of 'format' Signed-off-by: seongwoo --- cmake/packages/.FORMATCHECKED | 0 cmake/packages/TensorFlowConfig.cmake | 17 ++++++++++++++++- cmake/packages/TensorFlowVersionChecker.c | 9 +++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 cmake/packages/.FORMATCHECKED create mode 100644 cmake/packages/TensorFlowVersionChecker.c diff --git a/cmake/packages/.FORMATCHECKED b/cmake/packages/.FORMATCHECKED new file mode 100644 index 0000000..e69de29 diff --git a/cmake/packages/TensorFlowConfig.cmake b/cmake/packages/TensorFlowConfig.cmake index 025b551..ea76380 100644 --- a/cmake/packages/TensorFlowConfig.cmake +++ b/cmake/packages/TensorFlowConfig.cmake @@ -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 index 0000000..6161ef7 --- /dev/null +++ b/cmake/packages/TensorFlowVersionChecker.c @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + if (argc >= 2 && !strcmp(argv[1], TF_Version())) + return 0; + return 255; +} -- 2.7.4