From cafb37ec7e9364e0a645047d48b559cf2372fed6 Mon Sep 17 00:00:00 2001 From: David Stoup Date: Mon, 18 Nov 2019 09:27:05 -0500 Subject: [PATCH] Build protobuf statically. --- CMake/External_Caffe.cmake | 39 +++++++++++------------------ CMake/External_Caffe_Segnet.cmake | 41 +++++++++++-------------------- CMake/External_Protobuf.cmake | 31 +++++++++++++++++++++-- 3 files changed, 59 insertions(+), 52 deletions(-) diff --git a/CMake/External_Caffe.cmake b/CMake/External_Caffe.cmake index d74aa5a3..9488898f 100644 --- a/CMake/External_Caffe.cmake +++ b/CMake/External_Caffe.cmake @@ -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 diff --git a/CMake/External_Caffe_Segnet.cmake b/CMake/External_Caffe_Segnet.cmake index 1437a6cf..c8bc7640 100644 --- a/CMake/External_Caffe_Segnet.cmake +++ b/CMake/External_Caffe_Segnet.cmake @@ -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 @@ -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 ) @@ -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( diff --git a/CMake/External_Protobuf.cmake b/CMake/External_Protobuf.cmake index 1264ec44..7bcc0601 100644 --- a/CMake/External_Protobuf.cmake +++ b/CMake/External_Protobuf.cmake @@ -1,4 +1,5 @@ +set(protobuf_BUILD_SHARED_LIBS "OFF") if (Protobuf_SELECT_VERSION STREQUAL "3.9.0") ExternalProject_Add(Protobuf # PREFIX protobuf @@ -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) @@ -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}) ")