@ -15,6 +15,10 @@ endif ()
if ( POLICY CMP0048 )
if ( POLICY CMP0048 )
cmake_policy ( SET CMP0048 NEW )
cmake_policy ( SET CMP0048 NEW )
endif ( )
endif ( )
# MSVC r u n t i m e l i b r a r y f l a g s a r e s e l e c t e d b y a n a b s t r a c t i o n .
if ( POLICY CMP0091 )
cmake_policy ( SET CMP0091 NEW )
endif ( )
# P r o j e c t
# P r o j e c t
project ( protobuf C CXX )
project ( protobuf C CXX )
@ -176,20 +180,28 @@ if (protobuf_BUILD_SHARED_LIBS)
set ( protobuf_SHARED_OR_STATIC "SHARED" )
set ( protobuf_SHARED_OR_STATIC "SHARED" )
else ( protobuf_BUILD_SHARED_LIBS )
else ( protobuf_BUILD_SHARED_LIBS )
set ( protobuf_SHARED_OR_STATIC "STATIC" )
set ( protobuf_SHARED_OR_STATIC "STATIC" )
# I n c a s e w e a r e b u i l d i n g s t a t i c l i b r a r i e s , l i n k a l s o t h e r u n t i m e l i b r a r y s t a t i c a l l y
# T h e C M A K E _ < L A N G > _FLAGS ( _<BUILD_TYPE> ) ? i s m e a n t t o b e u s e r c o n t r o l l e d .
# s o t h a t M S V C R * . D L L i s n o t r e q u i r e d a t r u n t i m e .
# P r i o r t o C M a k e 3 . 1 5 , t h e MSVC r u n t i m e l i b r a r y w a s p u s h e d i n t o t h e s a m e f l a g s
# h t t p s : / / m s d n . m i c r o s o f t . c o m / e n - u s / l i b r a r y / 2 k z t 1 w y 3 . a s p x
# m a k i n g p r o g r a m m a t i c c o n t r o l d i f f i c u l t . P r e f e r t h e f u n c t i o n a l i t y i n n e w e r
# T h i s i s a c h i e v e d b y r e p l a c i n g m s v c o p t i o n / M D w i t h / M T a n d / M D d w i t h / M T d
# C M a k e v e r s i o n s w h e n a v a i l a b l e .
# h t t p : / / w w w . c m a k e . o r g / W i k i / C M a k e _ F A Q # H o w _ c a n _ I _ b u i l d _ m y _ M S V C _ a p p l i c a t i o n _ w i t h _ a _ s t a t i c _ r u n t i m e . 3 F
if ( CMAKE_VERSION VERSION_GREATER_EQUAL 3.15 )
if ( MSVC AND protobuf_MSVC_STATIC_RUNTIME )
set ( CMAKE_MSVC_RUNTIME_LIBRARY MultiThreaded $< $<CONFIG:Debug > :Debug> )
foreach ( flag_var
else ( )
C M A K E _ C X X _ F L A G S C M A K E _ C X X _ F L A G S _ D E B U G C M A K E _ C X X _ F L A G S _ R E L E A S E
# I n c a s e w e a r e b u i l d i n g s t a t i c l i b r a r i e s , l i n k a l s o t h e r u n t i m e l i b r a r y s t a t i c a l l y
C M A K E _ C X X _ F L A G S _ M I N S I Z E R E L C M A K E _ C X X _ F L A G S _ R E L W I T H D E B I N F O )
# s o t h a t M S V C R * . D L L i s n o t r e q u i r e d a t r u n t i m e .
if ( ${ flag_var } MATCHES "/MD" )
# h t t p s : / / m s d n . m i c r o s o f t . c o m / e n - u s / l i b r a r y / 2 k z t 1 w y 3 . a s p x
string ( REGEX REPLACE "/MD" "/MT" ${ flag_var } "${${flag_var}}" )
# T h i s i s a c h i e v e d b y r e p l a c i n g m s v c o p t i o n / M D w i t h / M T a n d / M D d w i t h / M T d
endif ( ${ flag_var } MATCHES "/MD" )
# h t t p : / / w w w . c m a k e . o r g / W i k i / C M a k e _ F A Q # H o w _ c a n _ I _ b u i l d _ m y _ M S V C _ a p p l i c a t i o n _ w i t h _ a _ s t a t i c _ r u n t i m e . 3 F
endforeach ( flag_var )
if ( MSVC AND protobuf_MSVC_STATIC_RUNTIME )
endif ( MSVC AND protobuf_MSVC_STATIC_RUNTIME )
foreach ( flag_var
C M A K E _ C X X _ F L A G S C M A K E _ C X X _ F L A G S _ D E B U G C M A K E _ C X X _ F L A G S _ R E L E A S E
C M A K E _ C X X _ F L A G S _ M I N S I Z E R E L C M A K E _ C X X _ F L A G S _ R E L W I T H D E B I N F O )
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 ( )
endif ( protobuf_BUILD_SHARED_LIBS )
endif ( protobuf_BUILD_SHARED_LIBS )
if ( MSVC )
if ( MSVC )