From: 채성우/On-Device Lab(SR)/Engineer/삼성전자 Date: Mon, 13 May 2019 09:13:14 +0000 (+0900) Subject: [CMake] Check TensorFlow version (#3373) X-Git-Tag: nncc_backup~611 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c1be7595d7d0cbd42d36893c0f68933d4aef6013;p=platform%2Fcore%2Fml%2Fnnfw.git [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 --- 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; +}