Skip to content

Commit a36252b

Browse files
committed
Updated docs for modern CMake #124
1 parent c3f646f commit a36252b

File tree

10 files changed

+54
-41
lines changed

10 files changed

+54
-41
lines changed

docs/source/examples.rst

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
Examples
22
========
33

4-
This guide show how to create and run some basic examples that show the functionality of cppflow. The code of these examples is available on the `GitHub repo <https://github.com/serizba/cppflow/tree/cppflow2/examples>`_. To run these examples, just use the provided CMake on each of them (after having installed the TF C API as in :ref:`Installation`):
5-
6-
.. code:: bash
7-
8-
git clone git@github.com:serizba/cppflow.git
9-
cd cppflow/examples/load_model
10-
mkdir build
11-
cd build
12-
cmake ..
13-
make
14-
./example
15-
16-
174
Create and load model
185
---------------------
196

docs/source/installation.rst

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Installation
44
============
55

6-
One of the advantages of cppflow is that you don't need to compile or install TensorFlow, you just need to download the `TF C API <https://www.tensorflow.org/install/lang_c>`_. As cppflow is a header-only library, once you have the C API, the only thing you need to do is include the cppflow files from your project.
6+
One of the advantages of cppflow is that you don't need to compile or install TensorFlow, you just need to download the `TF C API <https://www.tensorflow.org/install/lang_c>`_. Cppflow is a header-only library, and thus you can just include the cppflow files in your project.
77

88
To install the C API in your system you have two options:
99

@@ -18,12 +18,8 @@ You can install the C API in a system directory and do not worry about it again.
1818
1919
Install the TF C API in custom directory
2020
----------------------------------------
21-
.. note::
22-
The easiest way is to extract the library into your HOME directory, in a folder called ``libtensorflow2``. In this case, you can directly use the CMake files from the examples, which will search for the library in your HOME directory.
23-
24-
``mkdir -p ~/libtensorflow2/ && tar -C ~/libtensorflow2/ -xzf (downloaded file)``
2521

26-
You can also install the library in a custom directory. In this case, after `downloading it <https://www.tensorflow.org/install/lang_c>`_ and unpacking it you will need to update your PATH or add a hint to your ``CMakeLists.txt`` to find the library.
22+
You can also install the library in a custom directory. In this case, after `downloading it <https://www.tensorflow.org/install/lang_c>`_ and unpacking it you will need to update your PATH or tell CMake where you placed the library with ``-DCMAKE_PREFIX_PATH=...``.
2723

2824
.. code:: bash
2925
@@ -37,11 +33,24 @@ Now, update your path:
3733
export LIBRARY_PATH=$LIBRARY_PATH:/path/to/mydir/lib
3834
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/mydir/lib
3935
40-
Or add a hint in ``CMakeLists.txt`` as in the examples:
4136
42-
.. code:: cmake
37+
Install cppflow
38+
-----------------------------
39+
40+
Cppflow is just a header-only library, and thus it does not require to build it. To facilitate the installation, we provide a CMake file that will install the library in your system. To install it, you just have to:
41+
42+
.. code:: bash
43+
44+
mkdir build
45+
cd build
46+
cmake ..
47+
make -j
48+
make install
49+
50+
.. note::
51+
If you installed the TF C API in a custom directory, you will need to tell CMake where you placed the library with ``-DCMAKE_PREFIX_PATH=/path/to/mydir/``.
4352

44-
find_library(TENSORFLOW_LIB tensorflow HINT /path/to/mydir/lib)
53+
This will also compile the examples, if you don't want to compile them, you can use ``-DBUILD_EXAMPLES=OFF``.
4554

4655

4756
You are done, now you can proceed to build your :ref:`first example<First example>`.

docs/source/quickstart.rst

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Once you have downloaded the TF C API and cppflow you can start playing with ten
1212
.. code:: c++
1313

1414
#include <iostream>
15-
#include "cppflow/cppflow.h"
15+
#include <cppflow/cppflow.h>
1616

