Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
c3aa4c26
Commit
c3aa4c26
authored
Oct 14, 2015
by
Konstantin Podsvirov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved SHARED build from CMake project
parent
f397ede7
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
50 additions
and
30 deletions
+50
-30
.gitignore
.gitignore
+1
-0
appveyor.bat
appveyor.bat
+2
-3
CMakeLists.txt
cmake/CMakeLists.txt
+26
-22
libprotobuf-lite.cmake
cmake/libprotobuf-lite.cmake
+7
-2
libprotobuf.cmake
cmake/libprotobuf.cmake
+7
-2
libprotoc.cmake
cmake/libprotoc.cmake
+7
-1
No files found.
.gitignore
View file @
c3aa4c26
...
...
@@ -81,6 +81,7 @@ javanano/target
# Windows native output.
cmake/build
build_msvc
# NuGet packages: we want the repository configuration, but not the
# packages themselves.
...
...
appveyor.bat
View file @
c3aa4c26
...
...
@@ -10,7 +10,7 @@ goto :error
echo Building C++
mkdir build_msvc
cd build_msvc
cmake -G "%generator%" -DBUILD_SHARED_LIBS=%BUILD_DLL% ../cmake
cmake -G "%generator%" -D
protobuf_
BUILD_SHARED_LIBS=%BUILD_DLL% ../cmake
msbuild protobuf.sln /p:Platform=%vcplatform% /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" || goto error
cd %configuration%
tests.exe || goto error
...
...
@@ -26,4 +26,4 @@ goto :EOF
:error
echo Failed!
EXIT /b %ERRORLEVEL%
\ No newline at end of file
EXIT /b %ERRORLEVEL%
cmake/CMakeLists.txt
View file @
c3aa4c26
...
...
@@ -10,7 +10,12 @@ cmake_policy(SET CMP0022 NEW)
# Options
option
(
protobuf_VERBOSE
"Enable for verbose output"
OFF
)
option
(
protobuf_BUILD_TESTS
"Build tests"
ON
)
option
(
protobuf_BUILD_SHARED_LIBS
"Build Shared Libraries"
OFF
)
if
(
BUILD_SHARED_LIBS
)
set
(
protobuf_BUILD_SHARED_LIBS_DEFAULT ON
)
else
(
BUILD_SHARED_LIBS
)
set
(
protobuf_BUILD_SHARED_LIBS_DEFAULT OFF
)
endif
(
BUILD_SHARED_LIBS
)
option
(
protobuf_BUILD_SHARED_LIBS
"Build Shared Libraries"
${
protobuf_BUILD_SHARED_LIBS_DEFAULT
}
)
option
(
protobuf_MSVC_STATIC_RUNTIME
"Link static runtime libraries"
ON
)
if
(
MSVC
)
set
(
protobuf_WITH_ZLIB_DEFAULT OFF
)
...
...
@@ -89,29 +94,28 @@ if (HAVE_ZLIB)
add_definitions
(
-DHAVE_ZLIB
)
endif
(
HAVE_ZLIB
)
if
(
MSVC
)
if
(
protobuf_BUILD_SHARED_LIBS
)
add_definitions
(
-DPROTOBUF_USE_DLLS
)
else
(
protobuf_BUILD_SHARED_LIBS
)
# In case we are building static libraries, link also the runtime library statically
# so that MSVCR*.DLL is not required at runtime.
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
# This is achieved by replacing msvc option /MD with /MT and /MDd with /MTd
# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
if
(
protobuf_MSVC_STATIC_RUNTIME
)
foreach
(
flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if
(
${
flag_var
}
MATCHES
"/MD"
)
string
(
REGEX REPLACE
"/MD"
"/MT"
${
flag_var
}
"
${${
flag_var
}}
"
)
endif
(
${
flag_var
}
MATCHES
"/MD"
)
endforeach
(
flag_var
)
endif
(
protobuf_MSVC_STATIC_RUNTIME
)
endif
(
protobuf_BUILD_SHARED_LIBS
)
add_definitions
(
/wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305
)
endif
(
MSVC
)
if
(
protobuf_BUILD_SHARED_LIBS
)
set
(
protobuf_SHARED_OR_STATIC
"SHARED"
)
else
(
protobuf_BUILD_SHARED_LIBS
)
set
(
protobuf_SHARED_OR_STATIC
"STATIC"
)
# In case we are building static libraries, link also the runtime library statically
# so that MSVCR*.DLL is not required at runtime.
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx
# This is achieved by replacing msvc option /MD with /MT and /MDd with /MTd
# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F
if
(
MSVC AND protobuf_MSVC_STATIC_RUNTIME
)
foreach
(
flag_var
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if
(
${
flag_var
}
MATCHES
"/MD"
)
string
(
REGEX REPLACE
"/MD"
"/MT"
${
flag_var
}
"
${${
flag_var
}}
"
)
endif
(
${
flag_var
}
MATCHES
"/MD"
)
endforeach
(
flag_var
)
endif
(
MSVC AND protobuf_MSVC_STATIC_RUNTIME
)
endif
(
protobuf_BUILD_SHARED_LIBS
)
if
(
MSVC
)
add_definitions
(
/wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305
)
string
(
REPLACE
"/"
"
\\
"
PROTOBUF_SOURCE_WIN32_PATH
${
protobuf_SOURCE_DIR
}
)
string
(
REPLACE
"/"
"
\\
"
PROTOBUF_BINARY_WIN32_PATH
${
protobuf_BINARY_DIR
}
)
configure_file
(
extract_includes.bat.in extract_includes.bat
)
...
...
cmake/libprotobuf-lite.cmake
View file @
c3aa4c26
...
...
@@ -24,10 +24,15 @@ set(libprotobuf_lite_files
${
protobuf_source_dir
}
/src/google/protobuf/wire_format_lite.cc
)
add_library
(
libprotobuf-lite
${
libprotobuf_lite_files
}
)
add_library
(
libprotobuf-lite
${
protobuf_SHARED_OR_STATIC
}
${
libprotobuf_lite_files
}
)
target_link_libraries
(
libprotobuf-lite
${
CMAKE_THREAD_LIBS_INIT
}
)
target_include_directories
(
libprotobuf-lite PUBLIC
${
protobuf_source_dir
}
/src
)
if
(
MSVC AND protobuf_BUILD_SHARED_LIBS
)
target_compile_definitions
(
libprotobuf-lite
PUBLIC PROTOBUF_USE_DLLS
PRIVATE LIBPROTOBUF_EXPORTS
)
endif
()
set_target_properties
(
libprotobuf-lite PROPERTIES
COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS
OUTPUT_NAME
${
LIB_PREFIX
}
protobuf-lite
DEBUG_POSTFIX
"
${
protobuf_DEBUG_POSTFIX
}
"
)
cmake/libprotobuf.cmake
View file @
c3aa4c26
...
...
@@ -53,10 +53,15 @@ set(libprotobuf_files
${
protobuf_source_dir
}
/src/google/protobuf/wrappers.pb.cc
)
add_library
(
libprotobuf
${
libprotobuf_lite_files
}
${
libprotobuf_files
}
)
add_library
(
libprotobuf
${
protobuf_SHARED_OR_STATIC
}
${
libprotobuf_lite_files
}
${
libprotobuf_files
}
)
target_link_libraries
(
libprotobuf
${
CMAKE_THREAD_LIBS_INIT
}
${
ZLIB_LIBRARIES
}
)
target_include_directories
(
libprotobuf PUBLIC
${
protobuf_source_dir
}
/src
)
if
(
MSVC AND protobuf_BUILD_SHARED_LIBS
)
target_compile_definitions
(
libprotobuf
PUBLIC PROTOBUF_USE_DLLS
PRIVATE LIBPROTOBUF_EXPORTS
)
endif
()
set_target_properties
(
libprotobuf PROPERTIES
COMPILE_DEFINITIONS LIBPROTOBUF_EXPORTS
OUTPUT_NAME
${
LIB_PREFIX
}
protobuf
DEBUG_POSTFIX
"
${
protobuf_DEBUG_POSTFIX
}
"
)
cmake/libprotoc.cmake
View file @
c3aa4c26
...
...
@@ -89,8 +89,14 @@ set(libprotoc_files
${
protobuf_source_dir
}
/src/google/protobuf/compiler/zip_writer.cc
)
add_library
(
libprotoc
${
libprotoc_files
}
)
add_library
(
libprotoc
${
protobuf_SHARED_OR_STATIC
}
${
libprotoc_files
}
)
target_link_libraries
(
libprotoc libprotobuf
)
if
(
MSVC AND protobuf_BUILD_SHARED_LIBS
)
target_compile_definitions
(
libprotoc
PUBLIC PROTOBUF_USE_DLLS
PRIVATE LIBPROTOC_EXPORTS
)
endif
()
set_target_properties
(
libprotoc PROPERTIES
COMPILE_DEFINITIONS LIBPROTOC_EXPORTS
OUTPUT_NAME
${
LIB_PREFIX
}
protoc
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment