Unify versions across setup.py, libtorch, and libcaffe2 (#12053)

Summary:
This unifies our versions across setup.py, libtorch, and libcaffe2. CMake has a default version (bumped to 1.0.0) that can be overridden by setup.py. The versions are also printed as a part of cmake/Summary.cmake to make sure they are correct.

cc Yangqing ezyang soumith goldsborough pjh5
Pull Request resolved: https://github.com/pytorch/pytorch/pull/12053

Differential Revision: D10041878

Pulled By: orionr

fbshipit-source-id: a98a01771f6c008d1016ab63ab785c3a88c3ddb0
This commit is contained in:
Orion Reblitz-Richardson
2018-09-26 08:43:38 -07:00
committed by Facebook Github Bot
parent c8a0b11b7f
commit 02d7c88fa4
7 changed files with 36 additions and 17 deletions

View File

@ -10,12 +10,6 @@ if (NOT MSVC)
set(CMAKE_C_STANDARD 11)
endif()
set(CAFFE2_VERSION_MAJOR 0)
set(CAFFE2_VERSION_MINOR 8)
set(CAFFE2_VERSION_PATCH 2)
set(CAFFE2_VERSION
"${CAFFE2_VERSION_MAJOR}.${CAFFE2_VERSION_MINOR}.${CAFFE2_VERSION_PATCH}")
# One variable that determines whether the current cmake process is being run
# with the main Caffe2 library. This is useful for building modules - if
# modules are built with the main Caffe2 library then one does not need to do
@ -139,6 +133,22 @@ if (ANDROID OR IOS)
set(BUILD_ATEN_MOBILE ON)
endif()
# ---[ Utils
# TODO: merge the following 3 files into cmake/public/utils.cmake.
include(cmake/Utils.cmake)
include(cmake/public/utils.cmake)
# ---[ Version numbers for generated libraries
set(TORCH_DEFAULT_VERSION "1.0.0")
set(TORCH_BUILD_VERSION "${TORCH_DEFAULT_VERSION}" CACHE STRING "Torch build version")
if (NOT TORCH_BUILD_VERSION)
# An empty string was specified so force version to the default
set(TORCH_BUILD_VERSION "${TORCH_DEFAULT_VERSION}"
CACHE STRING "Torch build version" FORCE)
endif()
caffe2_parse_version_str(TORCH ${TORCH_BUILD_VERSION})
caffe2_parse_version_str(CAFFE2 ${TORCH_BUILD_VERSION})
# ---[ CMake scripts + modules
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
@ -165,11 +175,6 @@ include(cmake/MiscCheck.cmake)
# External projects
include(ExternalProject)
# ---[ Utils
# TODO: merge the following 3 files into cmake/public/utils.cmake.
include(cmake/Utils.cmake)
include(cmake/public/utils.cmake)
# ---[ Dependencies
include(cmake/Dependencies.cmake)

View File

@ -17,6 +17,8 @@ function (caffe2_print_configuration_summary)
message(STATUS " CMAKE_INSTALL_PREFIX : ${CMAKE_INSTALL_PREFIX}")
message(STATUS "")
message(STATUS " TORCH_VERSION : ${TORCH_VERSION}")
message(STATUS " CAFFE2_VERSION : ${CAFFE2_VERSION}")
message(STATUS " BUILD_ATEN_MOBILE : ${BUILD_ATEN_MOBILE}")
message(STATUS " BUILD_BINARY : ${BUILD_BINARY}")
message(STATUS " BUILD_CUSTOM_PROTOBUF : ${BUILD_CUSTOM_PROTOBUF}")

View File

@ -113,6 +113,21 @@ function(caffe_parse_header_single_define LIBNAME HDR_PATH VARNAME)
endif()
endfunction()
################################################################################################
# Parses a version string that might have values beyond major, minor, and patch
# and set version variables for the library.
# Usage:
# caffe2_parse_version_str(<library_name> <version_string>)
function(caffe2_parse_version_str LIBNAME VERSIONSTR)
string(REGEX REPLACE "^([0-9]+).*$" "\\1" ${LIBNAME}_VERSION_MAJOR "${VERSIONSTR}")
string(REGEX REPLACE "^[0-9]+\\.([0-9]+).*$" "\\1" ${LIBNAME}_VERSION_MINOR "${VERSIONSTR}")
string(REGEX REPLACE "[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" ${LIBNAME}_VERSION_PATCH "${VERSIONSTR}")
set(${LIBNAME}_VERSION_MAJOR ${${LIBNAME}_VERSION_MAJOR} ${ARGN} PARENT_SCOPE)
set(${LIBNAME}_VERSION_MINOR ${${LIBNAME}_VERSION_MINOR} ${ARGN} PARENT_SCOPE)
set(${LIBNAME}_VERSION_PATCH ${${LIBNAME}_VERSION_PATCH} ${ARGN} PARENT_SCOPE)
set(${LIBNAME}_VERSION "${${LIBNAME}_VERSION_MAJOR}.${${LIBNAME}_VERSION_MINOR}.${${LIBNAME}_VERSION_PATCH}" PARENT_SCOPE)
endfunction()
##############################################################################
# Helper function to automatically generate __init__.py files where python
# sources reside but there are no __init__.py present.

View File

@ -346,6 +346,7 @@ def build_libs(libs):
build_libs_cmd = ['bash', os.path.join('..', 'tools', 'build_pytorch_libs.sh')]
my_env = os.environ.copy()
my_env["PYTORCH_PYTHON"] = sys.executable
my_env["PYTORCH_BUILD_VERSION"] = version
my_env["CMAKE_PREFIX_PATH"] = full_site_packages
my_env["NUM_JOBS"] = str(NUM_JOBS)
my_env["ONNX_NAMESPACE"] = ONNX_NAMESPACE

View File

@ -172,6 +172,7 @@ goto:eof
cd build
cmake .. %CMAKE_GENERATOR_COMMAND% ^
-DCMAKE_BUILD_TYPE=%BUILD_TYPE% ^
-DTORCH_BUILD_VERSION="%PYTORCH_BUILD_VERSION%" ^
-DBUILD_TORCH="%BUILD_TORCH%" ^
-DNVTOOLEXT_HOME="%NVTOOLEXT_HOME%" ^
-DNO_API=ON ^

View File

@ -273,6 +273,7 @@ function build_caffe2() {
-DCMAKE_INSTALL_MESSAGE="LAZY" \
-DPYTHON_EXECUTABLE=$PYTORCH_PYTHON \
-DBUILDING_WITH_TORCH_LIBS=ON \
-DTORCH_BUILD_VERSION="$PYTORCH_BUILD_VERSION" \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DBUILD_TORCH=$BUILD_TORCH \
-DBUILD_PYTHON=$BUILD_PYTHON \

View File

@ -12,12 +12,6 @@ endif()
option(BUILD_TEST "Build torch test binaries" ON)
option(TORCH_STATIC "Build libtorch.a rather than libtorch.so" OFF)
# TODO: Unify with version from setup.py
set(TORCH_VERSION_MAJOR 0)
set(TORCH_VERSION_MINOR 4)
set(TORCH_VERSION_PATCH 1)
set(TORCH_VERSION "${TORCH_VERSION_MAJOR}.${TORCH_VERSION_MINOR}.${TORCH_VERSION_PATCH}")
set(TORCH_SRC_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(TORCH_ROOT "${TORCH_SRC_DIR}/..")