mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Added local build and apple fix for generating .so files
Summary: Closes https://github.com/caffe2/caffe2/pull/147 Reviewed By: bwasti Differential Revision: D4564024 Pulled By: JoelMarcey fbshipit-source-id: 526a5ab700f9356a3c93a6c64dc38e44a173559c
This commit is contained in:
committed by
Facebook Github Bot
parent
7d9a0a41fd
commit
7ee9984556
18
Makefile
18
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:
|
all:
|
||||||
@mkdir -p build && cd build && cmake .. && make
|
@mkdir -p build && cd build && cmake .. && make
|
||||||
|
|
||||||
#android:
|
local:
|
||||||
# @python brewtool/build_android.py build
|
@./scripts/build_local.sh
|
||||||
|
|
||||||
clean:
|
android:
|
||||||
@rm -r build/
|
@./scripts/build_android.sh
|
||||||
|
|
||||||
#test:
|
ios:
|
||||||
# @python brewtool/build.py test
|
@./scripts/build_ios.sh
|
||||||
|
|
||||||
#lint:
|
clean: # This will remove ALL build folders.
|
||||||
# @find caffe2 -type f -exec python brewtool/cpplint.py {} \;
|
@rm -r build*/
|
||||||
|
|
||||||
linecount:
|
linecount:
|
||||||
@cloc --read-lang-def=caffe.cloc caffe2 || \
|
@cloc --read-lang-def=caffe.cloc caffe2 || \
|
||||||
|
@ -118,6 +118,10 @@ endif()
|
|||||||
|
|
||||||
if (BUILD_PYTHON)
|
if (BUILD_PYTHON)
|
||||||
# ---[ Python.
|
# ---[ Python.
|
||||||
|
# ---[ Apple specific
|
||||||
|
if (APPLE)
|
||||||
|
set(CMAKE_SHARED_LIBRARY_SUFFIX ".so")
|
||||||
|
endif()
|
||||||
add_library(caffe2_pybind11_state SHARED ${Caffe2_CPU_PYTHON_SRCS})
|
add_library(caffe2_pybind11_state SHARED ${Caffe2_CPU_PYTHON_SRCS})
|
||||||
add_dependencies(caffe2_pybind11_state ${Caffe2_MAIN_LIBS_ORDER})
|
add_dependencies(caffe2_pybind11_state ${Caffe2_MAIN_LIBS_ORDER})
|
||||||
set_target_properties(caffe2_pybind11_state PROPERTIES PREFIX "")
|
set_target_properties(caffe2_pybind11_state PROPERTIES PREFIX "")
|
||||||
|
@ -1,30 +1,43 @@
|
|||||||
# Finds Google Protocol Buffers library and compilers and extends
|
# Finds Google Protocol Buffers library and compilers and extends
|
||||||
# the standard cmake script with version and python generation support
|
# the standard cmake script with version and python generation support
|
||||||
|
function(custom_protobuf_find)
|
||||||
if (ANDROID OR IOS OR WIN32)
|
|
||||||
option(protobuf_BUILD_SHARED_LIBS "" OFF)
|
option(protobuf_BUILD_SHARED_LIBS "" OFF)
|
||||||
option(protobuf_BUILD_TESTS "" OFF)
|
option(protobuf_BUILD_TESTS "" OFF)
|
||||||
option(protobuf_BUILD_EXAMPLES "" OFF)
|
option(protobuf_BUILD_EXAMPLES "" OFF)
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
# Protobuf generated files triggers a deprecated atomic operation warning
|
# Protobuf generated files triggers a deprecated atomic operation warning
|
||||||
# so we turn it off here.
|
# 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()
|
endif()
|
||||||
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/protobuf/cmake)
|
add_subdirectory(${PROJECT_SOURCE_DIR}/third_party/protobuf/cmake)
|
||||||
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third_party/protobuf/src)
|
include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third_party/protobuf/src)
|
||||||
list(APPEND Caffe2_DEPENDENCY_LIBS libprotobuf)
|
list(APPEND Caffe2_DEPENDENCY_LIBS libprotobuf)
|
||||||
|
set(Caffe2_DEPENDENCY_LIBS ${Caffe2_DEPENDENCY_LIBS} PARENT_SCOPE)
|
||||||
if(NOT EXISTS ${PROTOBUF_PROTOC_EXECUTABLE})
|
if(NOT EXISTS ${PROTOBUF_PROTOC_EXECUTABLE})
|
||||||
message(FATAL_ERROR
|
message(FATAL_ERROR
|
||||||
"To build with Android/iOS/Windows, you will need to manually "
|
"To build protobufs locally (required for Android/iOS/Windows), "
|
||||||
"specify a PROTOBUF_PROTOC_EXECUTABLE. See "
|
"you will need to manually specify a PROTOBUF_PROTOC_EXECUTABLE. "
|
||||||
"scripts/build_host_protoc.{sh,bat} for more details.")
|
"See scripts/build_host_protoc.{sh,bat} for more details.")
|
||||||
else()
|
else()
|
||||||
message(STATUS "Using protobuf compiler ${PROTOBUF_PROTOC_EXECUTABLE}.")
|
message(STATUS "Using protobuf compiler ${PROTOBUF_PROTOC_EXECUTABLE}.")
|
||||||
endif()
|
endif()
|
||||||
|
set(Protobuf_FOUND TRUE PARENT_SCOPE)
|
||||||
|
endfunction()
|
||||||
|
|
||||||
|
if (ANDROID OR IOS OR WIN32)
|
||||||
|
custom_protobuf_find()
|
||||||
else()
|
else()
|
||||||
find_package( Protobuf REQUIRED )
|
find_package( Protobuf )
|
||||||
list(APPEND Caffe2_DEPENDENCY_LIBS ${PROTOBUF_LIBRARIES})
|
if ( NOT (Protobuf_FOUND OR PROTOBUF_FOUND) )
|
||||||
include_directories(SYSTEM ${PROTOBUF_INCLUDE_DIR})
|
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()
|
endif()
|
||||||
|
|
||||||
# place where to generate protobuf sources
|
# place where to generate protobuf sources
|
||||||
|
30
scripts/build_local.sh
Executable file
30
scripts/build_local.sh
Executable file
@ -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
|
9
scripts/start_ipython_notebook.sh
Executable file
9
scripts/start_ipython_notebook.sh
Executable file
@ -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='*'
|
Reference in New Issue
Block a user