cjweeks / tensorflow-cmake

Integrate TensorFlow with CMake projects effortlessly
MIT License
331 stars 83 forks source link

problems installing eigen and prorobuf #26

Closed 9thDimension closed 6 years ago

9thDimension commented 6 years ago

Firstly, sorry for opening an issue to ask this, but I don't know how else to get in touch.

I'm at the stage of the instructions:

To generate the needed CMake files for your project, execute the script as follows: eigen.sh generate installed <tensorflow-root> [<cmake-dir> <install-dir>]...

OK - running that without the "optional" arguments fails because there already exists a file FindEigen.cmake in this repo's root directory:

cp: '/home/hal9000/Sources/tensorflow-cmake/FindEigen.cmake' and './FindEigen.cmake' are the same file Command failed - script terminated

So instead, I do $ sudo ./eigen.sh generate installed /home/hal9000/Sources/tensorflow /usr/share/cmake-3.5/Modules /usr/local, since the instructions earlier specify <install-dir> to be /usr/local, and I believe <cmake-dir> should be /usr/share/cmake-3.5/Modules. That's where those .cmake files are stored on my machine (is that the correct place, or am I missing the point here?).

Anyway, similarly I run $ sudo ./protobuf.sh install /home/hal9000/Sources/tensorflow /usr/share/cmake-3.5/Modules (which took almost forever to complete, ending with the worrying output Protobuf has been installed to /usr/share/cmake-3.5/Modules), followed by $ sudo ./protobuf.sh generate installed /home/hal9000/Sources/tensorflow /usr/share/cmake-3.5/Modules /usr/local.

Unfortunately, when I go to CLion and start adding this stuff

# Eigen
find_package(Eigen REQUIRED)
include_directories(${Eigen_INCLUDE_DIRS})

(and the equivalent lines for protobuf) to the CMakeLists.txt of my project, I get the error:

CMake Error at CMakeLists.txt:18 (include):
  include could not find load file:

    Protobuf

CMake Error at CMakeLists.txt:19 (add_dependencies):
  Cannot add target-level dependencies to non-existent target
  "<EXECUTABLE_NAME>".

  The add_dependencies works for top-level logical targets created by the...

I'm obviously doing something (probably everything?) wrong. So what am I not getting?

cjweeks commented 6 years ago

Part of your problem is actually my fault, because there's a typo in the README for the Protobuf instructions. I'll fix that very shortly. The arguments for protobuf.sh are actually the following: sudo protobuf.sh install <tensorflow-root> [<install-dir> <download-dir>]. That certainly makes a lot more sense than specifying the CMake directory while installing! So now, to install Prorobuf to /usr/local, you only need to execute the following:

sudo ./protobuf.sh install /home/hal9000/Sources/tensorflow 

You previously installed Protobuf into the shared CMake directory; I would definitely advise deleting it from there to save space and remove clutter. The installation of Protobuf does take a very long time; this is because we have to build a specific version from source.

Ok, so that's the first part. The next issue concerns where all the CMake files go. The files generated by the scripts in this repository are intended to be placed within the CMake Modules directory of your project. In most scenarios, this is in the <PROJECT_ROOT>/cmake/Modules directory. If we run the generate commands for the install-project example in the repository and open the project in CLion, we can see that the files are put into install-project/cmake/Modules:

tensorflow-cmake_issue26

So you should simply be able to correctly place the generated CMake files using the following:

./eigen.sh generate installed <PROJECT_ROOT>/cmake/Modules /usr/local
./protobuf.sh generate installed <PROJECT_ROOT>/cmake/Modules /usr/local

Note that <PROJECT_ROOT> should be replaced with the path to your CLion project. For example, I have the install-project example in ~/git/tensorflow-cmake/install-project, so I would execute the following:

./eigen.sh generate installed ~/git/tensorflow examples/install-project/cmake/Modules
./protobuf.sh generate installed ~/git/tensorflow examples/install-project/cmake/Modules

Don't forget that you have to manually copy FindTensorflow.cmake into this directory too.

Finally, the last issue comes from the CMake errors you are getting. It seems like you aren't changing the <EXECUTABLE_NAME> placeholder to the name of your actual executable. I would suggest taking a look at the CMakeLists.txt for this repository's install-project example. In that example, <EXECUTABLE_NAME> is install-project.

I hope this information helps; please let me know if these problems persist or any others arise.