Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update protobuf3 and use CMake #561

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 15 additions & 24 deletions CMake/External_Caffe.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,33 +75,24 @@ endif()
set( CAFFE_PROTOBUF_ARGS )

if(fletch_ENABLE_Protobuf)
get_system_library_name( protobuf protobuf_libname )
get_system_library_name( protobuf-lite protobuf-lite_libname )
get_system_library_name( protoc protoc_libname )

set( CAFFE_PROTOBUF_ARGS
-DPROTOBUF_INCLUDE_DIR:PATH=${fletch_BUILD_INSTALL_PREFIX}/include
-DPROTOBUF_LIBRARY:PATH=${fletch_BUILD_INSTALL_PREFIX}/lib/${protobuf_libname}
-DPROTOBUF_LIBRARY_DEBUG:PATH=${fletch_BUILD_INSTALL_PREFIX}/lib/${protobuf_libname}
-DPROTOBUF_LITE_LIBRARY:PATH=${fletch_BUILD_INSTALL_PREFIX}/lib/${protobuf-lite_libname}
-DPROTOBUF_LITE_LIBRARY_DEBUG:PATH=${fletch_BUILD_INSTALL_PREFIX}/lib/${protobuf-lite_libname}
-DPROTOBUF_PROTOC_EXECUTABLE:PATH=${fletch_BUILD_INSTALL_PREFIX}/bin/protoc
-DPROTOBUF_PROTOC_LIBRARY:PATH=${fletch_BUILD_INSTALL_PREFIX}/lib/${protoc_libname}
-DPROTOBUF_PROTOC_LIBRARY_DEBUG:PATH=${fletch_BUILD_INSTALL_PREFIX}/lib/${protoc_libname}
)
set(protobuf_include ${fletch_BUILD_INSTALL_PREFIX}/include)
set(protobuf_exe ${fletch_BUILD_INSTALL_PREFIX}/bin/protoc)
else()
set( CAFFE_PROTOBUF_ARGS
-DPROTOBUF_INCLUDE_DIR:PATH=${PROTOBUF_INCLUDE_DIR}
-DPROTOBUF_LIBRARY:PATH=${PROTOBUF_LIBRARY}
-DPROTOBUF_LIBRARY_DEBUG:PATH=${PROTOBUF_LIBRARY_DEBUG}
-DPROTOBUF_LITE_LIBRARY:PATH=${PROTOBUF_LITE_LIBRARY}
-DPROTOBUF_LITE_LIBRARY_DEBUG:PATH=${PROTOBUF_LITE_LIBRARY_DEBUG}
-DPROTOBUF_PROTOC_EXECUTABLE:PATH=${PROTOBUF_PROTOC_EXECUTABLE}
-DPROTOBUF_PROTOC_LIBRARY:PATH=${PROTOBUF_PROTOC_LIBRARY}
-DPROTOBUF_PROTOC_LIBRARY_DEBUG:PATH=${PROTOBUF_PROTOC_LIBRARY_DEBUG}
)
set(protobuf_include ${PROTOBUF_INCLUDE_DIR})
set(protobuf_exe ${PROTOBUF_PROTOC_EXECUTABLE})
endif()

set( CAFFE_PROTOBUF_ARGS
-DPROTOBUF_INCLUDE_DIR:PATH=${protobuf_include}
-DPROTOBUF_LIBRARY:PATH=${PROTOBUF_LIBRARY}
-DPROTOBUF_LIBRARY_DEBUG:PATH=${PROTOBUF_LIBRARY}
-DPROTOBUF_LITE_LIBRARY:PATH=${PROTOBUF_LITE_LIBRARY}
-DPROTOBUF_LITE_LIBRARY_DEBUG:PATH=${PROTOBUF_LITE_LIBRARY}
-DPROTOBUF_PROTOC_EXECUTABLE:PATH=${protobuf_exe}
-DPROTOBUF_PROTOC_LIBRARY:PATH=${PROTOBUF_PROTOC_LIBRARY}/
-DPROTOBUF_PROTOC_LIBRARY_DEBUG:PATH=${PROTOBUF_PROTOC_LIBRARY}
)

