2016-09-27 19:01:08 +00:00
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
2018-10-22 14:31:08 +00:00
#[=======================================================================[.rst:
G e n e r a t e E x p o r t H e a d e r
- - - - - - - - - - - - - - - - - - - -
F u n c t i o n f o r g e n e r a t i o n o f e x p o r t m a c r o s f o r l i b r a r i e s
2019-04-05 15:22:38 +00:00
T h i s m o d u l e p r o v i d e s t h e f u n c t i o n ` ` GENERATE_EXPORT_HEADER ( ) ` ` .
2018-10-22 14:31:08 +00:00
T h e ` ` G E N E R A T E _ E X P O R T _ H E A D E R ` ` f u n c t i o n c a n b e u s e d t o g e n e r a t e a f i l e
s u i t a b l e f o r p r e p r o c e s s o r i n c l u s i o n w h i c h c o n t a i n s E X P O R T m a c r o s t o b e
u s e d i n l i b r a r y c l a s s e s : :
GENERATE_EXPORT_HEADER ( LIBRARY_TARGET
[ B A S E _ N A M E < b a s e _ n a m e > ]
[ E X P O R T _ M A C R O _ N A M E < e x p o r t _ m a c r o _ n a m e > ]
[ E X P O R T _ F I L E _ N A M E < e x p o r t _ f i l e _ n a m e > ]
[ D E P R E C A T E D _ M A C R O _ N A M E < d e p r e c a t e d _ m a c r o _ n a m e > ]
[ N O _ E X P O R T _ M A C R O _ N A M E < n o _ e x p o r t _ m a c r o _ n a m e > ]
[ I N C L U D E _ G U A R D _ N A M E < i n c l u d e _ g u a r d _ n a m e > ]
[ S T A T I C _ D E F I N E < s t a t i c _ d e f i n e > ]
[ N O _ D E P R E C A T E D _ M A C R O _ N A M E < n o _ d e p r e c a t e d _ m a c r o _ n a m e > ]
[ D E F I N E _ N O _ D E P R E C A T E D ]
[ P R E F I X _ N A M E < p r e f i x _ n a m e > ]
[ C U S T O M _ C O N T E N T _ F R O M _ V A R I A B L E < v a r i a b l e > ]
)
T h e t a r g e t p r o p e r t i e s : p r o p _ t g t : ` C X X _ V I S I B I L I T Y _ P R E S E T < < L A N G > _ V I S I B I L I T Y _ P R E S E T > `
a n d : p r o p _ t g t : ` V I S I B I L I T Y _ I N L I N E S _ H I D D E N ` c a n b e u s e d t o a d d t h e a p p r o p r i a t e
c o m p i l e f l a g s f o r t a r g e t s . S e e t h e d o c u m e n t a t i o n o f t h o s e t a r g e t p r o p e r t i e s ,
a n d t h e c o n v e n i e n c e v a r i a b l e s
: v a r i a b l e : ` C M A K E _ C X X _ V I S I B I L I T Y _ P R E S E T < C M A K E _ < L A N G > _ V I S I B I L I T Y _ P R E S E T > ` a n d
: v a r i a b l e : ` C M A K E _ V I S I B I L I T Y _ I N L I N E S _ H I D D E N ` .
B y d e f a u l t ` ` GENERATE_EXPORT_HEADER ( ) ` ` g e n e r a t e s m a c r o n a m e s i n a f i l e
n a m e d e t e r m i n e d b y t h e n a m e o f t h e l i b r a r y . T h i s m e a n s t h a t i n t h e
s i m p l e s t c a s e , u s e r s o f ` ` G e n e r a t e E x p o r t H e a d e r ` ` w i l l b e e q u i v a l e n t t o :
. . c o d e - b l o c k : : c m a k e
set ( CMAKE_CXX_VISIBILITY_PRESET hidden )
set ( CMAKE_VISIBILITY_INLINES_HIDDEN 1 )
add_library ( somelib someclass.cpp )
generate_export_header ( somelib )
install ( TARGETS somelib DESTINATION ${ LIBRARY_INSTALL_DIR } )
install ( FILES
s o m e c l a s s . h
$ { P R O J E C T _ B I N A R Y _ D I R } / s o m e l i b _ e x p o r t . h D E S T I N A T I O N $ { I N C L U D E _ I N S T A L L _ D I R }
)
A n d i n t h e A B I h e a d e r f i l e s :
. . c o d e - b l o c k : : c + +
#include "somelib_export.h"
c l a s s S O M E L I B _ E X P O R T S o m e C l a s s {
. . .
} ;
T h e C M a k e f r a g m e n t w i l l g e n e r a t e a f i l e i n t h e
` ` $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } ` ` c a l l e d ` ` s o m e l i b _ e x p o r t . h ` ` c o n t a i n i n g t h e
m a c r o s ` ` S O M E L I B _ E X P O R T ` ` , ` ` S O M E L I B _ N O _ E X P O R T ` ` , ` ` S O M E L I B _ D E P R E C A T E D ` ` ,
` ` S O M E L I B _ D E P R E C A T E D _ E X P O R T ` ` a n d ` ` S O M E L I B _ D E P R E C A T E D _ N O _ E X P O R T ` ` .
T h e y w i l l b e f o l l o w e d b y c o n t e n t t a k e n f r o m t h e v a r i a b l e s p e c i f i e d b y
t h e ` ` C U S T O M _ C O N T E N T _ F R O M _ V A R I A B L E ` ` o p t i o n , i f a n y .
T h e r e s u l t i n g f i l e s h o u l d b e i n s t a l l e d w i t h o t h e r h e a d e r s i n t h e l i b r a r y .
T h e ` ` B A S E _ N A M E ` ` a r g u m e n t c a n b e u s e d t o o v e r r i d e t h e f i l e n a m e a n d t h e
n a m e s u s e d f o r t h e m a c r o s :
. . c o d e - b l o c k : : c m a k e
add_library ( somelib someclass.cpp )
generate_export_header ( somelib
B A S E _ N A M E o t h e r _ n a m e
)
G e n e r a t e s a f i l e c a l l e d ` ` o t h e r _ n a m e _ e x p o r t . h ` ` c o n t a i n i n g t h e m a c r o s
` ` O T H E R _ N A M E _ E X P O R T ` ` , ` ` O T H E R _ N A M E _ N O _ E X P O R T ` ` a n d ` ` O T H E R _ N A M E _ D E P R E C A T E D ` `
e t c .
T h e ` ` B A S E _ N A M E ` ` m a y b e o v e r r i d d e n b y s p e c i f y i n g o t h e r o p t i o n s i n t h e
f u n c t i o n . F o r e x a m p l e :
. . c o d e - b l o c k : : c m a k e
add_library ( somelib someclass.cpp )
generate_export_header ( somelib
E X P O R T _ M A C R O _ N A M E O T H E R _ N A M E _ E X P O R T
)
c r e a t e s t h e m a c r o ` ` O T H E R _ N A M E _ E X P O R T ` ` i n s t e a d o f ` ` S O M E L I B _ E X P O R T ` ` , b u t
o t h e r m a c r o s a n d t h e g e n e r a t e d f i l e n a m e i s a s d e f a u l t :
. . c o d e - b l o c k : : c m a k e
add_library ( somelib someclass.cpp )
generate_export_header ( somelib
D E P R E C A T E D _ M A C R O _ N A M E K D E _ D E P R E C A T E D
)
c r e a t e s t h e m a c r o ` ` K D E _ D E P R E C A T E D ` ` i n s t e a d o f ` ` S O M E L I B _ D E P R E C A T E D ` ` .
I f ` ` L I B R A R Y _ T A R G E T ` ` i s a s t a t i c l i b r a r y , m a c r o s a r e d e f i n e d w i t h o u t
v a l u e s .
I f t h e s a m e s o u r c e s a r e u s e d t o c r e a t e b o t h a s h a r e d a n d a s t a t i c
l i b r a r y , t h e u p p e r c a s e d s y m b o l ` ` $ { B A S E _ N A M E } _ S T A T I C _ D E F I N E ` ` s h o u l d b e
u s e d w h e n b u i l d i n g t h e s t a t i c l i b r a r y :
. . c o d e - b l o c k : : c m a k e
add_library ( shared_variant SHARED ${ lib_SRCS } )
add_library ( static_variant ${ lib_SRCS } )
generate_export_header ( shared_variant BASE_NAME libshared_and_static )
set_target_properties ( static_variant PROPERTIES
C O M P I L E _ F L A G S - D L I B S H A R E D _ A N D _ S T A T I C _ S T A T I C _ D E F I N E )
T h i s w i l l c a u s e t h e e x p o r t m a c r o s t o e x p a n d t o n o t h i n g w h e n b u i l d i n g
t h e s t a t i c l i b r a r y .
I f ` ` D E F I N E _ N O _ D E P R E C A T E D ` ` i s s p e c i f i e d , t h e n a m a c r o
` ` $ { B A S E _ N A M E } _ N O _ D E P R E C A T E D ` ` w i l l b e d e f i n e d T h i s m a c r o c a n b e u s e d t o
r e m o v e d e p r e c a t e d c o d e f r o m p r e p r o c e s s o r o u t p u t :
. . c o d e - b l o c k : : c m a k e
option ( EXCLUDE_DEPRECATED "Exclude deprecated parts of the library" FALSE )
if ( EXCLUDE_DEPRECATED )
set ( NO_BUILD_DEPRECATED DEFINE_NO_DEPRECATED )
endif ( )
generate_export_header ( somelib ${ NO_BUILD_DEPRECATED } )
A n d t h e n i n s o m e l i b :
. . c o d e - b l o c k : : c + +
c l a s s S O M E L I B _ E X P O R T S o m e C l a s s
{
p u b l i c :
#ifndef SOMELIB_NO_DEPRECATED
S O M E L I B _ D E P R E C A T E D v o i d oldMethod ( ) ;
#endif
} ;
. . c o d e - b l o c k : : c + +
#ifndef SOMELIB_NO_DEPRECATED
v o i d S o m e C l a s s : : oldMethod ( ) { }
#endif
I f ` ` P R E F I X _ N A M E ` ` i s s p e c i f i e d , t h e a r g u m e n t w i l l b e u s e d a s a p r e f i x t o
a l l g e n e r a t e d m a c r o s .
F o r e x a m p l e :
. . c o d e - b l o c k : : c m a k e
generate_export_header ( somelib PREFIX_NAME VTK_ )
G e n e r a t e s t h e m a c r o s ` ` V T K _ S O M E L I B _ E X P O R T ` ` e t c .
: :
ADD_COMPILER_EXPORT_FLAGS ( [<output_variable>] )
T h e ` ` A D D _ C O M P I L E R _ E X P O R T _ F L A G S ` ` f u n c t i o n a d d s ` ` - f v i s i b i l i t y = h i d d e n ` ` t o
: v a r i a b l e : ` C M A K E _ C X X _ F L A G S < C M A K E _ < L A N G > _ F L A G S > ` i f s u p p o r t e d , a n d i s a n o - o p
o n W i n d o w s w h i c h d o e s n o t n e e d e x t r a c o m p i l e r f l a g s f o r e x p o r t i n g s u p p o r t .
Y o u m a y o p t i o n a l l y p a s s a s i n g l e a r g u m e n t t o ` ` A D D _ C O M P I L E R _ E X P O R T _ F L A G S ` `
t h a t w i l l b e p o p u l a t e d w i t h t h e ` ` C X X _ F L A G S ` ` r e q u i r e d t o e n a b l e v i s i b i l i t y
s u p p o r t f o r t h e c o m p i l e r / a r c h i t e c t u r e i n u s e .
T h i s f u n c t i o n i s d e p r e c a t e d . S e t t h e t a r g e t p r o p e r t i e s
: p r o p _ t g t : ` C X X _ V I S I B I L I T Y _ P R E S E T < < L A N G > _ V I S I B I L I T Y _ P R E S E T > ` a n d
: p r o p _ t g t : ` V I S I B I L I T Y _ I N L I N E S _ H I D D E N ` i n s t e a d .
#]=======================================================================]
2011-07-13 00:13:33 +00:00
2018-02-26 12:09:08 +00:00
include ( CheckCCompilerFlag )
2011-07-13 00:13:33 +00:00
include ( CheckCXXCompilerFlag )
2011-08-11 16:18:19 +00:00
# TODO: Install this macro separately?
macro ( _check_cxx_compiler_attribute _ATTRIBUTE _RESULT )
2011-09-19 18:04:42 +00:00
check_cxx_source_compiles ( " ${ _ATTRIBUTE } int somefunc( ) { r e t u r n 0 ; }
i n t main ( ) { r e t u r n somefunc ( ) ; } " $ { _ R E S U L T }
2011-08-11 16:18:19 +00:00
)
endmacro ( )
2018-02-26 12:09:08 +00:00
# TODO: Install this macro separately?
macro ( _check_c_compiler_attribute _ATTRIBUTE _RESULT )
check_c_source_compiles ( " ${ _ATTRIBUTE } int somefunc( ) { r e t u r n 0 ; }
i n t main ( ) { r e t u r n somefunc ( ) ; } " $ { _ R E S U L T }
)
endmacro ( )
2011-07-13 00:13:33 +00:00
macro ( _test_compiler_hidden_visibility )
2011-08-10 19:13:33 +00:00
2012-02-24 16:48:02 +00:00
if ( CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.2" )
set ( GCC_TOO_OLD TRUE )
2016-09-14 14:11:43 +00:00
elseif ( CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER_VERSION VERSION_LESS "4.2" )
2012-02-24 16:48:02 +00:00
set ( GCC_TOO_OLD TRUE )
elseif ( CMAKE_CXX_COMPILER_ID MATCHES Intel AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "12.0" )
set ( _INTEL_TOO_OLD TRUE )
2011-08-23 17:49:39 +00:00
endif ( )
2011-08-11 16:18:19 +00:00
# Exclude XL here because it misinterprets -fvisibility=hidden even though
# the check_cxx_compiler_flag passes
2011-09-19 18:04:42 +00:00
if ( NOT GCC_TOO_OLD
2011-08-23 18:04:56 +00:00
A N D N O T _ I N T E L _ T O O _ O L D
A N D N O T WIN32
A N D N O T CYGWIN
2014-09-29 19:53:13 +00:00
A N D N O T C M A K E _ C X X _ C O M P I L E R _ I D M A T C H E S X L
A N D N O T C M A K E _ C X X _ C O M P I L E R _ I D M A T C H E S P G I
A N D N O T C M A K E _ C X X _ C O M P I L E R _ I D M A T C H E S W a t c o m )
2018-02-26 12:09:08 +00:00
if ( CMAKE_CXX_COMPILER_LOADED )
check_cxx_compiler_flag ( -fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY )
check_cxx_compiler_flag ( -fvisibility-inlines-hidden
C O M P I L E R _ H A S _ H I D D E N _ I N L I N E _ V I S I B I L I T Y )
else ( )
check_c_compiler_flag ( -fvisibility=hidden COMPILER_HAS_HIDDEN_VISIBILITY )
check_c_compiler_flag ( -fvisibility-inlines-hidden
C O M P I L E R _ H A S _ H I D D E N _ I N L I N E _ V I S I B I L I T Y )
endif ( )
2011-08-10 19:13:33 +00:00
endif ( )
2011-07-13 00:13:33 +00:00
endmacro ( )
2011-08-11 16:17:12 +00:00
macro ( _test_compiler_has_deprecated )
2015-12-03 20:42:30 +00:00
# NOTE: Some Embarcadero compilers silently compile __declspec(deprecated)
# without error, but this is not a documented feature and the attribute does
# not actually generate any warnings.
2014-09-29 19:53:13 +00:00
if ( CMAKE_CXX_COMPILER_ID MATCHES Borland
2015-12-03 20:42:30 +00:00
O R C M A K E _ C X X _ C O M P I L E R _ I D M A T C H E S E m b a r c a d e r o
2014-09-29 19:53:13 +00:00
O R C M A K E _ C X X _ C O M P I L E R _ I D M A T C H E S H P
2011-08-23 18:04:56 +00:00
O R G C C _ T O O _ O L D
2014-09-29 19:53:13 +00:00
O R C M A K E _ C X X _ C O M P I L E R _ I D M A T C H E S P G I
O R C M A K E _ C X X _ C O M P I L E R _ I D M A T C H E S W a t c o m )
2011-09-19 18:04:42 +00:00
set ( COMPILER_HAS_DEPRECATED "" CACHE INTERNAL
" C o m p i l e r s u p p o r t f o r a d e p r e c a t e d a t t r i b u t e " )
2011-08-11 16:17:12 +00:00
else ( )
2018-02-26 12:09:08 +00:00
if ( CMAKE_CXX_COMPILER_LOADED )
_check_cxx_compiler_attribute ( "__attribute__((__deprecated__))"
C O M P I L E R _ H A S _ D E P R E C A T E D _ A T T R )
if ( COMPILER_HAS_DEPRECATED_ATTR )
set ( COMPILER_HAS_DEPRECATED "${COMPILER_HAS_DEPRECATED_ATTR}"
C A C H E I N T E R N A L " C o m p i l e r s u p p o r t f o r a d e p r e c a t e d a t t r i b u t e " )
else ( )
_check_cxx_compiler_attribute ( "__declspec(deprecated)"
C O M P I L E R _ H A S _ D E P R E C A T E D )
endif ( )
2011-08-13 21:30:35 +00:00
else ( )
2018-02-26 12:09:08 +00:00
_check_c_compiler_attribute ( "__attribute__((__deprecated__))"
C O M P I L E R _ H A S _ D E P R E C A T E D _ A T T R )
if ( COMPILER_HAS_DEPRECATED_ATTR )
set ( COMPILER_HAS_DEPRECATED "${COMPILER_HAS_DEPRECATED_ATTR}"
C A C H E I N T E R N A L " C o m p i l e r s u p p o r t f o r a d e p r e c a t e d a t t r i b u t e " )
else ( )
_check_c_compiler_attribute ( "__declspec(deprecated)"
C O M P I L E R _ H A S _ D E P R E C A T E D )
endif ( )
2011-08-13 21:30:35 +00:00
endif ( )
2011-08-11 16:17:12 +00:00
endif ( )
endmacro ( )
2011-09-19 20:42:42 +00:00
get_filename_component ( _GENERATE_EXPORT_HEADER_MODULE_DIR
" $ { C M A K E _ C U R R E N T _ L I S T _ F I L E } " P A T H )
2011-07-13 00:13:33 +00:00
macro ( _DO_SET_MACRO_VALUES TARGET_LIBRARY )
set ( DEFINE_DEPRECATED )
set ( DEFINE_EXPORT )
set ( DEFINE_IMPORT )
set ( DEFINE_NO_EXPORT )
2011-08-14 13:37:24 +00:00
if ( COMPILER_HAS_DEPRECATED_ATTR )
2011-08-11 16:18:19 +00:00
set ( DEFINE_DEPRECATED "__attribute__ ((__deprecated__))" )
2011-08-14 13:37:24 +00:00
elseif ( COMPILER_HAS_DEPRECATED )
set ( DEFINE_DEPRECATED "__declspec(deprecated)" )
2011-07-13 00:13:33 +00:00
endif ( )
get_property ( type TARGET ${ TARGET_LIBRARY } PROPERTY TYPE )
if ( NOT ${ type } STREQUAL "STATIC_LIBRARY" )
2015-08-27 07:48:18 +00:00
if ( WIN32 OR CYGWIN )
2011-08-10 20:19:39 +00:00
set ( DEFINE_EXPORT "__declspec(dllexport)" )
set ( DEFINE_IMPORT "__declspec(dllimport)" )
2016-07-11 18:52:05 +00:00
elseif ( COMPILER_HAS_HIDDEN_VISIBILITY )
2011-08-10 08:32:58 +00:00
set ( DEFINE_EXPORT "__attribute__((visibility(\" default\ ")))" )
set ( DEFINE_IMPORT "__attribute__((visibility(\" default\ ")))" )
set ( DEFINE_NO_EXPORT "__attribute__((visibility(\" hidden\ ")))" )
2011-07-13 00:13:33 +00:00
endif ( )
endif ( )
endmacro ( )
macro ( _DO_GENERATE_EXPORT_HEADER TARGET_LIBRARY )
# Option overrides
2011-08-23 21:26:43 +00:00
set ( options DEFINE_NO_DEPRECATED )
2011-09-19 18:04:42 +00:00
set ( oneValueArgs PREFIX_NAME BASE_NAME EXPORT_MACRO_NAME EXPORT_FILE_NAME
D E P R E C A T E D _ M A C R O _ N A M E N O _ E X P O R T _ M A C R O _ N A M E S T A T I C _ D E F I N E
2018-01-08 19:00:24 +00:00
N O _ D E P R E C A T E D _ M A C R O _ N A M E C U S T O M _ C O N T E N T _ F R O M _ V A R I A B L E I N C L U D E _ G U A R D _ N A M E )
2011-07-13 00:13:33 +00:00
set ( multiValueArgs )
2011-09-19 18:04:42 +00:00
cmake_parse_arguments ( _GEH "${options}" "${oneValueArgs}" "${multiValueArgs}"
$ { A R G N } )
2011-07-13 00:13:33 +00:00
set ( BASE_NAME "${TARGET_LIBRARY}" )
if ( _GEH_BASE_NAME )
set ( BASE_NAME ${ _GEH_BASE_NAME } )
endif ( )
string ( TOUPPER ${ BASE_NAME } BASE_NAME_UPPER )
string ( TOLOWER ${ BASE_NAME } BASE_NAME_LOWER )
# Default options
2011-08-25 16:51:37 +00:00
set ( EXPORT_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_EXPORT" )
set ( NO_EXPORT_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_NO_EXPORT" )
2011-07-13 00:13:33 +00:00
set ( EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${BASE_NAME_LOWER}_export.h" )
2011-08-25 16:51:37 +00:00
set ( DEPRECATED_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_DEPRECATED" )
set ( STATIC_DEFINE "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_STATIC_DEFINE" )
2011-09-19 18:04:42 +00:00
set ( NO_DEPRECATED_MACRO_NAME
" $ { _ G E H _ P R E F I X _ N A M E } $ { B A S E _ N A M E _ U P P E R } _ N O _ D E P R E C A T E D " )
2011-07-13 00:13:33 +00:00
if ( _GEH_UNPARSED_ARGUMENTS )
message ( FATAL_ERROR "Unknown keywords given to GENERATE_EXPORT_HEADER(): \" ${ _GEH_UNPARSED_ARGUMENTS } \"")
endif ( )
if ( _GEH_EXPORT_MACRO_NAME )
2011-08-25 16:51:37 +00:00
set ( EXPORT_MACRO_NAME ${ _GEH_PREFIX_NAME } ${ _GEH_EXPORT_MACRO_NAME } )
2011-07-13 00:13:33 +00:00
endif ( )
2013-05-23 05:44:04 +00:00
string ( MAKE_C_IDENTIFIER ${ EXPORT_MACRO_NAME } EXPORT_MACRO_NAME )
2011-07-13 00:13:33 +00:00
if ( _GEH_EXPORT_FILE_NAME )
2011-12-31 20:31:40 +00:00
if ( IS_ABSOLUTE ${ _GEH_EXPORT_FILE_NAME } )
2011-07-13 00:13:33 +00:00
set ( EXPORT_FILE_NAME ${ _GEH_EXPORT_FILE_NAME } )
else ( )
set ( EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${_GEH_EXPORT_FILE_NAME}" )
endif ( )
endif ( )
2011-08-23 21:19:31 +00:00
if ( _GEH_DEPRECATED_MACRO_NAME )
2011-08-25 16:51:37 +00:00
set ( DEPRECATED_MACRO_NAME ${ _GEH_PREFIX_NAME } ${ _GEH_DEPRECATED_MACRO_NAME } )
2011-07-13 00:13:33 +00:00
endif ( )
2013-05-23 05:44:04 +00:00
string ( MAKE_C_IDENTIFIER ${ DEPRECATED_MACRO_NAME } DEPRECATED_MACRO_NAME )
2011-07-13 00:13:33 +00:00
if ( _GEH_NO_EXPORT_MACRO_NAME )
2011-08-25 16:51:37 +00:00
set ( NO_EXPORT_MACRO_NAME ${ _GEH_PREFIX_NAME } ${ _GEH_NO_EXPORT_MACRO_NAME } )
2011-07-13 00:13:33 +00:00
endif ( )
2013-05-23 05:44:04 +00:00
string ( MAKE_C_IDENTIFIER ${ NO_EXPORT_MACRO_NAME } NO_EXPORT_MACRO_NAME )
2011-07-13 00:13:33 +00:00
if ( _GEH_STATIC_DEFINE )
2011-08-25 16:51:37 +00:00
set ( STATIC_DEFINE ${ _GEH_PREFIX_NAME } ${ _GEH_STATIC_DEFINE } )
2011-07-13 00:13:33 +00:00
endif ( )
2013-05-23 05:44:04 +00:00
string ( MAKE_C_IDENTIFIER ${ STATIC_DEFINE } STATIC_DEFINE )
2011-07-13 00:13:33 +00:00
2011-09-19 18:04:42 +00:00
if ( _GEH_DEFINE_NO_DEPRECATED )
2016-03-17 11:02:26 +00:00
set ( DEFINE_NO_DEPRECATED 1 )
else ( )
set ( DEFINE_NO_DEPRECATED 0 )
2011-08-23 21:26:43 +00:00
endif ( )
2011-09-19 18:04:42 +00:00
if ( _GEH_NO_DEPRECATED_MACRO_NAME )
set ( NO_DEPRECATED_MACRO_NAME
$ { _ G E H _ P R E F I X _ N A M E } $ { _ G E H _ N O _ D E P R E C A T E D _ M A C R O _ N A M E } )
2011-08-23 21:26:43 +00:00
endif ( )
2013-05-23 05:44:04 +00:00
string ( MAKE_C_IDENTIFIER ${ NO_DEPRECATED_MACRO_NAME } NO_DEPRECATED_MACRO_NAME )
2011-08-23 21:26:43 +00:00
2018-01-08 19:00:24 +00:00
if ( _GEH_INCLUDE_GUARD_NAME )
set ( INCLUDE_GUARD_NAME ${ _GEH_INCLUDE_GUARD_NAME } )
else ( )
set ( INCLUDE_GUARD_NAME "${EXPORT_MACRO_NAME}_H" )
endif ( )
2011-07-13 00:13:33 +00:00
2011-08-08 00:08:10 +00:00
get_target_property ( EXPORT_IMPORT_CONDITION ${ TARGET_LIBRARY } DEFINE_SYMBOL )
2011-09-19 18:04:42 +00:00
if ( NOT EXPORT_IMPORT_CONDITION )
2011-08-08 00:08:10 +00:00
set ( EXPORT_IMPORT_CONDITION ${ TARGET_LIBRARY } _EXPORTS )
endif ( )
2013-05-23 05:44:04 +00:00
string ( MAKE_C_IDENTIFIER ${ EXPORT_IMPORT_CONDITION } EXPORT_IMPORT_CONDITION )
2011-08-08 00:08:10 +00:00
2016-06-28 13:42:08 +00:00
if ( _GEH_CUSTOM_CONTENT_FROM_VARIABLE )
if ( DEFINED "${_GEH_CUSTOM_CONTENT_FROM_VARIABLE}" )
set ( CUSTOM_CONTENT "${${_GEH_CUSTOM_CONTENT_FROM_VARIABLE}}" )
else ( )
set ( CUSTOM_CONTENT "" )
endif ( )
endif ( )
2011-09-19 18:04:42 +00:00
configure_file ( "${_GENERATE_EXPORT_HEADER_MODULE_DIR}/exportheader.cmake.in"
" $ { E X P O R T _ F I L E _ N A M E } " @ O N L Y )
2011-07-13 00:13:33 +00:00
endmacro ( )
function ( GENERATE_EXPORT_HEADER TARGET_LIBRARY )
get_property ( type TARGET ${ TARGET_LIBRARY } PROPERTY TYPE )
2013-03-14 15:37:49 +00:00
if ( NOT ${ type } STREQUAL "STATIC_LIBRARY"
A N D N O T $ { t y p e } S T R E Q U A L " S H A R E D _ L I B R A R Y "
2014-07-03 14:23:40 +00:00
A N D N O T $ { t y p e } S T R E Q U A L " O B J E C T _ L I B R A R Y "
2013-03-14 15:37:49 +00:00
A N D N O T $ { t y p e } S T R E Q U A L " M O D U L E _ L I B R A R Y " )
2011-07-13 00:13:33 +00:00
message ( WARNING "This macro can only be used with libraries" )
return ( )
endif ( )
_test_compiler_hidden_visibility ( )
2011-08-11 16:17:12 +00:00
_test_compiler_has_deprecated ( )
2011-07-13 00:13:33 +00:00
_do_set_macro_values ( ${ TARGET_LIBRARY } )
_do_generate_export_header ( ${ TARGET_LIBRARY } ${ ARGN } )
endfunction ( )
2011-09-20 04:16:16 +00:00
function ( add_compiler_export_flags )
2013-09-02 08:57:55 +00:00
if ( NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.12 )
2013-10-08 16:14:21 +00:00
message ( DEPRECATION "The add_compiler_export_flags function is obsolete. Use the CXX_VISIBILITY_PRESET and VISIBILITY_INLINES_HIDDEN target properties instead." )
2013-09-02 08:57:55 +00:00
endif ( )
2011-07-13 00:13:33 +00:00
2011-08-10 08:26:16 +00:00
_test_compiler_hidden_visibility ( )
2011-08-11 16:17:12 +00:00
_test_compiler_has_deprecated ( )
2011-08-10 08:26:16 +00:00
2016-07-11 18:52:05 +00:00
option ( USE_COMPILER_HIDDEN_VISIBILITY
" U s e H I D D E N v i s i b i l i t y s u p p o r t i f a v a i l a b l e . " O N )
mark_as_advanced ( USE_COMPILER_HIDDEN_VISIBILITY )
2011-08-11 08:39:51 +00:00
if ( NOT ( USE_COMPILER_HIDDEN_VISIBILITY AND COMPILER_HAS_HIDDEN_VISIBILITY ) )
2011-09-19 18:55:19 +00:00
# Just return if there are no flags to add.
2011-07-13 00:13:33 +00:00
return ( )
endif ( )
2011-08-10 08:28:15 +00:00
set ( EXTRA_FLAGS "-fvisibility=hidden" )
2011-07-13 00:13:33 +00:00
2011-08-10 08:28:15 +00:00
if ( COMPILER_HAS_HIDDEN_INLINE_VISIBILITY )
set ( EXTRA_FLAGS "${EXTRA_FLAGS} -fvisibility-inlines-hidden" )
2011-07-13 00:13:33 +00:00
endif ( )
2011-09-19 20:42:42 +00:00
# Either return the extra flags needed in the supplied argument, or to the
# CMAKE_CXX_FLAGS if no argument is supplied.
2015-02-26 16:26:12 +00:00
if ( ARGC GREATER 0 )
2011-09-20 04:16:16 +00:00
set ( ${ ARGV0 } "${EXTRA_FLAGS}" PARENT_SCOPE )
2011-09-19 20:42:42 +00:00
else ( )
2016-09-01 19:32:32 +00:00
string ( APPEND CMAKE_CXX_FLAGS " ${EXTRA_FLAGS}" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE )
2011-09-19 20:42:42 +00:00
endif ( )
2011-09-20 04:16:16 +00:00
endfunction ( )