-
Notifications
You must be signed in to change notification settings - Fork 134
/
CMakeLists.txt
132 lines (107 loc) · 4.82 KB
/
CMakeLists.txt
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
cmake_minimum_required(VERSION 3.6)
project(hello_tf)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if((CMAKE_CXX_COMPILER_ID MATCHES "GNU") OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
set(CMAKE_VERBOSE_MAKEFILE ON)
add_compile_options(-Wall -Wextra -pedantic-errors -Werror)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_compile_options(/W4 /WX)
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.11)
add_compile_options(/permissive-)
endif()
endif()
if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tensorflow)
make_directory(${CMAKE_SOURCE_DIR}/tensorflow)
endif()
if(UNIX AND NOT APPLE)
if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tensorflow)
make_directory(${CMAKE_SOURCE_DIR}/tensorflow)
endif()
if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tensorflow/lib/libtensorflow.so)
file(
DOWNLOAD
https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-linux-x86_64-2.7.0.tar.gz ${CMAKE_SOURCE_DIR}/tensorflow/linux.tar.gz
STATUS
status
LOG
log
)
list(GET status 0 status_code)
list(GET status 1 status_string)
if(NOT status_code EQUAL 0)
message(FATAL_ERROR "error downloading tensorflow lib: ${status_string}" "${log}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvzf ${CMAKE_SOURCE_DIR}/tensorflow/linux.tar.gz WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tensorflow)
file(REMOVE ${CMAKE_SOURCE_DIR}/tensorflow/linux.tar.gz)
endif()
elseif(APPLE)
if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tensorflow)
make_directory(${CMAKE_SOURCE_DIR}/tensorflow)
endif()
if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tensorflow/lib/libtensorflow.so)
file(
DOWNLOAD
https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-darwin-x86_64-2.7.0.tar.gz ${CMAKE_SOURCE_DIR}/tensorflow/darwin.tar.gz
STATUS
status
LOG
log
)
list(GET status 0 status_code)
list(GET status 1 status_string)
if(NOT status_code EQUAL 0)
message(FATAL_ERROR "error downloading tensorflow lib: ${status_string}" "${log}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvzf ${CMAKE_SOURCE_DIR}/tensorflow/darwin.tar.gz WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tensorflow)
file(REMOVE ${CMAKE_SOURCE_DIR}/tensorflow/darwin.tar.gz)
endif()
elseif(WIN32)
if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tensorflow)
make_directory(${CMAKE_SOURCE_DIR}/tensorflow)
endif()
if (NOT EXISTS ${CMAKE_SOURCE_DIR}/tensorflow/lib/tensorflow.dll)
file(
DOWNLOAD
https://storage.googleapis.com/tensorflow/libtensorflow/libtensorflow-cpu-windows-x86_64-2.7.0.zip ${CMAKE_SOURCE_DIR}/tensorflow/windows.zip
STATUS
status
LOG
log
)
list(GET status 0 status_code)
list(GET status 1 status_string)
if(NOT status_code EQUAL 0)
message(FATAL_ERROR "error downloading tensorflow lib: ${status_string}" "${log}")
endif()
execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvzf ${CMAKE_SOURCE_DIR}/tensorflow/windows.zip WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/tensorflow)
file(REMOVE ${CMAKE_SOURCE_DIR}/tensorflow/windows.zip)
endif()
configure_file(tensorflow/lib/tensorflow.dll ${CMAKE_CURRENT_BINARY_DIR}/tensorflow.dll COPYONLY)
configure_file(tensorflow/lib/tensorflow.dll ${CMAKE_CURRENT_BINARY_DIR}/test/tensorflow.dll COPYONLY)
endif()
include_directories(tensorflow/include)
include_directories(src/3rdparty/scope_guard/include)
link_directories(${CMAKE_SOURCE_DIR}/tensorflow/lib)
add_executable(hello_tf src/hello_tf.cpp)
target_link_libraries(hello_tf tensorflow)
add_executable(session_run src/session_run.cpp src/tf_utils.cpp src/tf_utils.hpp)
target_link_libraries(session_run tensorflow)
add_executable(load_graph src/load_graph.cpp)
target_link_libraries(load_graph tensorflow)
add_executable(interface src/interface.cpp src/tf_utils.cpp src/tf_utils.hpp)
target_link_libraries(interface tensorflow)
add_executable(graph_info src/graph_info.cpp src/tf_utils.cpp src/tf_utils.hpp)
target_link_libraries(graph_info tensorflow)
add_executable(create_tensor src/create_tensor.cpp)
target_link_libraries(create_tensor tensorflow)
add_executable(tensor_info src/tensor_info.cpp src/tf_utils.cpp src/tf_utils.hpp)
target_link_libraries(tensor_info tensorflow)
add_executable(allocate_tensor src/allocate_tensor.cpp)
target_link_libraries(allocate_tensor tensorflow)
add_executable(batch_interface src/batch_interface.cpp src/tf_utils.cpp src/tf_utils.hpp)
target_link_libraries(batch_interface tensorflow)
configure_file(models/graph.pb ${CMAKE_CURRENT_BINARY_DIR}/graph.pb COPYONLY)
enable_testing()
add_subdirectory(test)