blob: 14d2fdf262698e89f5609ebf5aba58ca20a1bac9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
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
function(_TensorFlow_import)
# Find the header & lib
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")
if(NOT TensorFlow_LIB OR NOT TensorFlow_INCLUDE_DIR)
message(STATUS "Found TensorFlow: FALSE")
set(TensorFlow_FOUND FALSE PARENT_SCOPE)
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 COMPILE_RESULT_VAR)
message(STATUS "Failed to build TensorFlowVersionChecker. Your libtensorflow may be built on different version of Ubuntu.")
message(STATUS "Found TensorFlow: FALSE")
set(TensorFlow_FOUND FALSE PARENT_SCOPE)
return()
endif(NOT COMPILE_RESULT_VAR)
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})")
# NOTE IMPORTED target may be more appropriate for this case
add_library(tensorflow INTERFACE)
target_link_libraries(tensorflow INTERFACE ${TensorFlow_LIB})
target_include_directories(tensorflow INTERFACE ${TensorFlow_INCLUDE_DIR})
endif(NOT TARGET tensorflow)
set(TensorFlow_FOUND TRUE PARENT_SCOPE)
endfunction(_TensorFlow_import)
_TensorFlow_import()
|