1717
int main() {
1818

@@ -26,11 +26,11 @@ Once you have downloaded the TF C API and cppflow you can start playing with ten
2626
return 0;
2727
}
2828

29-
Easy right?, now you can compile it with the terminal (if you have configured the TF C API as stated in :ref:`Installation`) using the following command:
29+
Easy right?, now you can compile it with the terminal (if you have configured the TF C API and installed cppflow as stated in :ref:`Installation`) using the following command:
3030

3131
.. code:: bash
3232
33-
g++ -std=c++17 -o main.out -I /path/to/libtensorflow2/include/ -I/path/to/cppflow/include/ main.cpp -ltensorflow
33+
g++ -std=c++17 -o main.out main.cpp -ltensorflow
3434
./main.out
3535
3636
You should see the result of ``a + b``:
@@ -48,17 +48,34 @@ Probably a more convenient way of compiling your code is using CMake.
4848
.. code:: cmake
4949
5050
cmake_minimum_required(VERSION 3.10)
51+
5152
project(example)
5253
53-
find_library(TENSORFLOW_LIB tensorflow HINT $ENV{HOME}/libtensorflow2/lib)
54+
add_executable(example main.cpp)
55+
56+
find_package(cppflow REQUIRED)
5457
55-
set(CMAKE_CXX_STANDARD 17)
58+
target_include_directories(
59+
example PUBLIC
60+
cppflow::cppflow
61+
)
5662
57-
add_executable(example main.cpp)
58-
target_include_directories(example PRIVATE /path/to/cppflow/include/ $ENV{HOME}/libtensorflow2/include)
59-
target_link_libraries (example "${TENSORFLOW_LIB}")
63+
target_link_libraries(
64+
example PUBLIC
65+
cppflow::cppflow
66+
)
6067
68+
Now you can compile it with:
6169

70+
.. code:: bash
71+
72+
mkdir build
73+
cd build
74+
cmake ..
75+
make
76+
77+
.. note::
78+
If you installed the TF C API or cppflow in a custom directory, you will need to tell CMake where you placed them ``-DCMAKE_PREFIX_PATH=/path/to/mydir/``.
6279

6380
Load a model
6481
------------
@@ -68,7 +85,7 @@ You can easily run TensorFlow models with cppflow by loading a `saved model <htt
6885
.. code:: c++
6986

7087
#include <iostream>
71-
#include "cppflow/cppflow.h"
88+
#include <cppflow/cppflow.h>
7289

7390

7491
int main() {

examples/eager_op_multithread/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <vector>
44
#include <iostream>
55

6-
#include "cppflow/cppflow.h"
6+
#include <cppflow/cppflow.h>
77

88
constexpr size_t num_iter = 10240;
99
constexpr size_t num_threads = 32;

examples/efficientnet/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <iostream>
22

3-
#include "cppflow/cppflow.h"
3+
#include <cppflow/cppflow.h>
44

55

66
int main() {

examples/load_frozen_graph/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <iostream>
22

3-
#include "cppflow/ops.h"
4-
#include "cppflow/model.h"
3+
#include <cppflow/ops.h>
4+
#include <cppflow/model.h>
55

66

77
int main() {

examples/load_model/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <iostream>
22

3-
#include "cppflow/ops.h"
4-
#include "cppflow/model.h"
3+
#include <cppflow/ops.h>
4+
#include <cppflow/model.h>
55

66

77
int main() {

examples/multi_input_output/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <iostream>
22

3-
#include "cppflow/ops.h"
4-
#include "cppflow/model.h"
3+
#include <cppflow/ops.h>
4+
#include <cppflow/model.h>
55

66
int main() {
77

examples/tensor/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <iostream>
44
#include <stdexcept>
55

6-
#include "cppflow/cppflow.h"
6+
#include <cppflow/cppflow.h>
77

88
bool float_equal(const float f1, const float f2) {
99
return std::abs(f1/f2-1.0f) < 1e-6;

examples/tensor/odr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "cppflow/cppflow.h"
1+
#include <cppflow/cppflow.h>
22

33
// Do NOT remove this file
44
// test ODR violation

0 commit comments

Comments
 (0)