{"action":"created","issue":{"url":"https://api.github.com/repos/BVLC/caffe/issues/1667","labels_url":"https://api.github.com/repos/BVLC/caffe/issues/1667/labels{/name}","comments_url":"https://api.github.com/repos/BVLC/caffe/issues/1667/comments","events_url":"https://api.github.com/repos/BVLC/caffe/issues/1667/events","html_url":"https://github.com/BVLC/caffe/pull/1667","id":53261563,"number":1667,"title":"Improved CMake scripts","user":{"login":"Nerei","id":1026828,"avatar_url":"https://avatars.githubusercontent.com/u/1026828?v=3","gravatar_id":"","url":"https://api.github.com/users/Nerei","html_url":"https://github.com/Nerei","followers_url":"https://api.github.com/users/Nerei/followers","following_url":"https://api.github.com/users/Nerei/following{/other_user}","gists_url":"https://api.github.com/users/Nerei/gists{/gist_id}","starred_url":"https://api.github.com/users/Nerei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nerei/subscriptions","organizations_url":"https://api.github.com/users/Nerei/orgs","repos_url":"https://api.github.com/users/Nerei/repos","events_url":"https://api.github.com/users/Nerei/events{/privacy}","received_events_url":"https://api.github.com/users/Nerei/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/BVLC/caffe/labels/compatibility","name":"compatibility","color":"fbe58a"},{"url":"https://api.github.com/repos/BVLC/caffe/labels/focus","name":"focus","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":16,"created_at":"2015-01-02T16:28:36Z","updated_at":"2015-01-11T22:16:48Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/BVLC/caffe/pulls/1667","html_url":"https://github.com/BVLC/caffe/pull/1667","diff_url":"https://github.com/BVLC/caffe/pull/1667.diff","patch_url":"https://github.com/BVLC/caffe/pull/1667.patch"},"body":"@shelhamer @jeffdonahue @baeuml @kloudkl @akosiorek @Yangqing @BlGene\r\n\r\nHello all, \r\n\r\nhope I referenced everyone who participated cmake development (at least I didn't find others)\r\n\r\nFollowing discussion here https://github.com/BVLC/caffe/pull/1586, as I promised, I prepared slightly improved caffe cmake scripts. The improvement was developed using _Ubuntu 14.04_ and tested on _Yosemite_ (with libstdc++). I believe Windows support now is as difficult as compiling all dependencies. But I prefer to postpone testing on Windows until current very linux-ish build scripts and behaviour are slightly adapted for cross-platform use and some dependencies are made optional.\r\n\r\n### Description of changes and new features added\r\n\r\n**Added OpenCV like formatted configuration log**\r\nhttps://travis-ci.org/BVLC/caffe/jobs/45700248\r\n\r\n**Added CaffeConfig.cmake generation for build/install cases.**\r\nThis allows you to connect Caffe to your application using CMake's `find_package(Caffe)`. For more detailed description see below.\r\n\r\n**BUILD_SHARED_LIB=ON (default) or OFF**\r\nbuild caffe as shared library. In CMake it not good practice to build both shared and static simultaneously. That’s why the switch.\r\n\r\n**CPU_ONLY = OFF(default) or ON**\r\nForces excluding CUDA support. Also Caffe will compile in `CPU_ONLY` mode if CUDA Toolkit is not installed or found by cmake. Before build please read chic configuration log dumped by cmake to control this case.\r\n\r\n**WITH_CUDNN = ON (default)**\r\nIf enabled and `cudnn` is found build with it, otherwise build without.\r\n\r\n**CUDA_ARCH_NAME=Auto(default), All, Fermi, Kepler, Maxwell, Manual**\r\nspecifies target GPU architecture, Selecting concrete value reduces CUDA code compilation time (for instance compilation for sm_20 and sm_30 is twice longer than just for one of them). In case of Auto, cmake will make an attempt to detect GPUS installed in your computer and compile only for them. In case of manual, new `CUDA_ARH_BIN/PTX` cmake variables are created where space separated list of architectures should be set.  Example,  `CUDA_ARH_BIN=”20 21(20) 50”`\r\n\r\n**BUILD_docs = OFF (default)**\r\n* If doxygen installed and found enables doc target. Use `make docs` to build and `make jekyll` to run web server. html docs are built in `<source folder>/doxygen`, and next symlink is created in `<source folder>/docs/doxygen`. Functionality from `scripts/gather_examples.sh` is now implemented in `cmake`, but `copy_notebook.py` is still required.\r\n* Source folder for generation is used because `.Doxyfile` contains relative paths and I prefer not to modify it now, but think generation in binary folder is better\r\n\r\n**BUILD_python = ON (default)**\r\nBuild python interface if all required dependencies found, otherwise excluded from build automatically\r\n\r\n**BUILD_matlab = OFF(default)**\r\nEnables building matlab interfaces. Currently it supports both **Octave** and **Matlab**. For Octave set `Octave_compiler` to mkoctfile if not found automatically. For Matlab specify `Matlab_DIR` or `Matlab_mex` and `Matlab_mexext` if again not found automatically. If both installed and found, to select which one to use, set `Matlab_build_mex_using=Matlab(default) or Octave`. Note matlab wrappers can only be built if `BUILD_SHARED_LIB=On`. On macos both doesn’t compile.\r\n\r\n**Proto-files**\r\nNow protobuf files **ARE NOT** copied to `<caffe_root>/include/caffe/proto` anymore. Instead they are generated to `<build_dir>/include/caffe/proto`. Know one may include old headers, but this is interest rates to payback of technical debt appeared due to incorrect original cmake scripts design. Also removed them from `.gitignore`\r\n\r\n**test.testbin**\r\n* Now *NO* `cmake_test_defines.hpp` and `sample_data_list.txt` are configured by cmake to source directory and *NO* `-DCMAKE_BUILD` definition added and all `*.in` templates were removed. This is because `make runtest` command is executed in source directory, and embedding absolute paths to test cpp-files is not required! Consider configure_file() to source folder as antipattern. However, one may return such embedding by uncommenting couple lines in `srcs/test/CMakeLists.txt`. \r\n* All garbage targets (one per each test file) were removed because they flood IDEs while compilation time reduction is controversial. I replaced them with option BUILD_only_tests that allows quickly include only selected tests. Example:  cmake `-DBUILD_only_tests==\"common,net,blob,im2col_kernel`\r\n\r\n**Yosemite support**\r\nI was able to compile using the Caffe instruction with libstdc++ and patching opencv as here https://github.com/bhack/opencv/commit/32f6e1a554dea1849ee3a53fea171cbd5969ef41.  `Accelerate.framework` support added. Matlab interface was failed to compile.\r\n\r\n**Temporary changes**\r\n* `make simlink` creates simlink `[caffe_root]/build -> cmake_build_directory`\r\n* Now all examples are built without `.bin` suffix and next simlink with `.bin` suffix created nearby. So that tutorials could work. Once naming standardized, should remove this.\r\n\r\n### Including Caffe in your CMake project via find_package()\r\n```\r\ngit clone git@github.com:BVLC/caffe.git. \r\ncd caffe && mkdir cmake_build && cd cmake_build\r\ncmake .. -DBUILD_SHARED_LIB=ON\r\n```\r\nVerify that cmake found everything and in proper locations.  After can run `make -j 12` right now or better do this:\r\n```\r\ncmake . -DCMAKE_BUILD_TYPE=Debug     # switch to debug\r\nmake -j 12 && make install           # installs by default to build_dir/install\r\ncmake . -DCMAKE_BUILD_TYPE=Release   # switch to release\r\nmake -j 12 && make install           # doesn’t overwrite debug install\r\nmake simlink\r\n```\r\nAfter the operations complete, caffe tutorials should work from caffe root directory. Let’s now see how to connect caffe to a C++ application that uses Caffe API with cmake. Prepare the following script:\r\n```cmake\r\ncmake_minimum_required(VERSION 2.8.8)\r\n\r\nfind_package(Caffe)\r\ninclude_directories(${Caffe_INCLUDE_DIRS})\r\nadd_definitions(${Caffe_DEFINITIONS})    # ex. -DCPU_ONLY\r\n\r\nadd_executable(caffeinated_application main.cpp)\r\ntarget_link_libraries(caffeinated_application ${Caffe_LIBRARIES})\r\n```\r\nRun CMake to configure this application and generate build scripts or IDE project. It will automatically find Caffe in its build directory and pick up all necessarily dependencies (includes, libraries, definitions) and application will compile without any additional actions. If you have several Caffe builds or for some reason Cmake wasn’t able find Caffe automatically, you may specify `Caffe_DIR=<path-to-caffe-build-dir>` in Cmake and this guarantees that everything will work.\r\n\r\nSpecified Caffe_DIR to build directory leads to always using a build configuration (say, Release or Debug) Caffe compiled last time for. If you set `Caffe_DIR=<caffe-install-dir>/share/Caffe` where both configurations have been installed, proper debug or release caffe binaries will be selected depending on for which configuration you compile your `caffeinated_application`.\r\n\r\n\r\n\r\nEnjoy!!\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/BVLC/caffe/issues/comments/69514536","html_url":"https://github.com/BVLC/caffe/pull/1667#issuecomment-69514536","issue_url":"https://api.github.com/repos/BVLC/caffe/issues/1667","id":69514536,"user":{"login":"bhack","id":1710528,"avatar_url":"https://avatars.githubusercontent.com/u/1710528?v=3","gravatar_id":"","url":"https://api.github.com/users/bhack","html_url":"https://github.com/bhack","followers_url":"https://api.github.com/users/bhack/followers","following_url":"https://api.github.com/users/bhack/following{/other_user}","gists_url":"https://api.github.com/users/bhack/gists{/gist_id}","starred_url":"https://api.github.com/users/bhack/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bhack/subscriptions","organizations_url":"https://api.github.com/users/bhack/orgs","repos_url":"https://api.github.com/users/bhack/repos","events_url":"https://api.github.com/users/bhack/events{/privacy}","received_events_url":"https://api.github.com/users/bhack/received_events","type":"User","site_admin":false},"created_at":"2015-01-11T22:16:48Z","updated_at":"2015-01-11T22:16:48Z","body":"Static library are directly supported in VS. Also dynamic one are supported with [some additional steps](http://www.mingw.org/wiki/msvc_and_mingw_dlls)"}}