diff --git a/Makefile b/Makefile index 52d5a8b1ded..fb5f898b21a 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,19 @@ -# This makefile does nothing but delegating the actual compilation to build.py. +# This makefile does nothing but delegating the actual building to cmake. all: @mkdir -p build && cd build && cmake .. && make -#android: -# @python brewtool/build_android.py build +local: + @./scripts/build_local.sh -clean: - @rm -r build/ +android: + @./scripts/build_android.sh -#test: -# @python brewtool/build.py test +ios: + @./scripts/build_ios.sh -#lint: -# @find caffe2 -type f -exec python brewtool/cpplint.py {} \; +clean: # This will remove ALL build folders. + @rm -r build*/ linecount: @cloc --read-lang-def=caffe.cloc caffe2 || \ diff --git a/caffe2/CMakeLists.txt b/caffe2/CMakeLists.txt index 89ea255a243..a09b272a039 100644 --- a/caffe2/CMakeLists.txt +++ b/caffe2/CMakeLists.txt @@ -118,6 +118,10 @@ endif() if (BUILD_PYTHON) # ---[ Python. + # ---[ Apple specific + if (APPLE) + set(CMAKE_SHARED_LIBRARY_SUFFIX ".so") + endif() add_library(caffe2_pybind11_state SHARED ${Caffe2_CPU_PYTHON_SRCS}) add_dependencies(caffe2_pybind11_state ${Caffe2_MAIN_LIBS_ORDER}) set_target_properties(caffe2_pybind11_state PROPERTIES PREFIX "") diff --git a/cmake/ProtoBuf.cmake b/cmake/ProtoBuf.cmake index 39335b8929f..7ae0a4a295d 100644 --- a/cmake/ProtoBuf.cmake +++ b/cmake/ProtoBuf.cmake @@ -1,30 +1,43 @@ # Finds Google Protocol Buffers library and compilers and extends # the standard cmake script with version and python generation support - -if (ANDROID OR IOS OR WIN32) +function(custom_protobuf_find) option(protobuf_BUILD_SHARED_LIBS "" OFF) option(protobuf_BUILD_TESTS "" OFF) option(protobuf_BUILD_EXAMPLES "" OFF) if (APPLE) # Protobuf generated files triggers a deprecated atomic operation warning # so we turn it off here. - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated-declarations" PARENT_SCOPE) endif() add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/protobuf/cmake) include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third_party/protobuf/src) list(APPEND Caffe2_DEPENDENCY_LIBS libprotobuf) + set(Caffe2_DEPENDENCY_LIBS ${Caffe2_DEPENDENCY_LIBS} PARENT_SCOPE) if(NOT EXISTS ${PROTOBUF_PROTOC_EXECUTABLE}) message(FATAL_ERROR - "To build with Android/iOS/Windows, you will need to manually " - "specify a PROTOBUF_PROTOC_EXECUTABLE. See " - "scripts/build_host_protoc.{sh,bat} for more details.") + "To build protobufs locally (required for Android/iOS/Windows), " + "you will need to manually specify a PROTOBUF_PROTOC_EXECUTABLE. " + "See scripts/build_host_protoc.{sh,bat} for more details.") else() message(STATUS "Using protobuf compiler ${PROTOBUF_PROTOC_EXECUTABLE}.") endif() + set(Protobuf_FOUND TRUE PARENT_SCOPE) +endfunction() + +if (ANDROID OR IOS OR WIN32) + custom_protobuf_find() else() - find_package( Protobuf REQUIRED ) - list(APPEND Caffe2_DEPENDENCY_LIBS ${PROTOBUF_LIBRARIES}) - include_directories(SYSTEM ${PROTOBUF_INCLUDE_DIR}) + find_package( Protobuf ) + if ( NOT (Protobuf_FOUND OR PROTOBUF_FOUND) ) + custom_protobuf_find() + else() + list(APPEND Caffe2_DEPENDENCY_LIBS ${PROTOBUF_LIBRARIES}) + include_directories(SYSTEM ${PROTOBUF_INCLUDE_DIR}) + endif() +endif() + +if (NOT (Protobuf_FOUND OR PROTOBUF_FOUND) ) + message(FATAL_ERROR "Could not find Protobuf or compile local version.") endif() # place where to generate protobuf sources diff --git a/scripts/build_local.sh b/scripts/build_local.sh new file mode 100755 index 00000000000..4e0d62b7e43 --- /dev/null +++ b/scripts/build_local.sh @@ -0,0 +1,30 @@ +#!/bin/bash +############################################################################## +# Example command to build Caffe2 locally without installing many dependencies +############################################################################## +# +# This script builds protoc locally and then sets the appropriate dependencies +# to remove the need for many external dependencies. +# + +CAFFE2_ROOT="$( cd "$(dirname "$0")"/.. ; pwd -P)" +echo "Caffe2 codebase root is: $CAFFE2_ROOT" + +# We are going to build the target into build. +BUILD_ROOT=$CAFFE2_ROOT/build +mkdir -p $BUILD_ROOT +echo "Build Caffe2 into: $BUILD_ROOT" + +# Build protobuf from third_party so we have a host protoc binary. +echo "Building protoc" +$CAFFE2_ROOT/scripts/build_host_protoc.sh || exit 1 + +# Now, actually build the target. +echo "Building caffe2" +cd $BUILD_ROOT + +cmake .. \ + -DPROTOBUF_PROTOC_EXECUTABLE=$CAFFE2_ROOT/build_host_protoc/bin/protoc \ + -DBUILD_SHARED_LIBS=OFF \ + || exit 1 +make diff --git a/scripts/start_ipython_notebook.sh b/scripts/start_ipython_notebook.sh new file mode 100755 index 00000000000..324b87f0b40 --- /dev/null +++ b/scripts/start_ipython_notebook.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh +# This script simply starts the ipython notebook and allows all network machines +# to access it. + +# Use the following command for very verbose prints. +# GLOG_logtostderr=1 GLOG_v=1 PYTHONPATH=../../../build:$PYTHONPATH ipython notebook --ip='*' + +# Use the following command for a normal run. +PYTHONPATH=build:$PYTHONPATH ipython notebook --notebook-dir=caffe2/python/tutorial --ip='*'