if(fletch_ENABLE_OpenCV)
set( CAFFE_OPENCV_ARGS
-DOpenCV_DIR:PATH=${fletch_BUILD_PREFIX}/src/OpenCV-build
Expand Down
41 changes: 15 additions & 26 deletions CMake/External_Caffe_Segnet.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,24 @@ endif()
set( CAFFE_SEGNET_PROTOBUF_ARGS )

if(fletch_ENABLE_Protobuf)
get_system_library_name( protobuf protobuf_libname )
get_system_library_name( protobuf-lite protobuf-lite_libname )
get_system_library_name( protoc protoc_libname )

set( CAFFE_SEGNET_PROTOBUF_ARGS
-DPROTOBUF_INCLUDE_DIR:PATH=${fletch_BUILD_INSTALL_PREFIX}/include
-DPROTOBUF_LIBRARY:PATH=${fletch_BUILD_INSTALL_PREFIX}/lib/${protobuf_libname}
-DPROTOBUF_LIBRARY_DEBUG:PATH=${fletch_BUILD_INSTALL_PREFIX}/lib/${protobuf_libname}
-DPROTOBUF_LITE_LIBRARY:PATH=${fletch_BUILD_INSTALL_PREFIX}/lib/${protobuf-lite_libname}
-DPROTOBUF_LITE_LIBRARY_DEBUG:PATH=${fletch_BUILD_INSTALL_PREFIX}/lib/${protobuf-lite_libname}
-DPROTOBUF_PROTOC_EXECUTABLE:PATH=${fletch_BUILD_INSTALL_PREFIX}/bin/protoc
-DPROTOBUF_PROTOC_LIBRARY:PATH=${fletch_BUILD_INSTALL_PREFIX}/lib/${protoc_libname}
-DPROTOBUF_PROTOC_LIBRARY_DEBUG:PATH=${fletch_BUILD_INSTALL_PREFIX}/lib/${protoc_libname}
)
set(protobuf_include ${fletch_BUILD_INSTALL_PREFIX}/include)
set(protobuf_exe ${fletch_BUILD_INSTALL_PREFIX}/bin/protoc)
else()
set( CAFFE_SEGNET_PROTOBUF_ARGS
-DPROTOBUF_INCLUDE_DIR:PATH=${PROTOBUF_INCLUDE_DIR}
-DPROTOBUF_LIBRARY:PATH=${PROTOBUF_LIBRARY}
-DPROTOBUF_LIBRARY_DEBUG:PATH=${PROTOBUF_LIBRARY_DEBUG}
-DPROTOBUF_LITE_LIBRARY:PATH=${PROTOBUF_LITE_LIBRARY}
-DPROTOBUF_LITE_LIBRARY_DEBUG:PATH=${PROTOBUF_LITE_LIBRARY_DEBUG}
-DPROTOBUF_PROTOC_EXECUTABLE:PATH=${PROTOBUF_PROTOC_EXECUTABLE}
-DPROTOBUF_PROTOC_LIBRARY:PATH=${PROTOBUF_PROTOC_LIBRARY}
-DPROTOBUF_PROTOC_LIBRARY_DEBUG:PATH=${PROTOBUF_PROTOC_LIBRARY_DEBUG}
)
set(protobuf_include ${PROTOBUF_INCLUDE_DIR})
set(protobuf_exe ${PROTOBUF_PROTOC_EXECUTABLE})
endif()

set( CAFFE_SEGNET_PROTOBUF_ARGS
-DPROTOBUF_INCLUDE_DIR:PATH=${protobuf_include}
-DPROTOBUF_LIBRARY:PATH=${PROTOBUF_LIBRARY}
-DPROTOBUF_LIBRARY_DEBUG:PATH=${PROTOBUF_LIBRARY}
-DPROTOBUF_LITE_LIBRARY:PATH=${PROTOBUF_LITE_LIBRARY}
-DPROTOBUF_LITE_LIBRARY_DEBUG:PATH=${PROTOBUF_LITE_LIBRARY}
-DPROTOBUF_PROTOC_EXECUTABLE:PATH=${protobuf_exe}
-DPROTOBUF_PROTOC_LIBRARY:PATH=${PROTOBUF_PROTOC_LIBRARY}/
-DPROTOBUF_PROTOC_LIBRARY_DEBUG:PATH=${PROTOBUF_PROTOC_LIBRARY}
)

if(fletch_ENABLE_OpenCV)
set( CAFFE_SEGNET_OPENCV_ARGS
-DOpenCV_DIR:PATH=${fletch_BUILD_PREFIX}/src/OpenCV-build
Expand Down Expand Up @@ -176,7 +167,6 @@ if(fletch_ENABLE_HDF5)
get_system_library_name( hdf5_cpp_debug hdf5_cpp_libname )
get_system_library_name( hdf5_hl_cpp_debug hdf5_hl_cpp_libname )


else()

get_system_library_name( hdf5 hdf5_libname )
Expand Down Expand Up @@ -270,7 +260,6 @@ else()
)
endif()


set (Caffe_Segnet_PATCH_DIR "${fletch_SOURCE_DIR}/Patches/Caffe_Segnet/${Caffe_Segnet_version}")
if (EXISTS ${Caffe_Segnet_PATCH_DIR})
set(
Expand Down
102 changes: 67 additions & 35 deletions CMake/External_Protobuf.cmake
Original file line number Diff line number Diff line change
@@ -1,52 +1,84 @@
if (WIN32)
# Build option for windows not yet generated
message( FATAL_ERROR "Protobuf on windows not yet supported" )
endif()

# Check that python and protobuf versions are compatible
if(fletch_BUILD_WITH_PYTHON AND fletch_ENABLE_Protobuf)
# Note the python protobuf wrapper is not installed here.
# Instead it must be installed via `pip install protobuf`
if (${Protobuf_version} LESS 3.0 AND fletch_PYTHON_MAJOR_VERSION MATCHES "^3.*")
message(ERROR " Must use Protobuf >= 3.x with Python 3.x")
set(protobuf_BUILD_SHARED_LIBS "OFF")
if (Protobuf_SELECT_VERSION STREQUAL "3.9.0")
ExternalProject_Add(Protobuf
# PREFIX protobuf
URL ${Protobuf_url}
URL_MD5 ${Protobuf_md5}
SOURCE_SUBDIR ./cmake
${COMMON_EP_ARGS}
${COMMON_CMAKE_EP_ARGS}
CMAKE_ARGS
${COMMON_CMAKE_ARGS}
-Dprotobuf_BUILD_TESTS:BOOL=OFF
-Dprotobuf_BUILD_EXAMPLES:BOOL=${protobuf_BUILD_SHARED_LIBS}
-Dprotobuf_BUILD_SHARED_LIBS:BOOL=OFF
-Dprotobuf_MSVC_STATIC_RUNTIME:BOOL=OFF#Don't change MSVC runtime settings (/MD or /MT)
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=TRUE
-Dprotobuf_WITH_ZLIB:BOOL=OFF
)
elseif (NOT WIN32)
set (Protobuf_PATCH_DIR ${fletch_SOURCE_DIR}/Patches/Protobuf/${Protobuf_SELECT_VERSION})
if (EXISTS ${Protobuf_PATCH_DIR})
set(Protobuf_PATCH_COMMAND ${CMAKE_COMMAND}
-DProtobuf_PATCH_DIR=${Protobuf_PATCH_DIR}
-DProtobuf_SOURCE_DIR=${fletch_BUILD_PREFIX}/src/Protobuf
-P ${Protobuf_PATCH_DIR}/Patch.cmake)
else()
set(Protobuf_PATCH_COMMAND "")
endif()
endif()



set (Protobuf_PATCH_DIR ${fletch_SOURCE_DIR}/Patches/Protobuf/${Protobuf_SELECT_VERSION})
if (EXISTS ${Protobuf_PATCH_DIR})
set(Protobuf_PATCH_COMMAND ${CMAKE_COMMAND}
-DProtobuf_PATCH_DIR=${Protobuf_PATCH_DIR}
-DProtobuf_SOURCE_DIR=${fletch_BUILD_PREFIX}/src/Protobuf
-P ${Protobuf_PATCH_DIR}/Patch.cmake)
else()
set(Protobuf_PATCH_COMMAND "")
endif()


Fletch_Require_Make()
ExternalProject_Add(Protobuf
URL ${Protobuf_url}
URL_MD5 ${Protobuf_md5}
${COMMON_EP_ARGS}
PATCH_COMMAND ${CMAKE_COMMAND}
Fletch_Require_Make()
ExternalProject_Add(Protobuf
URL ${Protobuf_url}
URL_MD5 ${Protobuf_md5}
${COMMON_EP_ARGS}
PATCH_COMMAND ${CMAKE_COMMAND}
${Protobuf_PATCH_COMMAND}
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ./configure
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ./configure
--prefix=${fletch_BUILD_INSTALL_PREFIX}
BUILD_COMMAND ${MAKE_EXECUTABLE}
INSTALL_COMMAND ${MAKE_EXECUTABLE} install
)
BUILD_COMMAND ${MAKE_EXECUTABLE}
INSTALL_COMMAND ${MAKE_EXECUTABLE} install
)
else()
# Build option for windows not yet generated
message( FATAL_ERROR "Protobuf 2 not yet supported on windows" )
endif()

fletch_external_project_force_install(PACKAGE Protobuf)

set(Protobuf_ROOT ${fletch_BUILD_INSTALL_PREFIX} CACHE PATH "")

if(NOT protobuf_BUILD_SHARED_LIBS)
if(WIN32)
set(PROTOBUF_LIBRARY "${Protobuf_ROOT}/lib/libprotobuf.lib")
set(PROTOBUF_LITE_LIBRARY "${Protobuf_ROOT}/lib/libprotobuf-lite.lib")
set(PROTOBUF_PROTOC_LIBRARY "${Protobuf_ROOT}/lib/libprotc.lib")
else()
set(PROTOBUF_LIBRARY "${Protobuf_ROOT}/lib/libprotobuf.a")
set(PROTOBUF_LITE_LIBRARY "${Protobuf_ROOT}/lib/libprotobuf-lite.a")
set(PROTOBUF_PROTOC_LIBRARY "${Protobuf_ROOT}/lib/libprotc.a")
endif()
else()
if(WIN32)
set(PROTOBUF_LIBRARY "${Protobuf_ROOT}/lib/libprotobuf.lib")
set(PROTOBUF_LITE_LIBRARY "${Protobuf_ROOT}/lib/libprotobuf-lite.lib")
set(PROTOBUF_PROTOC_LIBRARY "${Protobuf_ROOT}/lib/libprotc.lib")
else()
set(PROTOBUF_LIBRARY "${Protobuf_ROOT}/lib/libprotobuf.so")
set(PROTOBUF_LITE_LIBRARY "${Protobuf_ROOT}/lib/libprotobuf-lite.so")
set(PROTOBUF_PROTOC_LIBRARY "${Protobuf_ROOT}/lib/libprotc.so")
endif()
endif()

file(APPEND ${fletch_CONFIG_INPUT} "
#######################################
# Google Protobuf
#######################################
set(Protobuf_ROOT \${fletch_ROOT})
set(PROTOBUF_LIBRARY \${PROTOBUF_LIBRARY})
set(PROTOBUF_LITE_LIBRARY \${PROTOBUF_LITE_LIBRARY})
set(PROTOBUF_PROTOC_LIBRARY \${PROTOBUF_PROTOC_LIBRARY})
")

31 changes: 14 additions & 17 deletions CMake/fletch-tarballs.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -490,25 +490,22 @@ if(NOT WIN32)
endif()

# Protobuf
if(NOT WIN32)
if (fletch_ENABLE_Protobuf OR fletch_ENABLE_ALL_PACKAGES OR AUTO_ENABLE_CAFFE_DEPENDENCY)
set(Protobuf_SELECT_VERSION "2.5.0" CACHE STRING "Select the version of ProtoBuf to build.")
set_property(CACHE Protobuf_SELECT_VERSION PROPERTY STRINGS "2.5.0" "3.4.1")
endif()

set(Protobuf_version ${Protobuf_SELECT_VERSION})
# WIN32 only supports the CMake version, 3.9.0
if (WIN32)
set(Protobuf_SELECT_VERSION "3.9.0" CACHE STRING "Select the version of ProtoBuf to build.")
else()
set(Protobuf_SELECT_VERSION "3.9.0" CACHE STRING "Select the version of ProtoBuf to build.")
set_property(CACHE Protobuf_SELECT_VERSION PROPERTY STRINGS "2.5.0" "3.9.0")
endif()

if (Protobuf_version VERSION_EQUAL 2.5.0)
set(Protobuf_url "https://github.com/google/protobuf/releases/download/v${Protobuf_version}/protobuf-${Protobuf_version}.tar.bz2" )
set(Protobuf_md5 "a72001a9067a4c2c4e0e836d0f92ece4" )
elseif (Protobuf_version VERSION_EQUAL 3.4.1)
set(Protobuf_url "https://github.com/google/protobuf/releases/download/v${Protobuf_version}/protobuf-cpp-${Protobuf_version}.tar.gz" )
set(Protobuf_md5 "74446d310ce79cf20bab3ffd0e8f8f8f" )
elseif(Protobuf_version)
message(ERROR "Protobuf Version ${Protobuf_version} Not Supported")
endif()
list(APPEND fletch_external_sources Protobuf )
if (Protobuf_SELECT_VERSION VERSION_EQUAL 2.5.0)
set(Protobuf_url "https://github.com/google/protobuf/releases/download/v${Protobuf_SELECT_VERSION}/protobuf-${Protobuf_SELECT_VERSION}.tar.bz2" )
set(Protobuf_md5 "a72001a9067a4c2c4e0e836d0f92ece4" )
elseif (Protobuf_SELECT_VERSION VERSION_EQUAL 3.9.0)
set(Protobuf_url "https://github.com/protocolbuffers/protobuf/releases/download/v${Protobuf_SELECT_VERSION}/protobuf-all-${Protobuf_SELECT_VERSION}.zip")
set(Protobuf_md5 "4f042c8b46823a69db3dcbc7381b73f4" )
endif()
list(APPEND fletch_external_sources Protobuf )

# Caffe
set(InternalCaffe True)
Expand Down