# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.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
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 ( ) ` ` .
. . v e r s i o n a d d e d : : 3 . 1 2
A d d e d s u p p o r t f o r C p r o j e c t s . P r e v i o u s v e r s i o n s s u p p o r t e d C + + p r o j e c t o n l y .
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 .
. . v e r s i o n a d d e d : : 3 . 1
L i b r a r y t a r g e t c a n b e a n ` ` O B J E C T ` ` l i b r a r y .
. . v e r s i o n a d d e d : : 3 . 7
A d d e d 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 .
. . v e r s i o n a d d e d : : 3 . 1 1
A d d e d t h e ` ` I N C L U D E _ G U A R D _ N A M E ` ` o p t i o n .
: :
ADD_COMPILER_EXPORT_FLAGS ( [<output_variable>] )
. . d e p r e c a t e d : : 3 . 0
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 .
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 .
#]=======================================================================]
include ( CheckCCompilerFlag )
include ( CheckCXXCompilerFlag )
# TODO: Install this macro separately?
macro ( _check_cxx_compiler_attribute _ATTRIBUTE _RESULT )
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 }
)
endmacro ( )
# 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 ( )
macro ( _test_compiler_hidden_visibility )
if ( CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.2" )
set ( GCC_TOO_OLD TRUE )
elseif ( CMAKE_COMPILER_IS_GNUCC AND CMAKE_C_COMPILER_VERSION VERSION_LESS "4.2" )
set ( GCC_TOO_OLD TRUE )
elseif ( CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "12.0" )
set ( _INTEL_TOO_OLD TRUE )
endif ( )
# Exclude XL here because it misinterprets -fvisibility=hidden even though
# the check_cxx_compiler_flag passes
if ( NOT GCC_TOO_OLD
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
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 " ^ ( I B M C l a n g | X L C l a n g | 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 | N V H P C ) $ "
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 )
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 ( )
endif ( )
endmacro ( )
macro ( _test_compiler_has_deprecated )
# 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.
if ( CMAKE_CXX_COMPILER_ID MATCHES Borland
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
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
O R G C C _ T O O _ O L D
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 | N V H P C ) $ "
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 )
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 " )
else ( )
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 ( )
else ( )
_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 ( )
endif ( )
endif ( )
endmacro ( )
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 )
macro ( _DO_SET_MACRO_VALUES TARGET_LIBRARY )
set ( DEFINE_DEPRECATED )
set ( DEFINE_EXPORT )
set ( DEFINE_IMPORT )
set ( DEFINE_NO_EXPORT )
if ( COMPILER_HAS_DEPRECATED_ATTR )
set ( DEFINE_DEPRECATED "__attribute__ ((__deprecated__))" )
elseif ( COMPILER_HAS_DEPRECATED )
set ( DEFINE_DEPRECATED "__declspec(deprecated)" )
endif ( )
get_property ( type TARGET ${ TARGET_LIBRARY } PROPERTY TYPE )
if ( NOT ${ type } STREQUAL "STATIC_LIBRARY" )
if ( WIN32 OR CYGWIN )
set ( DEFINE_EXPORT "__declspec(dllexport)" )
set ( DEFINE_IMPORT "__declspec(dllimport)" )
elseif ( COMPILER_HAS_HIDDEN_VISIBILITY )
set ( DEFINE_EXPORT "__attribute__((visibility(\" default\ ")))" )
set ( DEFINE_IMPORT "__attribute__((visibility(\" default\ ")))" )
set ( DEFINE_NO_EXPORT "__attribute__((visibility(\" hidden\ ")))" )
endif ( )
endif ( )
endmacro ( )
macro ( _DO_GENERATE_EXPORT_HEADER TARGET_LIBRARY )
# Option overrides
set ( options DEFINE_NO_DEPRECATED )
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
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 )
set ( multiValueArgs )
cmake_parse_arguments ( _GEH "${options}" "${oneValueArgs}" "${multiValueArgs}"
$ { A R G N } )
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
set ( EXPORT_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_EXPORT" )
set ( NO_EXPORT_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_NO_EXPORT" )
set ( EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${BASE_NAME_LOWER}_export.h" )
set ( DEPRECATED_MACRO_NAME "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_DEPRECATED" )
set ( STATIC_DEFINE "${_GEH_PREFIX_NAME}${BASE_NAME_UPPER}_STATIC_DEFINE" )
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 " )
if ( _GEH_UNPARSED_ARGUMENTS )
message ( FATAL_ERROR "Unknown keywords given to GENERATE_EXPORT_HEADER(): \" ${ _GEH_UNPARSED_ARGUMENTS } \"")
endif ( )
if ( _GEH_EXPORT_MACRO_NAME )
set ( EXPORT_MACRO_NAME ${ _GEH_PREFIX_NAME } ${ _GEH_EXPORT_MACRO_NAME } )
endif ( )
string ( MAKE_C_IDENTIFIER ${ EXPORT_MACRO_NAME } EXPORT_MACRO_NAME )
if ( _GEH_EXPORT_FILE_NAME )
if ( IS_ABSOLUTE ${ _GEH_EXPORT_FILE_NAME } )
set ( EXPORT_FILE_NAME ${ _GEH_EXPORT_FILE_NAME } )
else ( )
set ( EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/${_GEH_EXPORT_FILE_NAME}" )
endif ( )
endif ( )
if ( _GEH_DEPRECATED_MACRO_NAME )
set ( DEPRECATED_MACRO_NAME ${ _GEH_PREFIX_NAME } ${ _GEH_DEPRECATED_MACRO_NAME } )
endif ( )
string ( MAKE_C_IDENTIFIER ${ DEPRECATED_MACRO_NAME } DEPRECATED_MACRO_NAME )
if ( _GEH_NO_EXPORT_MACRO_NAME )
set ( NO_EXPORT_MACRO_NAME ${ _GEH_PREFIX_NAME } ${ _GEH_NO_EXPORT_MACRO_NAME } )
endif ( )
string ( MAKE_C_IDENTIFIER ${ NO_EXPORT_MACRO_NAME } NO_EXPORT_MACRO_NAME )
if ( _GEH_STATIC_DEFINE )
set ( STATIC_DEFINE ${ _GEH_PREFIX_NAME } ${ _GEH_STATIC_DEFINE } )
endif ( )
string ( MAKE_C_IDENTIFIER ${ STATIC_DEFINE } STATIC_DEFINE )
if ( _GEH_DEFINE_NO_DEPRECATED )
set ( DEFINE_NO_DEPRECATED 1 )
else ( )
set ( DEFINE_NO_DEPRECATED 0 )
endif ( )
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 } )
endif ( )
string ( MAKE_C_IDENTIFIER ${ NO_DEPRECATED_MACRO_NAME } NO_DEPRECATED_MACRO_NAME )
if ( _GEH_INCLUDE_GUARD_NAME )
set ( INCLUDE_GUARD_NAME ${ _GEH_INCLUDE_GUARD_NAME } )
else ( )
set ( INCLUDE_GUARD_NAME "${EXPORT_MACRO_NAME}_H" )
endif ( )
get_target_property ( EXPORT_IMPORT_CONDITION ${ TARGET_LIBRARY } DEFINE_SYMBOL )
if ( NOT EXPORT_IMPORT_CONDITION )
set ( EXPORT_IMPORT_CONDITION ${ TARGET_LIBRARY } _EXPORTS )
endif ( )
string ( MAKE_C_IDENTIFIER ${ EXPORT_IMPORT_CONDITION } EXPORT_IMPORT_CONDITION )
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 ( )
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 )
endmacro ( )
function ( GENERATE_EXPORT_HEADER TARGET_LIBRARY )
get_property ( type TARGET ${ TARGET_LIBRARY } PROPERTY TYPE )
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 "
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 "
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 " )
message ( WARNING "This macro can only be used with libraries" )
return ( )
endif ( )
_test_compiler_hidden_visibility ( )
_test_compiler_has_deprecated ( )
_do_set_macro_values ( ${ TARGET_LIBRARY } )
_do_generate_export_header ( ${ TARGET_LIBRARY } ${ ARGN } )
endfunction ( )
function ( add_compiler_export_flags )
if ( NOT CMAKE_MINIMUM_REQUIRED_VERSION VERSION_LESS 2.8.12 )
message ( DEPRECATION "The add_compiler_export_flags function is obsolete. Use the CXX_VISIBILITY_PRESET and VISIBILITY_INLINES_HIDDEN target properties instead." )
endif ( )
_test_compiler_hidden_visibility ( )
_test_compiler_has_deprecated ( )
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 )
if ( NOT ( USE_COMPILER_HIDDEN_VISIBILITY AND COMPILER_HAS_HIDDEN_VISIBILITY ) )
# Just return if there are no flags to add.
return ( )
endif ( )
set ( EXTRA_FLAGS "-fvisibility=hidden" )
if ( COMPILER_HAS_HIDDEN_INLINE_VISIBILITY )
set ( EXTRA_FLAGS "${EXTRA_FLAGS} -fvisibility-inlines-hidden" )
endif ( )
# Either return the extra flags needed in the supplied argument, or to the
# CMAKE_CXX_FLAGS if no argument is supplied.
if ( ARGC GREATER 0 )
set ( ${ ARGV0 } "${EXTRA_FLAGS}" PARENT_SCOPE )
else ( )
string ( APPEND CMAKE_CXX_FLAGS " ${EXTRA_FLAGS}" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE )
endif ( )
endfunction ( )