Skip to content

Commit

Permalink
Build protobuf statically.
Browse files Browse the repository at this point in the history
  • Loading branch information
dstoup committed Nov 18, 2019
1 parent 7c0f237 commit cafb37e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 52 deletions.
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
31 changes: 29 additions & 2 deletions CMake/External_Protobuf.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

set(protobuf_BUILD_SHARED_LIBS "OFF")
if (Protobuf_SELECT_VERSION STREQUAL "3.9.0")
ExternalProject_Add(Protobuf
# PREFIX protobuf
Expand All @@ -10,9 +11,10 @@ if (Protobuf_SELECT_VERSION STREQUAL "3.9.0")
CMAKE_ARGS
${COMMON_CMAKE_ARGS}
-Dprotobuf_BUILD_TESTS:BOOL=OFF
-Dprotobuf_BUILD_EXAMPLES:BOOL=OFF
-Dprotobuf_BUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-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)
Expand Down Expand Up @@ -48,10 +50,35 @@ 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})
")

0 comments on commit cafb37e

Please sign in to comment.