# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#[=======================================================================[.rst:
U s e J a v a
- - - - - - -
T h i s f i l e p r o v i d e s s u p p o r t f o r ` ` J a v a ` ` . I t i s a s s u m e d t h a t
: m o d u l e : ` F i n d J a v a ` h a s a l r e a d y b e e n l o a d e d . S e e : m o d u l e : ` F i n d J a v a ` f o r
i n f o r m a t i o n o n h o w t o l o a d J a v a i n t o y o u r C M a k e p r o j e c t .
S y n o p s i s
^ ^ ^ ^ ^ ^ ^ ^
. . p a r s e d - l i t e r a l : :
` C r e a t i n g a n d I n s t a l l i n g J A R S ` _
` a d d _ j a r ` _ ( <target_name> [SOURCES] <source1> [<source2>...] ... )
` i n s t a l l _ j a r ` _ ( <target_name> DESTINATION <destination> [COMPONENT <component>] )
` i n s t a l l _ j n i _ s y m l i n k ` _ ( <target_name> DESTINATION <destination> [COMPONENT <component>] )
` H e a d e r G e n e r a t i o n ` _
` c r e a t e _ j a v a h ` _ ( ( TARGET <target> | GENERATED_FILES <VAR> ) CLASSES <class>... ... )
` E x p o r t i n g J A R T a r g e t s ` _
` i n s t a l l _ j a r _ e x p o r t s ` _ ( TARGETS <jars>... FILE <filename> DESTINATION <destination> ... )
` e x p o r t _ j a r s ` _ ( TARGETS <jars>... [NAMESPACE <namespace>] FILE <filename> )
` F i n d i n g J A R s ` _
` f i n d _ j a r ` _ ( <VAR> NAMES <name1> [<name2>...] [PATHS <path1> [<path2>... ENV <var>]] ... )
` C r e a t i n g J a v a D o c u m e n t a t i o n ` _
` c r e a t e _ j a v a d o c ` _ ( <VAR> ( PACKAGES <pkg1> [<pkg2>...] | FILES <file1> [<file2>...] ) ... )
C r e a t i n g A n d I n s t a l l i n g J A R s
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
. . _ a d d _ j a r :
. . c o m m a n d : : a d d _ j a r
C r e a t e s a j a r f i l e c o n t a i n i n g j a v a o b j e c t s a n d , o p t i o n a l l y , r e s o u r c e s : :
add_jar ( <target_name>
[ S O U R C E S ] < s o u r c e 1 > [ < s o u r c e 2 > . . . ] [ < r e s o u r c e 1 > . . . ]
[ R E S O U R C E S N A M E S P A C E < n s 1 > < r e s o u r c e 1 > . . . [ N A M E S P A C E < n s X > < r e s o u r c e X > . . . ] . . . ]
[ I N C L U D E _ J A R S < j a r 1 > [ < j a r 2 > . . . ] ]
[ E N T R Y _ P O I N T < e n t r y > ]
[ V E R S I O N < v e r s i o n > ]
[ M A N I F E S T < m a n i f e s t > ]
[ O U T P U T _ N A M E < n a m e > ]
[ O U T P U T _ D I R < d i r > ]
[ G E N E R A T E _ N A T I V E _ H E A D E R S < t a r g e t >
[ DESTINATION ( <dir>|INSTALL <dir> [BUILD <dir>] ) ] ]
)
T h i s c o m m a n d c r e a t e s a ` ` < t a r g e t _ n a m e > . j a r ` ` . I t c o m p i l e s t h e g i v e n
` ` < s o u r c e > ` ` f i l e s a n d a d d s t h e g i v e n ` ` < r e s o u r c e > ` ` f i l e s t o
t h e j a r f i l e . S o u r c e f i l e s c a n b e j a v a f i l e s o r l i s t i n g f i l e s
( p r e f i x e d b y ` ` @ ` ` ) . I f o n l y r e s o u r c e f i l e s a r e g i v e n t h e n j u s t a j a r f i l e
i s c r e a t e d .
` ` S O U R C E S ` `
C o m p i l e s t h e s p e c i f i e d s o u r c e f i l e s a n d a d d s t h e r e s u l t i n t h e j a r f i l e .
. . v e r s i o n a d d e d : : 3 . 4
S u p p o r t f o r r e s p o n s e f i l e s , p r e f i x e d b y ` ` @ ` ` .
` ` R E S O U R C E S ` `
. . v e r s i o n a d d e d : : 3 . 2 1
A d d s t h e n a m e d ` ` < r e s o u r c e > ` ` f i l e s t o t h e j a r b y s t r i p p i n g t h e s o u r c e f i l e
p a t h a n d p l a c i n g t h e f i l e b e n e a t h ` ` < n s > ` ` w i t h i n t h e j a r .
F o r e x a m p l e : :
R E S O U R C E S N A M E S P A C E " / c o m / m y / n a m e s p a c e " " a / p a t h / t o / r e s o u r c e . t x t "
r e s u l t s i n a r e s o u r c e a c c e s s i b l e v i a ` ` / c o m / m y / n a m e s p a c e / r e s o u r c e . t x t ` `
w i t h i n t h e j a r .
R e s o u r c e s m a y b e a d d e d w i t h o u t a d j u s t i n g t h e n a m e s p a c e b y a d d i n g t h e m t o
t h e l i s t o f ` ` S O U R C E S ` ` ( o r i g i n a l b e h a v i o r ) , i n t h i s c a s e , r e s o u r c e
p a t h s m u s t b e r e l a t i v e t o ` ` C M A K E _ C U R R E N T _ S O U R C E _ D I R ` ` . A d d i n g r e s o u r c e s
w i t h o u t u s i n g t h e ` ` R E S O U R C E S ` ` p a r a m e t e r i n o u t o f s o u r c e b u i l d s w i l l
a l m o s t c e r t a i n l y r e s u l t i n c o n f u s i o n .
. . n o t e : :
A d d i n g r e s o u r c e s v i a t h e ` ` S O U R C E S ` ` p a r a m e t e r r e l i e s u p o n a h a r d - c o d e d
l i s t o f f i l e e x t e n s i o n s w h i c h a r e t e s t e d t o d e t e r m i n e w h e t h e r t h e y
compile ( e.g. File.java ) . ` ` S O U R C E S ` ` f i l e s w h i c h m a t c h t h e e x t e n s i o n s
a r e c o m p i l e d . F i l e s w h i c h d o n o t m a t c h a r e t r e a t e d a s r e s o u r c e s . T o
i n c l u d e u n c o m p i l e d r e s o u r c e s m a t c h i n g t h o s e f i l e e x t e n s i o n s u s e
t h e ` ` R E S O U R C E S ` ` p a r a m e t e r .
` ` I N C L U D E _ J A R S ` `
T h e l i s t o f j a r s a r e a d d e d t o t h e c l a s s p a t h w h e n c o m p i l i n g t h e j a v a s o u r c e s
a n d a l s o t o t h e d e p e n d e n c i e s o f t h e t a r g e t . ` ` I N C L U D E _ J A R S ` ` a l s o a c c e p t s
o t h e r t a r g e t n a m e s c r e a t e d b y ` ` add_jar ( ) ` ` . F o r b a c k w a r d s c o m p a t i b i l i t y ,
j a r f i l e s l i s t e d a s s o u r c e s a r e ignored ( as they have been since the first
v e r s i o n o f t h i s m o d u l e ) .
` ` E N T R Y _ P O I N T ` `
D e f i n e s a n e n t r y p o i n t i n t h e j a r f i l e .
` ` V E R S I O N ` `
A d d s a v e r s i o n t o t h e t a r g e t o u t p u t n a m e .
T h e f o l l o w i n g e x a m p l e w i l l c r e a t e a j a r f i l e w i t h t h e n a m e
` ` s h i b b o l e e t - 1 . 2 . 0 . j a r ` ` a n d w i l l c r e a t e a s y m l i n k ` ` s h i b b o l e e t . j a r ` `
p o i n t i n g t o t h e j a r w i t h t h e v e r s i o n i n f o r m a t i o n .
. . c o d e - b l o c k : : c m a k e
add_jar ( shibboleet shibbotleet.java VERSION 1.2.0 )
` ` M A N I F E S T ` `
D e f i n e s a c u s t o m m a n i f e s t f o r t h e j a r .
` ` O U T P U T _ N A M E ` `
S p e c i f y a d i f f e r e n t o u t p u t n a m e f o r t h e t a r g e t .
` ` O U T P U T _ D I R ` `
S e t s t h e d i r e c t o r y w h e r e t h e j a r f i l e w i l l b e g e n e r a t e d . I f n o t s p e c i f i e d ,
: v a r i a b l e : ` C M A K E _ C U R R E N T _ B I N A R Y _ D I R ` i s u s e d a s t h e o u t p u t d i r e c t o r y .
` ` G E N E R A T E _ N A T I V E _ H E A D E R S ` `
. . v e r s i o n a d d e d : : 3 . 1 1
G e n e r a t e s n a t i v e h e a d e r f i l e s f o r m e t h o d s d e c l a r e d a s n a t i v e . T h e s e f i l e s
p r o v i d e t h e c o n n e c t i v e g l u e t h a t a l l o w y o u r J a v a a n d C c o d e t o i n t e r a c t .
A n I N T E R F A C E t a r g e t w i l l b e c r e a t e d f o r a n e a s y u s a g e o f g e n e r a t e d f i l e s .
S u b - o p t i o n ` ` D E S T I N A T I O N ` ` c a n b e u s e d t o s p e c i f y t h e o u t p u t d i r e c t o r y f o r
g e n e r a t e d h e a d e r f i l e s .
T h i s o p t i o n r e q u i r e s , a t l e a s t , v e r s i o n 1 . 8 o f t h e J D K .
F o r a n o p t i m u m u s a g e o f t h i s o p t i o n , i t i s r e c o m m e n d e d t o i n c l u d e m o d u l e
J N I b e f o r e a n y c a l l t o ` ` add_jar ( ) ` ` . T h e p r o d u c e d t a r g e t f o r n a t i v e
h e a d e r s c a n t h e n b e u s e d t o c o m p i l e C / C + + s o u r c e s w i t h t h e
: c o m m a n d : ` t a r g e t _ l i n k _ l i b r a r i e s ` c o m m a n d .
. . c o d e - b l o c k : : c m a k e
find_package ( JNI )
add_jar ( foo foo.java GENERATE_NATIVE_HEADERS foo-native )
add_library ( bar bar.cpp )
target_link_libraries ( bar PRIVATE foo-native )
. . v e r s i o n a d d e d : : 3 . 2 0
` ` D E S T I N A T I O N ` ` s u b - o p t i o n n o w s u p p o r t s t h e p o s s i b i l i t y t o s p e c i f y
d i f f e r e n t o u t p u t d i r e c t o r i e s f o r ` ` B U I L D ` ` a n d ` ` I N S T A L L ` ` s t e p s . I f
` ` B U I L D ` ` d i r e c t o r y i s n o t s p e c i f i e d , a d e f a u l t d i r e c t o r y w i l l b e u s e d .
T o e x p o r t t h e i n t e r f a c e t a r g e t g e n e r a t e d b y ` ` G E N E R A T E _ N A T I V E _ H E A D E R S ` `
o p t i o n , s u b - o p t i o n ` ` I N S T A L L ` ` o f ` ` D E S T I N A T I O N ` ` i s r e q u i r e d :
. . c o d e - b l o c k : : c m a k e
add_jar ( foo foo.java GENERATE_NATIVE_HEADERS foo-native
D E S T I N A T I O N I N S T A L L i n c l u d e )
install ( TARGETS foo-native EXPORT native )
install ( DIRECTORY "$<TARGET_PROPERTY:foo-native,NATIVE_HEADERS_DIRECTORY>/"
D E S T I N A T I O N i n c l u d e )
install ( EXPORT native DESTINATION /to/export NAMESPACE foo )
S o m e v a r i a b l e s c a n b e s e t t o c u s t o m i z e t h e b e h a v i o r o f ` ` add_jar ( ) ` ` a s w e l l
a s t h e j a v a c o m p i l e r :
` ` C M A K E _ J A V A _ C O M P I L E _ F L A G S ` `
S p e c i f y a d d i t i o n a l f l a g s t o j a v a c o m p i l e r .
` ` C M A K E _ J A V A _ I N C L U D E _ P A T H ` `
S p e c i f y a d d i t i o n a l p a t h s t o t h e c l a s s p a t h .
` ` C M A K E _ J N I _ T A R G E T ` `
I f t h e t a r g e t i s a J N I l i b r a r y , s e t s t h i s b o o l e a n v a r i a b l e t o ` ` T R U E ` ` t o
e n a b l e c r e a t i o n o f a J N I s y m b o l i c link ( see also
: r e f : ` install_jni_symlink ( ) < i n s t a l l _ j n i _ s y m l i n k > ` ) .
` ` C M A K E _ J A R _ C L A S S E S _ P R E F I X ` `
I f m u l t i p l e j a r s s h o u l d b e p r o d u c e d f r o m t h e s a m e j a v a s o u r c e f i l e t r e e ,
t o p r e v e n t t h e a c c u m u l a t i o n o f d u p l i c a t e c l a s s f i l e s i n s u b s e q u e n t j a r s ,
s e t / r e s e t ` ` C M A K E _ J A R _ C L A S S E S _ P R E F I X ` ` p r i o r t o c a l l i n g t h e ` ` add_jar ( ) ` ` :
. . c o d e - b l o c k : : c m a k e
set ( CMAKE_JAR_CLASSES_PREFIX com/redhat/foo )
add_jar ( foo foo.java )
set ( CMAKE_JAR_CLASSES_PREFIX com/redhat/bar )
add_jar ( bar bar.java )
T h e ` ` add_jar ( ) ` ` f u n c t i o n s e t s t h e f o l l o w i n g t a r g e t p r o p e r t i e s o n
` ` < t a r g e t _ n a m e > ` ` :
` ` I N S T A L L _ F I L E S ` `
T h e f i l e s w h i c h s h o u l d b e i n s t a l l e d . T h i s i s u s e d b y
: r e f : ` install_jar ( ) < i n s t a l l _ j a r > ` .
` ` J N I _ S Y M L I N K ` `
T h e J N I s y m l i n k w h i c h s h o u l d b e i n s t a l l e d . T h i s i s u s e d b y
: r e f : ` install_jni_symlink ( ) < i n s t a l l _ j n i _ s y m l i n k > ` .
` ` J A R _ F I L E ` `
T h e l o c a t i o n o f t h e j a r f i l e s o t h a t y o u c a n i n c l u d e i t .
` ` C L A S S D I R ` `
T h e d i r e c t o r y w h e r e t h e c l a s s f i l e s c a n b e f o u n d . F o r e x a m p l e t o u s e t h e m
w i t h ` ` j a v a h ` ` .
` ` N A T I V E _ H E A D E R S _ D I R E C T O R Y ` `
. . v e r s i o n a d d e d : : 3 . 2 0
T h e d i r e c t o r y w h e r e n a t i v e h e a d e r s a r e g e n e r a t e d . D e f i n e d w h e n o p t i o n
` ` G E N E R A T E _ N A T I V E _ H E A D E R S ` ` i s s p e c i f i e d .
. . _ i n s t a l l _ j a r :
. . c o m m a n d : : i n s t a l l _ j a r
T h i s c o m m a n d i n s t a l l s t h e j a r f i l e t o t h e g i v e n d e s t i n a t i o n : :
install_jar ( <target_name> <destination> )
install_jar ( <target_name> DESTINATION <destination> [COMPONENT <component>] )
T h i s c o m m a n d i n s t a l l s t h e ` ` < t a r g e t _ n a m e > ` ` f i l e t o t h e g i v e n
` ` < d e s t i n a t i o n > ` ` . I t s h o u l d b e c a l l e d i n t h e s a m e s c o p e a s
: r e f : ` add_jar ( ) < a d d _ j a r > ` o r i t w i l l f a i l .
. . v e r s i o n a d d e d : : 3 . 4
T h e s e c o n d s i g n a t u r e w i t h ` ` D E S T I N A T I O N ` ` a n d ` ` C O M P O N E N T ` ` o p t i o n s .
` ` D E S T I N A T I O N ` `
S p e c i f y t h e d i r e c t o r y o n d i s k t o w h i c h a f i l e w i l l b e i n s t a l l e d .
` ` C O M P O N E N T ` `
S p e c i f y a n i n s t a l l a t i o n c o m p o n e n t n a m e w i t h w h i c h t h e i n s t a l l r u l e i s
a s s o c i a t e d , s u c h a s " r u n t i m e " o r " d e v e l o p m e n t " .
T h e ` ` install_jar ( ) ` ` c o m m a n d s e t s t h e f o l l o w i n g t a r g e t p r o p e r t i e s
o n ` ` < t a r g e t _ n a m e > ` ` :
` ` I N S T A L L _ D E S T I N A T I O N ` `
H o l d s t h e ` ` < d e s t i n a t i o n > ` ` a s d e s c r i b e d a b o v e , a n d i s u s e d b y
: r e f : ` install_jar_exports ( ) < i n s t a l l _ j a r _ e x p o r t s > ` .
. . _ i n s t a l l _ j n i _ s y m l i n k :
. . c o m m a n d : : i n s t a l l _ j n i _ s y m l i n k
I n s t a l l s J N I s y m l i n k s f o r t a r g e t g e n e r a t e d b y : r e f : ` add_jar ( ) < a d d _ j a r > ` : :
install_jni_symlink ( <target_name> <destination> )
install_jni_symlink ( <target_name> DESTINATION <destination> [COMPONENT <component>] )
T h i s c o m m a n d i n s t a l l s t h e ` ` < t a r g e t _ n a m e > ` ` J N I s y m l i n k s t o t h e g i v e n
` ` < d e s t i n a t i o n > ` ` . I t s h o u l d b e c a l l e d i n t h e s a m e s c o p e a s
: r e f : ` add_jar ( ) < a d d _ j a r > ` o r i t w i l l f a i l .
. . v e r s i o n a d d e d : : 3 . 4
T h e s e c o n d s i g n a t u r e w i t h ` ` D E S T I N A T I O N ` ` a n d ` ` C O M P O N E N T ` ` o p t i o n s .
` ` D E S T I N A T I O N ` `
S p e c i f y t h e d i r e c t o r y o n d i s k t o w h i c h a f i l e w i l l b e i n s t a l l e d .
` ` C O M P O N E N T ` `
S p e c i f y a n i n s t a l l a t i o n c o m p o n e n t n a m e w i t h w h i c h t h e i n s t a l l r u l e i s
a s s o c i a t e d , s u c h a s " r u n t i m e " o r " d e v e l o p m e n t " .
U t i l i z e t h e f o l l o w i n g c o m m a n d s t o c r e a t e a J N I s y m b o l i c l i n k :
. . c o d e - b l o c k : : c m a k e
set ( CMAKE_JNI_TARGET TRUE )
add_jar ( shibboleet shibbotleet.java VERSION 1.2.0 )
install_jar ( shibboleet ${ LIB_INSTALL_DIR } /shibboleet )
install_jni_symlink ( shibboleet ${ JAVA_LIB_INSTALL_DIR } )
H e a d e r G e n e r a t i o n
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
. . _ c r e a t e _ j a v a h :
. . c o m m a n d : : c r e a t e _ j a v a h
. . v e r s i o n a d d e d : : 3 . 4
G e n e r a t e s C h e a d e r f i l e s f o r j a v a c l a s s e s : :
create_javah ( TARGET <target> | GENERATED_FILES <VAR>
C L A S S E S < c l a s s > . . .
[ C L A S S P A T H < c l a s s p a t h > . . . ]
[ D E P E N D S < d e p e n d > . . . ]
[ O U T P U T _ N A M E < p a t h > | O U T P U T _ D I R < p a t h > ]
)
. . d e p r e c a t e d : : 3 . 1 1
T h i s c o m m a n d w i l l n o l o n g e r b e s u p p o r t e d s t a r t i n g w i t h v e r s i o n 1 0 o f t h e J D K
d u e t o t h e ` s u p p r e s s i o n o f j a v a h t o o l < h t t p s : / / o p e n j d k . o r g / j e p s / 3 1 3 > ` _ .
T h e : r e f : ` add_jar ( GENERATE_NATIVE_HEADERS ) < a d d _ j a r > ` c o m m a n d s h o u l d b e
u s e d i n s t e a d .
C r e a t e C h e a d e r f i l e s f r o m j a v a c l a s s e s . T h e s e f i l e s p r o v i d e t h e c o n n e c t i v e
g l u e t h a t a l l o w y o u r J a v a a n d C c o d e t o i n t e r a c t .
T h e r e a r e t w o m a i n s i g n a t u r e s f o r ` ` create_javah ( ) ` ` . T h e f i r s t s i g n a t u r e
r e t u r n s g e n e r a t e d f i l e s t h r o u g h v a r i a b l e s p e c i f i e d b y t h e ` ` G E N E R A T E D _ F I L E S ` `
o p 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
create_javah ( GENERATED_FILES files_headers
C L A S S E S o r g . c m a k e . H e l l o W o r l d
C L A S S P A T H h e l l o . j a r
)
T h e s e c o n d s i g n a t u r e f o r ` ` create_javah ( ) ` ` c r e a t e s a t a r g e t w h i c h
e n c a p s u l a t e s h e a d e r f i l e s g e n e r a t i o n . E . g .
. . c o d e - b l o c k : : c m a k e
create_javah ( TARGET target_headers
C L A S S E S o r g . c m a k e . H e l l o W o r l d
C L A S S P A T H h e l l o . j a r
)
B o t h s i g n a t u r e s s h a r e s a m e o p t i o n s .
` ` C L A S S E S ` `
S p e c i f i e s J a v a c l a s s e s u s e d t o g e n e r a t e h e a d e r s .
` ` C L A S S P A T H ` `
S p e c i f i e s v a r i o u s p a t h s t o l o o k u p c l a s s e s . H e r e ` ` . c l a s s ` ` f i l e s , j a r
f i l e s o r t a r g e t s c r e a t e d b y c o m m a n d a d d _ j a r c a n b e u s e d .
` ` D E P E N D S ` `
T a r g e t s o n w h i c h t h e j a v a h t a r g e t d e p e n d s .
` ` O U T P U T _ N A M E ` `
C o n c a t e n a t e s t h e r e s u l t i n g h e a d e r f i l e s f o r a l l t h e c l a s s e s l i s t e d b y
o p t i o n ` ` C L A S S E S ` ` i n t o ` ` < p a t h > ` ` . S a m e b e h a v i o r a s o p t i o n ` ` - o ` ` o f
` ` j a v a h ` ` t o o l .
` ` O U T P U T _ D I R ` `
S e t s t h e d i r e c t o r y w h e r e t h e h e a d e r f i l e s w i l l b e g e n e r a t e d . S a m e b e h a v i o r
a s o p t i o n ` ` - d ` ` o f ` ` j a v a h ` ` t o o l . I f n o t s p e c i f i e d ,
: v a r i a b l e : ` C M A K E _ C U R R E N T _ B I N A R Y _ D I R ` i s u s e d a s t h e o u t p u t d i r e c t o r y .
E x p o r t i n g J A R T a r g e t s
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
. . _ i n s t a l l _ j a r _ e x p o r t s :
. . c o m m a n d : : i n s t a l l _ j a r _ e x p o r t s
. . v e r s i o n a d d e d : : 3 . 7
I n s t a l l s a t a r g e t e x p o r t f i l e : :
install_jar_exports ( TARGETS <jars>...
[ N A M E S P A C E < n a m e s p a c e > ]
F I L E < f i l e n a m e >
D E S T I N A T I O N < d e s t i n a t i o n > [ C O M P O N E N T < c o m p o n e n t > ] )
T h i s c o m m a n d i n s t a l l s a t a r g e t e x p o r t f i l e ` ` < f i l e n a m e > ` ` f o r t h e n a m e d j a r
t a r g e t s t o t h e g i v e n ` ` < d e s t i n a t i o n > ` ` d i r e c t o r y . I t s f u n c t i o n i s s i m i l a r t o
t h a t o f : c o m m a n d : ` install ( EXPORT ) ` .
` ` T A R G E T S ` `
L i s t o f t a r g e t s c r e a t e d b y : r e f : ` add_jar ( ) < a d d _ j a r > ` c o m m a n d .
` ` N A M E S P A C E ` `
. . v e r s i o n a d d e d : : 3 . 9
T h e ` ` < n a m e s p a c e > ` ` v a l u e w i l l b e p r e p e n d t o t h e t a r g e t n a m e s a s t h e y a r e
w r i t t e n t o t h e i m p o r t f i l e .
` ` F I L E ` `
S p e c i f y n a m e o f t h e e x p o r t f i l e .
` ` D E S T I N A T I O N ` `
S p e c i f y t h e d i r e c t o r y o n d i s k t o w h i c h a f i l e w i l l b e i n s t a l l e d .
` ` C O M P O N E N T ` `
S p e c i f y a n i n s t a l l a t i o n c o m p o n e n t n a m e w i t h w h i c h t h e i n s t a l l r u l e i s
a s s o c i a t e d , s u c h a s " r u n t i m e " o r " d e v e l o p m e n t " .
. . _ e x p o r t _ j a r s :
. . c o m m a n d : : e x p o r t _ j a r s
. . v e r s i o n a d d e d : : 3 . 7
W r i t e s a t a r g e t e x p o r t f i l e : :
export_jars ( TARGETS <jars>...
[ N A M E S P A C E < n a m e s p a c e > ]
F I L E < f i l e n a m e > )
T h i s c o m m a n d w r i t e s a t a r g e t e x p o r t f i l e ` ` < f i l e n a m e > ` ` f o r t h e n a m e d ` ` < j a r s > ` `
t a r g e t s . I t s f u n c t i o n i s s i m i l a r t o t h a t o f : c o m m a n d : ` e x p o r t ` .
` ` T A R G E T S ` `
L i s t o f t a r g e t s c r e a t e d b y : r e f : ` add_jar ( ) < a d d _ j a r > ` c o m m a n d .
` ` N A M E S P A C E ` `
. . v e r s i o n a d d e d : : 3 . 9
T h e ` ` < n a m e s p a c e > ` ` v a l u e w i l l b e p r e p e n d t o t h e t a r g e t n a m e s a s t h e y a r e
w r i t t e n t o t h e i m p o r t f i l e .
` ` F I L E ` `
S p e c i f y n a m e o f t h e e x p o r t f i l e .
F i n d i n g J A R s
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
. . _ f i n d _ j a r :
. . c o m m a n d : : f i n d _ j a r
F i n d s t h e s p e c i f i e d j a r f i l e : :
find_jar ( <VAR>
< n a m e > | N A M E S < n a m e 1 > [ < n a m e 2 > . . . ]
[ P A T H S < p a t h 1 > [ < p a t h 2 > . . . E N V < v a r > ] ]
[ V E R S I O N S < v e r s i o n 1 > [ < v e r s i o n 2 > ] ]
[ D O C " c a c h e d o c u m e n t a t i o n s t r i n g " ]
)
T h i s c o m m a n d i s u s e d t o f i n d a f u l l p a t h t o t h e n a m e d j a r . A c a c h e
e n t r y n a m e d b y ` ` < V A R > ` ` i s c r e a t e d t o s t o r e t h e r e s u l t o f t h i s c o m m a n d .
I f t h e f u l l p a t h t o a j a r i s f o u n d t h e r e s u l t i s s t o r e d i n t h e
v a r i a b l e a n d t h e s e a r c h w i l l n o t r e p e a t e d u n l e s s t h e v a r i a b l e i s
c l e a r e d . I f n o t h i n g i s f o u n d , t h e r e s u l t w i l l b e ` ` < V A R > - N O T F O U N D ` ` , a n d
t h e s e a r c h w i l l b e a t t e m p t e d a g a i n n e x t t i m e ` ` find_jar ( ) ` ` i s i n v o k e d w i t h
t h e s a m e v a r i a b l e .
` ` N A M E S ` `
S p e c i f y o n e o r m o r e p o s s i b l e n a m e s f o r t h e j a r f i l e .
` ` P A T H S ` `
S p e c i f y d i r e c t o r i e s t o s e a r c h i n a d d i t i o n t o t h e d e f a u l t l o c a t i o n s .
T h e ` ` E N V ` ` v a r s u b - o p t i o n r e a d s p a t h s f r o m a s y s t e m e n v i r o n m e n t v a r i a b l e .
` ` V E R S I O N S ` `
S p e c i f y j a r v e r s i o n s .
` ` D O C ` `
S p e c i f y t h e d o c u m e n t a t i o n s t r i n g f o r t h e ` ` < V A R > ` ` c a c h e e n t r y .
C r e a t i n g J a v a D o c u m e n t a t i o n
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
. . _ c r e a t e _ j a v a d o c :
. . c o m m a n d : : c r e a t e _ j a v a d o c
C r e a t e s j a v a d o c u m e n t a t i o n b a s e d o n f i l e s a n d p a c k a g e s : :
create_javadoc ( <VAR>
( P A C K A G E S < p k g 1 > [ < p k g 2 > . . . ] | F I L E S < f i l e 1 > [ < f i l e 2 > . . . ] )
[ S O U R C E P A T H < s o u r c e p a t h > ]
[ C L A S S P A T H < c l a s s p a t h > ]
[ I N S T A L L P A T H < i n s t a l l p a t h > ]
[ D O C T I T L E < t h e d o c u m e n t a t i o n t i t l e > ]
[ W I N D O W T I T L E < t h e t i t l e o f t h e d o c u m e n t > ]
[ AUTHOR ( TRUE|FALSE ) ]
[ USE ( TRUE|FALSE ) ]
[ VERSION ( TRUE|FALSE ) ]
)
T h e ` ` create_javadoc ( ) ` ` c o m m a n d c a n b e u s e d t o c r e a t e j a v a d o c u m e n t a t i o n .
T h e r e a r e t w o m a i n s i g n a t u r e s f o r ` ` create_javadoc ( ) ` ` .
T h e f i r s t s i g n a t u r e w o r k s w i t h p a c k a g e n a m e s o n a p a t h w i t h s o u r c e f i l e s :
. . c o d e - b l o c k : : c m a k e
create_javadoc ( my_example_doc
P A C K A G E S c o m . e x a m p l e . f o o c o m . e x a m p l e . b a r
S O U R C E P A T H " $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R } "
C L A S S P A T H $ { C M A K E _ J A V A _ I N C L U D E _ P A T H }
W I N D O W T I T L E " M y e x a m p l e "
D O C T I T L E " < h 1 > M y e x a m p l e < / h 1 > "
A U T H O R T R U E
U S E T R U E
V E R S I O N T R U E
)
T h e s e c o n d s i g n a t u r e f o r ` ` create_javadoc ( ) ` ` w o r k s o n a g i v e n l i s t o f f i l e s :
. . c o d e - b l o c k : : c m a k e
create_javadoc ( my_example_doc
F I L E S j a v a / A . j a v a j a v a / B . j a v a
C L A S S P A T H $ { C M A K E _ J A V A _ I N C L U D E _ P A T H }
W I N D O W T I T L E " M y e x a m p l e "
D O C T I T L E " < h 1 > M y e x a m p l e < / h 1 > "
A U T H O R T R U E
U S E T R U E
V E R S I O N T R U E
)
B o t h s i g n a t u r e s s h a r e m o s t o f t h e o p t i o n s . F o r m o r e d e t a i l s p l e a s e r e a d t h e
j a v a d o c m a n p a g e .
` ` P A C K A G E S ` `
S p e c i f y j a v a p a c k a g e s .
` ` F I L E S ` `
S p e c i f y j a v a s o u r c e f i l e s . I f r e l a t i v e p a t h s a r e s p e c i f i e d , t h e y a r e
r e l a t i v e t o : v a r i a b l e : ` C M A K E _ C U R R E N T _ S O U R C E _ D I R ` .
` ` S O U R C E P A T H ` `
S p e c i f y t h e d i r e c t o r y w h e r e t o l o o k f o r p a c k a g e s . B y d e f a u l t ,
: v a r i a b l e : ` C M A K E _ C U R R E N T _ S O U R C E _ D I R ` d i r e c t o r y i s u s e d .
` ` C L A S S P A T H ` `
S p e c i f y w h e r e t o f i n d u s e r c l a s s f i l e s . S a m e b e h a v i o r a s o p t i o n
` ` - c l a s s p a t h ` ` o f ` ` j a v a d o c ` ` t o o l .
` ` I N S T A L L P A T H ` `
S p e c i f y w h e r e t o i n s t a l l t h e j a v a d o c u m e n t a t i o n . I f y o u s p e c i f i e d , t h e
d o c u m e n t a t i o n w i l l b e i n s t a l l e d t o
` ` $ { C M A K E _ I N S T A L L _ P R E F I X } / s h a r e / j a v a d o c / < V A R > ` ` .
` ` D O C T I T L E ` `
S p e c i f y t h e t i t l e t o p l a c e n e a r t h e t o p o f t h e o v e r v i e w s u m m a r y f i l e .
S a m e b e h a v i o r a s o p t i o n ` ` - d o c t i t l e ` ` o f ` ` j a v a d o c ` ` t o o l .
` ` W I N D O W T I T L E ` `
S p e c i f y t h e t i t l e t o b e p l a c e d i n t h e H T M L ` ` < t i t l e > ` ` t a g . S a m e b e h a v i o r
a s o p t i o n ` ` - w i n d o w t i t l e ` ` o f ` ` j a v a d o c ` ` t o o l .
` ` A U T H O R ` `
W h e n v a l u e ` ` T R U E ` ` i s s p e c i f i e d , i n c l u d e s t h e ` ` @ a u t h o r ` ` t e x t i n t h e
g e n e r a t e d d o c s . S a m e b e h a v i o r a s o p t i o n ` ` - a u t h o r ` ` o f ` ` j a v a d o c ` ` t o o l .
` ` U S E ` `
W h e n v a l u e ` ` T R U E ` ` i s s p e c i f i e d , c r e a t e s c l a s s a n d p a c k a g e u s a g e p a g e s .
I n c l u d e s o n e U s e p a g e f o r e a c h d o c u m e n t e d c l a s s a n d p a c k a g e . S a m e b e h a v i o r
a s o p t i o n ` ` - u s e ` ` o f ` ` j a v a d o c ` ` t o o l .
` ` V E R S I O N ` `
W h e n v a l u e ` ` T R U E ` ` i s s p e c i f i e d , i n c l u d e s t h e v e r s i o n t e x t i n t h e
g e n e r a t e d d o c s . S a m e b e h a v i o r a s o p t i o n ` ` - v e r s i o n ` ` o f ` ` j a v a d o c ` ` t o o l .
#]=======================================================================]
function ( __java_copy_file src dest comment )
add_custom_command (
O U T P U T $ { d e s t }
C O M M A N D $ { C M A K E _ C O M M A N D } - E c o p y _ i f _ d i f f e r e n t
A R G S $ { s r c }
$ { d e s t }
D E P E N D S $ { s r c }
C O M M E N T $ { c o m m e n t }
V E R B A T I M
)
endfunction ( )
function ( __java_lcat VAR )
foreach ( _line IN LISTS ARGN )
string ( APPEND ${ VAR } "${_line}\n" )
endforeach ( )
set ( ${ VAR } "${${VAR}}" PARENT_SCOPE )
endfunction ( )
function ( __java_export_jar VAR TARGET PATH )
get_target_property ( _jarpath ${ TARGET } JAR_FILE )
get_filename_component ( _jarname ${ _jarpath } NAME )
set ( _target "${_jar_NAMESPACE}${TARGET}" )
__java_lcat ( ${ VAR }
" # Create imported target ${_target}"
" add_library ( ${ _target } IMPORTED STATIC ) "
" set_target_properties ( ${ _target } PROPERTIES "
" I M P O R T E D _ L O C A T I O N \ " $ { P A T H } / $ { _ j a r n a m e } \ " "
" J A R _ F I L E \ " $ { P A T H } / $ { _ j a r n a m e } \ " ) "
" "
)
set ( ${ VAR } "${${VAR}}" PARENT_SCOPE )
endfunction ( )
function ( __java_copy_resource_namespaces VAR DEST JAVA_RESOURCE_FILES JAVA_RESOURCE_FILES_RELATIVE )
set ( _ns_ID "" )
set ( _ns_VAL "" )
foreach ( _item IN LISTS VAR )
if ( NOT _ns_ID )
if ( NOT _item STREQUAL "NAMESPACE" )
message ( FATAL_ERROR "UseJava: Expecting \" NAMESPACE\ ", got\t\" ${ _item } \"")
return ( )
endif ( )
endif ( )
if ( _item STREQUAL "NAMESPACE" )
set ( _ns_VAL "" ) # Prepare for next namespace
set ( _ns_ID "${_item}" )
continue ( )
endif ( )
if ( NOT _ns_VAL )
# we're expecting the next token to be a namespace value
# whatever it is, we're treating it like a namespace
set ( _ns_VAL "${_item}" )
continue ( )
endif ( )
if ( _ns_ID AND _ns_VAL )
# We're expecting a file name, check to see if we got one
cmake_path ( ABSOLUTE_PATH _item OUTPUT_VARIABLE _test_file_name )
if ( NOT EXISTS "${_test_file_name}" )
message ( FATAL_ERROR "UseJava: File does not exist:\t${_item}" )
return ( )
endif ( )
endif ( )
cmake_path ( ABSOLUTE_PATH _item OUTPUT_VARIABLE _abs_file_name )
cmake_path ( GET _item FILENAME _resource_file_name )
set ( _dest_resource_file_name "${_ns_VAL}/${_resource_file_name}" )
__java_copy_file ( ${ _abs_file_name }
$ { D E S T } / $ { _ d e s t _ r e s o u r c e _ f i l e _ n a m e }
" C o p y i n g $ { _ i t e m } t o t h e b u i l d d i r e c t o r y " )
list ( APPEND RESOURCE_FILES_LIST ${ DEST } / ${ _dest_resource_file_name } )
list ( APPEND RELATIVE_RESOURCE_FILES_LIST ${ _dest_resource_file_name } )
endforeach ( )
set ( ${ JAVA_RESOURCE_FILES } "${RESOURCE_FILES_LIST}" PARENT_SCOPE )
set ( ${ JAVA_RESOURCE_FILES_RELATIVE } "${RELATIVE_RESOURCE_FILES_LIST}" PARENT_SCOPE )
endfunction ( )
# define helper scripts
set ( _JAVA_EXPORT_TARGETS_SCRIPT ${ CMAKE_CURRENT_LIST_DIR } /UseJava/javaTargets.cmake.in )
set ( _JAVA_SYMLINK_SCRIPT ${ CMAKE_CURRENT_LIST_DIR } /UseJava/Symlinks.cmake )
if ( CMAKE_HOST_WIN32 AND NOT CYGWIN AND CMAKE_HOST_SYSTEM_NAME MATCHES "Windows" )
set ( _UseJava_PATH_SEP "$<SEMICOLON>" )
else ( )
set ( _UseJava_PATH_SEP ":" )
endif ( )
function ( add_jar _TARGET_NAME )
set ( options ) # currently there are no zero value args (aka: options)
set ( oneValueArgs "ENTRY_POINT;MANIFEST;OUTPUT_DIR;;OUTPUT_NAME;VERSION" )
set ( multiValueArgs "GENERATE_NATIVE_HEADERS;INCLUDE_JARS;RESOURCES;SOURCES" )
cmake_parse_arguments ( PARSE_ARGV 1 _add_jar
" $ { o p t i o n s } "
" $ { o n e V a l u e A r g s } "
" $ { m u l t i V a l u e A r g s } " )
# In CMake < 2.8.12, add_jar used variables which were set prior to calling
# add_jar for customizing the behavior of add_jar. In order to be backwards
# compatible, check if any of those variables are set, and use them to
# initialize values of the named arguments. (Giving the corresponding named
# argument will override the value set here.)
#
# New features should use named arguments only.
if ( NOT DEFINED _add_jar_VERSION AND DEFINED CMAKE_JAVA_TARGET_VERSION )
set ( _add_jar_VERSION "${CMAKE_JAVA_TARGET_VERSION}" )
endif ( )
if ( NOT DEFINED _add_jar_OUTPUT_DIR AND DEFINED CMAKE_JAVA_TARGET_OUTPUT_DIR )
set ( _add_jar_OUTPUT_DIR "${CMAKE_JAVA_TARGET_OUTPUT_DIR}" )
endif ( )
if ( NOT DEFINED _add_jar_OUTPUT_NAME AND DEFINED CMAKE_JAVA_TARGET_OUTPUT_NAME )
set ( _add_jar_OUTPUT_NAME "${CMAKE_JAVA_TARGET_OUTPUT_NAME}" )
# reset
set ( CMAKE_JAVA_TARGET_OUTPUT_NAME )
endif ( )
if ( NOT DEFINED _add_jar_ENTRY_POINT AND DEFINED CMAKE_JAVA_JAR_ENTRY_POINT )
set ( _add_jar_ENTRY_POINT "${CMAKE_JAVA_JAR_ENTRY_POINT}" )
endif ( )
# This *should* still work if <resources1>... are included without a
# named RESOURCES argument. In that case, the old behavior of potentially
# misplacing the within the Jar will behave as previously (incorrectly)
set ( _JAVA_SOURCE_FILES ${ _add_jar_SOURCES } ${ _add_jar_UNPARSED_ARGUMENTS } )
if ( NOT DEFINED _add_jar_OUTPUT_DIR )
set ( _add_jar_OUTPUT_DIR ${ CMAKE_CURRENT_BINARY_DIR } )
else ( )
get_filename_component ( _add_jar_OUTPUT_DIR ${ _add_jar_OUTPUT_DIR } ABSOLUTE )
endif ( )
# ensure output directory exists
file ( MAKE_DIRECTORY "${_add_jar_OUTPUT_DIR}" )
if ( _add_jar_ENTRY_POINT )
set ( _ENTRY_POINT_OPTION e )
set ( _ENTRY_POINT_VALUE ${ _add_jar_ENTRY_POINT } )
endif ( )
if ( _add_jar_MANIFEST )
set ( _MANIFEST_OPTION m )
get_filename_component ( _MANIFEST_VALUE "${_add_jar_MANIFEST}" ABSOLUTE )
endif ( )
unset ( _GENERATE_NATIVE_HEADERS )
if ( _add_jar_GENERATE_NATIVE_HEADERS )
# Raise an error if JDK version is less than 1.8 because javac -h is not supported
# by earlier versions.
if ( Java_VERSION VERSION_LESS 1.8 )
message ( FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS is not supported with this version of Java." )
endif ( )
unset ( _GENERATE_NATIVE_HEADERS_OUTPUT_DESC )
cmake_parse_arguments ( _add_jar_GENERATE_NATIVE_HEADERS "" "" "DESTINATION" ${ _add_jar_GENERATE_NATIVE_HEADERS } )
if ( NOT _add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS )
message ( FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: missing required argument." )
endif ( )
list ( LENGTH _add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS length )
if ( length GREATER 1 )
list ( REMOVE_AT _add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS 0 )
message ( FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: ${_add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS}: unexpected argument(s)." )
endif ( )
if ( NOT _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION )
set ( _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir/native_headers" )
else ( )
list ( LENGTH _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION length )
if ( NOT length EQUAL 1 )
cmake_parse_arguments ( _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION "" "BUILD;INSTALL" "" "${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION}" )
if ( _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_UNPARSED_ARGUMENTS )
message ( FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: DESTINATION: ${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_UNPARSED_ARGUMENTS}: unexpected argument(s)." )
endif ( )
if ( NOT _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_INSTALL )
message ( FATAL_ERROR "ADD_JAR: GENERATE_NATIVE_HEADERS: DESTINATION: INSTALL sub-option is required." )
endif ( )
if ( NOT _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_BUILD )
set ( _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_BUILD "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir/native_headers" )
endif ( )
set ( _add_jar_GENERATE_NATIVE_HEADERS_DESTINATION "${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_BUILD}" )
set ( _GENERATE_NATIVE_HEADERS_OUTPUT_DESC "$<BUILD_INTERFACE:${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_BUILD}>" "$<INSTALL_INTERFACE:${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION_INSTALL}>" )
endif ( )
endif ( )
set ( _GENERATE_NATIVE_HEADERS_TARGET ${ _add_jar_GENERATE_NATIVE_HEADERS_UNPARSED_ARGUMENTS } )
set ( _GENERATE_NATIVE_HEADERS_OUTPUT_DIR "${_add_jar_GENERATE_NATIVE_HEADERS_DESTINATION}" )
set ( _GENERATE_NATIVE_HEADERS -h "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}" )
if ( NOT _GENERATE_NATIVE_HEADERS_OUTPUT_DESC )
set ( _GENERATE_NATIVE_HEADERS_OUTPUT_DESC "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}" )
endif ( )
endif ( )
if ( LIBRARY_OUTPUT_PATH )
set ( CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${ LIBRARY_OUTPUT_PATH } )
else ( )
set ( CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${ _add_jar_OUTPUT_DIR } )
endif ( )
set ( CMAKE_JAVA_INCLUDE_PATH
$ { C M A K E _ J A V A _ I N C L U D E _ P A T H }
$ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
$ { C M A K E _ J A V A _ O B J E C T _ O U T P U T _ P A T H }
$ { C M A K E _ J A V A _ L I B R A R Y _ O U T P U T _ P A T H }
)
foreach ( JAVA_INCLUDE_DIR IN LISTS CMAKE_JAVA_INCLUDE_PATH )
string ( APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL "${_UseJava_PATH_SEP}${JAVA_INCLUDE_DIR}" )
endforeach ( )
set ( CMAKE_JAVA_CLASS_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir" )
set ( _JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}.jar" )
if ( _add_jar_OUTPUT_NAME AND _add_jar_VERSION )
set ( _JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}-${_add_jar_VERSION}.jar" )
set ( _JAVA_TARGET_OUTPUT_LINK "${_add_jar_OUTPUT_NAME}.jar" )
elseif ( _add_jar_VERSION )
set ( _JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}-${_add_jar_VERSION}.jar" )
set ( _JAVA_TARGET_OUTPUT_LINK "${_TARGET_NAME}.jar" )
elseif ( _add_jar_OUTPUT_NAME )
set ( _JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}.jar" )
endif ( )
set ( _JAVA_CLASS_FILES )
set ( _JAVA_COMPILE_FILES )
set ( _JAVA_COMPILE_FILELISTS )
set ( _JAVA_DEPENDS )
set ( _JAVA_COMPILE_DEPENDS )
set ( _JAVA_RESOURCE_FILES )
set ( _JAVA_RESOURCE_FILES_RELATIVE )
foreach ( _JAVA_SOURCE_FILE IN LISTS _JAVA_SOURCE_FILES )
get_filename_component ( _JAVA_EXT ${ _JAVA_SOURCE_FILE } EXT )
get_filename_component ( _JAVA_FILE ${ _JAVA_SOURCE_FILE } NAME_WE )
get_filename_component ( _JAVA_PATH ${ _JAVA_SOURCE_FILE } PATH )
get_filename_component ( _JAVA_FULL ${ _JAVA_SOURCE_FILE } ABSOLUTE )
if ( _JAVA_SOURCE_FILE MATCHES "^@(.+)$" )
get_filename_component ( _JAVA_FULL ${ CMAKE_MATCH_1 } ABSOLUTE )
list ( APPEND _JAVA_COMPILE_FILELISTS ${ _JAVA_FULL } )
elseif ( _JAVA_EXT MATCHES ".java" )
file ( RELATIVE_PATH _JAVA_REL_BINARY_PATH ${ CMAKE_CURRENT_BINARY_DIR } ${ _JAVA_FULL } )
file ( RELATIVE_PATH _JAVA_REL_SOURCE_PATH ${ CMAKE_CURRENT_SOURCE_DIR } ${ _JAVA_FULL } )
string ( LENGTH ${ _JAVA_REL_BINARY_PATH } _BIN_LEN )
string ( LENGTH ${ _JAVA_REL_SOURCE_PATH } _SRC_LEN )
if ( _BIN_LEN LESS _SRC_LEN )
set ( _JAVA_REL_PATH ${ _JAVA_REL_BINARY_PATH } )
else ( )
set ( _JAVA_REL_PATH ${ _JAVA_REL_SOURCE_PATH } )
endif ( )
get_filename_component ( _JAVA_REL_PATH ${ _JAVA_REL_PATH } PATH )
list ( APPEND _JAVA_COMPILE_FILES ${ _JAVA_SOURCE_FILE } )
set ( _JAVA_CLASS_FILE "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_REL_PATH}/${_JAVA_FILE}.class" )
set ( _JAVA_CLASS_FILES ${ _JAVA_CLASS_FILES } ${ _JAVA_CLASS_FILE } )
elseif ( _JAVA_EXT MATCHES ".jar"
O R _ J A V A _ E X T M A T C H E S " . w a r "
O R _ J A V A _ E X T M A T C H E S " . e a r "
O R _ J A V A _ E X T M A T C H E S " . s a r " )
# Ignored for backward compatibility
elseif ( _JAVA_EXT STREQUAL "" )
list ( APPEND CMAKE_JAVA_INCLUDE_PATH ${ JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE } } ${ JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE } _CLASSPATH} )
list ( APPEND _JAVA_DEPENDS ${ JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE } } )
else ( )
__java_copy_file ( ${ CMAKE_CURRENT_SOURCE_DIR } / ${ _JAVA_SOURCE_FILE }
$ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H } / $ { _ J A V A _ S O U R C E _ F I L E }
" C o p y i n g $ { _ J A V A _ S O U R C E _ F I L E } t o t h e b u i l d d i r e c t o r y " )
list ( APPEND _JAVA_RESOURCE_FILES ${ CMAKE_JAVA_CLASS_OUTPUT_PATH } / ${ _JAVA_SOURCE_FILE } )
list ( APPEND _JAVA_RESOURCE_FILES_RELATIVE ${ _JAVA_SOURCE_FILE } )
endif ( )
endforeach ( )
if ( _add_jar_RESOURCES ) # Process RESOURCES if it exists
__java_copy_resource_namespaces ( "${_add_jar_RESOURCES}"
$ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H }
_ J A V A _ R E S O U R C E _ F I L E S
_ J A V A _ R E S O U R C E _ F I L E S _ R E L A T I V E )
endif ( )
foreach ( _JAVA_INCLUDE_JAR IN LISTS _add_jar_INCLUDE_JARS )
if ( TARGET ${ _JAVA_INCLUDE_JAR } )
get_target_property ( _JAVA_JAR_PATH ${ _JAVA_INCLUDE_JAR } JAR_FILE )
if ( _JAVA_JAR_PATH )
string ( APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL "${_UseJava_PATH_SEP}${_JAVA_JAR_PATH}" )
list ( APPEND CMAKE_JAVA_INCLUDE_PATH ${ _JAVA_JAR_PATH } )
list ( APPEND _JAVA_DEPENDS ${ _JAVA_INCLUDE_JAR } )
list ( APPEND _JAVA_COMPILE_DEPENDS ${ _JAVA_JAR_PATH } )
else ( )
message ( SEND_ERROR "add_jar: INCLUDE_JARS target ${_JAVA_INCLUDE_JAR} is not a jar" )
endif ( )
else ( )
string ( APPEND CMAKE_JAVA_INCLUDE_PATH_FINAL "${_UseJava_PATH_SEP}${_JAVA_INCLUDE_JAR}" )
list ( APPEND CMAKE_JAVA_INCLUDE_PATH "${_JAVA_INCLUDE_JAR}" )
list ( APPEND _JAVA_DEPENDS "${_JAVA_INCLUDE_JAR}" )
list ( APPEND _JAVA_COMPILE_DEPENDS "${_JAVA_INCLUDE_JAR}" )
endif ( )
endforeach ( )
if ( _JAVA_COMPILE_FILES OR _JAVA_COMPILE_FILELISTS )
set ( _JAVA_SOURCES_FILELISTS )
if ( _JAVA_COMPILE_FILES )
# Create the list of files to compile.
set ( _JAVA_SOURCES_FILE ${ CMAKE_JAVA_CLASS_OUTPUT_PATH } /java_sources )
string ( REPLACE ";" "\" \n\"" _JAVA_COMPILE_STRING "\" ${ _JAVA_COMPILE_FILES } \"")
set ( CMAKE_CONFIGURABLE_FILE_CONTENT "${_JAVA_COMPILE_STRING}" )
configure_file ( "${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
" $ { _ J A V A _ S O U R C E S _ F I L E } " @ O N L Y )
unset ( CMAKE_CONFIGURABLE_FILE_CONTENT )
list ( APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_SOURCES_FILE}" )
endif ( )
if ( _JAVA_COMPILE_FILELISTS )
foreach ( _JAVA_FILELIST IN LISTS _JAVA_COMPILE_FILELISTS )
list ( APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_FILELIST}" )
endforeach ( )
endif ( )
cmake_language ( GET_MESSAGE_LOG_LEVEL _LOG_LEVEL )
# Compile the java files and create a list of class files
add_custom_command (
# NOTE: this command generates an artificial dependency file
O U T P U T $ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H } / j a v a _ c o m p i l e d _ $ { _ T A R G E T _ N A M E }
C O M M A N D $ { C M A K E _ C O M M A N D }
- D C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H = $ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H }
- D C M A K E _ J A R _ C L A S S E S _ P R E F I X = $ { C M A K E _ J A R _ C L A S S E S _ P R E F I X }
- P $ { C M A K E _ C U R R E N T _ F U N C T I O N _ L I S T _ D I R } / U s e J a v a / C l e a r C l a s s F i l e s . c m a k e
- - l o g - l e v e l $ { _ L O G _ L E V E L }
C O M M A N D $ { J a v a _ J A V A C _ E X E C U T A B L E }
$ { C M A K E _ J A V A _ C O M P I L E _ F L A G S }
- c l a s s p a t h " $ { C M A K E _ J A V A _ I N C L U D E _ P A T H _ F I N A L } "
- d $ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H }
$ { _ G E N E R A T E _ N A T I V E _ H E A D E R S }
$ { _ J A V A _ S O U R C E S _ F I L E L I S T S }
C O M M A N D $ { C M A K E _ C O M M A N D } - E t o u c h $ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H } / j a v a _ c o m p i l e d _ $ { _ T A R G E T _ N A M E }
D E P E N D S $ { _ J A V A _ C O M P I L E _ F I L E S } $ { _ J A V A _ C O M P I L E _ F I L E L I S T S } $ { _ J A V A _ C O M P I L E _ D E P E N D S } $ { _ J A V A _ S O U R C E S _ F I L E }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
C O M M E N T " B u i l d i n g J a v a o b j e c t s f o r $ { _ T A R G E T _ N A M E } . j a r "
V E R B A T I M
)
add_custom_command (
O U T P U T $ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H } / j a v a _ c l a s s _ f i l e l i s t
C O M M A N D $ { C M A K E _ C O M M A N D }
- D C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H = $ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H }
- D C M A K E _ J A R _ C L A S S E S _ P R E F I X = $ { C M A K E _ J A R _ C L A S S E S _ P R E F I X }
- P $ { C M A K E _ C U R R E N T _ F U N C T I O N _ L I S T _ D I R } / U s e J a v a / C l a s s F i l e l i s t . c m a k e
D E P E N D S $ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H } / j a v a _ c o m p i l e d _ $ { _ T A R G E T _ N A M E }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
V E R B A T I M
)
else ( )
# create an empty java_class_filelist
if ( NOT EXISTS ${ CMAKE_JAVA_CLASS_OUTPUT_PATH } /java_class_filelist )
file ( WRITE ${ CMAKE_JAVA_CLASS_OUTPUT_PATH } /java_class_filelist "" )
endif ( )
endif ( )
# create the jar file
set ( _JAVA_JAR_OUTPUT_PATH
" $ { _ a d d _ j a r _ O U T P U T _ D I R } / $ { _ J A V A _ T A R G E T _ O U T P U T _ N A M E } " )
if ( CMAKE_JNI_TARGET )
add_custom_command (
O U T P U T $ { _ J A V A _ J A R _ O U T P U T _ P A T H }
C O M M A N D $ { J a v a _ J A R _ E X E C U T A B L E }
- c f $ { _ E N T R Y _ P O I N T _ O P T I O N } $ { _ M A N I F E S T _ O P T I O N } $ { _ J A V A _ J A R _ O U T P U T _ P A T H } $ { _ E N T R Y _ P O I N T _ V A L U E } $ { _ M A N I F E S T _ V A L U E }
$ { _ J A V A _ R E S O U R C E _ F I L E S _ R E L A T I V E } @ j a v a _ c l a s s _ f i l e l i s t
C O M M A N D $ { C M A K E _ C O M M A N D }
- D _ J A V A _ T A R G E T _ D I R = $ { _ a d d _ j a r _ O U T P U T _ D I R }
- D _ J A V A _ T A R G E T _ O U T P U T _ N A M E = $ { _ J A V A _ T A R G E T _ O U T P U T _ N A M E }
- D _ J A V A _ T A R G E T _ O U T P U T _ L I N K = $ { _ J A V A _ T A R G E T _ O U T P U T _ L I N K }
- P $ { _ J A V A _ S Y M L I N K _ S C R I P T }
C O M M A N D $ { C M A K E _ C O M M A N D }
- D _ J A V A _ T A R G E T _ D I R = $ { _ a d d _ j a r _ O U T P U T _ D I R }
- D _ J A V A _ T A R G E T _ O U T P U T _ N A M E = $ { _ J A V A _ J A R _ O U T P U T _ P A T H }
- D _ J A V A _ T A R G E T _ O U T P U T _ L I N K = $ { _ J A V A _ T A R G E T _ O U T P U T _ L I N K }
- P $ { _ J A V A _ S Y M L I N K _ S C R I P T }
D E P E N D S $ { _ J A V A _ R E S O U R C E _ F I L E S } $ { _ J A V A _ D E P E N D S } $ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H } / j a v a _ c l a s s _ f i l e l i s t
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H }
C O M M E N T " C r e a t i n g J a v a a r c h i v e $ { _ J A V A _ T A R G E T _ O U T P U T _ N A M E } "
V E R B A T I M
)
else ( )
add_custom_command (
O U T P U T $ { _ J A V A _ J A R _ O U T P U T _ P A T H }
C O M M A N D $ { J a v a _ J A R _ E X E C U T A B L E }
- c f $ { _ E N T R Y _ P O I N T _ O P T I O N } $ { _ M A N I F E S T _ O P T I O N } $ { _ J A V A _ J A R _ O U T P U T _ P A T H } $ { _ E N T R Y _ P O I N T _ V A L U E } $ { _ M A N I F E S T _ V A L U E }
$ { _ J A V A _ R E S O U R C E _ F I L E S _ R E L A T I V E } @ j a v a _ c l a s s _ f i l e l i s t
C O M M A N D $ { C M A K E _ C O M M A N D }
- D _ J A V A _ T A R G E T _ D I R = $ { _ a d d _ j a r _ O U T P U T _ D I R }
- D _ J A V A _ T A R G E T _ O U T P U T _ N A M E = $ { _ J A V A _ T A R G E T _ O U T P U T _ N A M E }
- D _ J A V A _ T A R G E T _ O U T P U T _ L I N K = $ { _ J A V A _ T A R G E T _ O U T P U T _ L I N K }
- P $ { _ J A V A _ S Y M L I N K _ S C R I P T }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H }
D E P E N D S $ { _ J A V A _ R E S O U R C E _ F I L E S } $ { _ J A V A _ D E P E N D S } $ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H } / j a v a _ c l a s s _ f i l e l i s t
C O M M E N T " C r e a t i n g J a v a a r c h i v e $ { _ J A V A _ T A R G E T _ O U T P U T _ N A M E } "
V E R B A T I M
)
endif ( )
# Add the target and make sure we have the latest resource files.
add_custom_target ( ${ _TARGET_NAME } ALL DEPENDS ${ _JAVA_JAR_OUTPUT_PATH } )
set_property (
T A R G E T
$ { _ T A R G E T _ N A M E }
P R O P E R T Y
I N S T A L L _ F I L E S
$ { _ J A V A _ J A R _ O U T P U T _ P A T H }
)
if ( _JAVA_TARGET_OUTPUT_LINK )
set_property (
T A R G E T
$ { _ T A R G E T _ N A M E }
P R O P E R T Y
I N S T A L L _ F I L E S
$ { _ J A V A _ J A R _ O U T P U T _ P A T H }
$ { _ a d d _ j a r _ O U T P U T _ D I R } / $ { _ J A V A _ T A R G E T _ O U T P U T _ L I N K }
)
if ( CMAKE_JNI_TARGET )
set_property (
T A R G E T
$ { _ T A R G E T _ N A M E }
P R O P E R T Y
J N I _ S Y M L I N K
$ { _ a d d _ j a r _ O U T P U T _ D I R } / $ { _ J A V A _ T A R G E T _ O U T P U T _ L I N K }
)
endif ( )
endif ( )
set_property (
T A R G E T
$ { _ T A R G E T _ N A M E }
P R O P E R T Y
J A R _ F I L E
$ { _ J A V A _ J A R _ O U T P U T _ P A T H }
)
set_property (
T A R G E T
$ { _ T A R G E T _ N A M E }
P R O P E R T Y
C L A S S D I R
$ { C M A K E _ J A V A _ C L A S S _ O U T P U T _ P A T H }
)
if ( _GENERATE_NATIVE_HEADERS )
# create an INTERFACE library encapsulating include directory for generated headers
add_library ( ${ _GENERATE_NATIVE_HEADERS_TARGET } INTERFACE )
target_include_directories ( ${ _GENERATE_NATIVE_HEADERS_TARGET } INTERFACE
" $ { _ G E N E R A T E _ N A T I V E _ H E A D E R S _ O U T P U T _ D E S C } "
$ { J N I _ I N C L U D E _ D I R S } )
set_property ( TARGET ${ _GENERATE_NATIVE_HEADERS_TARGET } PROPERTY NATIVE_HEADERS_DIRECTORY "${_GENERATE_NATIVE_HEADERS_OUTPUT_DIR}" )
# this INTERFACE library depends on jar generation
add_dependencies ( ${ _GENERATE_NATIVE_HEADERS_TARGET } ${ _TARGET_NAME } )
set_property ( DIRECTORY APPEND PROPERTY ADDITIONAL_CLEAN_FILES
" $ { _ G E N E R A T E _ N A T I V E _ H E A D E R S _ O U T P U T _ D I R } " )
endif ( )
endfunction ( )
function ( INSTALL_JAR _TARGET_NAME )
if ( ARGC EQUAL 2 )
set ( _DESTINATION ${ ARGV1 } )
else ( )
cmake_parse_arguments ( _install_jar
" "
" D E S T I N A T I O N ; C O M P O N E N T "
" "
$ { A R G N } )
if ( _install_jar_DESTINATION )
set ( _DESTINATION ${ _install_jar_DESTINATION } )
else ( )
message ( SEND_ERROR "install_jar: ${_TARGET_NAME}: DESTINATION must be specified." )
endif ( )
if ( _install_jar_COMPONENT )
set ( _COMPONENT COMPONENT ${ _install_jar_COMPONENT } )
endif ( )
endif ( )
get_property ( __FILES
T A R G E T
$ { _ T A R G E T _ N A M E }
P R O P E R T Y
I N S T A L L _ F I L E S
)
set_property (
T A R G E T
$ { _ T A R G E T _ N A M E }
P R O P E R T Y
I N S T A L L _ D E S T I N A T I O N
$ { _ D E S T I N A T I O N }
)
if ( __FILES )
install (
F I L E S
$ { _ _ F I L E S }
D E S T I N A T I O N
$ { _ D E S T I N A T I O N }
$ { _ C O M P O N E N T }
)
else ( )
message ( SEND_ERROR "install_jar: The target ${_TARGET_NAME} is not known in this scope." )
endif ( )
endfunction ( )
function ( INSTALL_JNI_SYMLINK _TARGET_NAME )
if ( ARGC EQUAL 2 )
set ( _DESTINATION ${ ARGV1 } )
else ( )
cmake_parse_arguments ( _install_jni_symlink
" "
" D E S T I N A T I O N ; C O M P O N E N T "
" "
$ { A R G N } )
if ( _install_jni_symlink_DESTINATION )
set ( _DESTINATION ${ _install_jni_symlink_DESTINATION } )
else ( )
message ( SEND_ERROR "install_jni_symlink: ${_TARGET_NAME}: DESTINATION must be specified." )
endif ( )
if ( _install_jni_symlink_COMPONENT )
set ( _COMPONENT COMPONENT ${ _install_jni_symlink_COMPONENT } )
endif ( )
endif ( )
get_property ( __SYMLINK
T A R G E T
$ { _ T A R G E T _ N A M E }
P R O P E R T Y
J N I _ S Y M L I N K
)
if ( __SYMLINK )
install (
F I L E S
$ { _ _ S Y M L I N K }
D E S T I N A T I O N
$ { _ D E S T I N A T I O N }
$ { _ C O M P O N E N T }
)
else ( )
message ( SEND_ERROR "install_jni_symlink: The target ${_TARGET_NAME} is not known in this scope." )
endif ( )
endfunction ( )
function ( find_jar VARIABLE )
set ( _jar_names )
set ( _jar_files )
set ( _jar_versions )
set ( _jar_paths
/ u s r / s h a r e / j a v a /
/ u s r / l o c a l / s h a r e / j a v a /
$ { J a v a _ J A R _ P A T H S } )
set ( _jar_doc "NOTSET" )
set ( _state "name" )
foreach ( arg IN LISTS ARGN )
if ( _state STREQUAL "name" )
if ( arg STREQUAL "VERSIONS" )
set ( _state "versions" )
elseif ( arg STREQUAL "NAMES" )
set ( _state "names" )
elseif ( arg STREQUAL "PATHS" )
set ( _state "paths" )
elseif ( arg STREQUAL "DOC" )
set ( _state "doc" )
else ( )
set ( _jar_names ${ arg } )
if ( _jar_doc STREQUAL "NOTSET" )
set ( _jar_doc "Finding ${arg} jar" )
endif ( )
endif ( )
elseif ( _state STREQUAL "versions" )
if ( arg STREQUAL "NAMES" )
set ( _state "names" )
elseif ( arg STREQUAL "PATHS" )
set ( _state "paths" )
elseif ( arg STREQUAL "DOC" )
set ( _state "doc" )
else ( )
set ( _jar_versions ${ _jar_versions } ${ arg } )
endif ( )
elseif ( _state STREQUAL "names" )
if ( arg STREQUAL "VERSIONS" )
set ( _state "versions" )
elseif ( arg STREQUAL "PATHS" )
set ( _state "paths" )
elseif ( arg STREQUAL "DOC" )
set ( _state "doc" )
else ( )
set ( _jar_names ${ _jar_names } ${ arg } )
if ( _jar_doc STREQUAL "NOTSET" )
set ( _jar_doc "Finding ${arg} jar" )
endif ( )
endif ( )
elseif ( _state STREQUAL "paths" )
if ( arg STREQUAL "VERSIONS" )
set ( _state "versions" )
elseif ( arg STREQUAL "NAMES" )
set ( _state "names" )
elseif ( arg STREQUAL "DOC" )
set ( _state "doc" )
else ( )
set ( _jar_paths ${ _jar_paths } ${ arg } )
endif ( )
elseif ( _state STREQUAL "doc" )
if ( arg STREQUAL "VERSIONS" )
set ( _state "versions" )
elseif ( arg STREQUAL "NAMES" )
set ( _state "names" )
elseif ( arg STREQUAL "PATHS" )
set ( _state "paths" )
else ( )
set ( _jar_doc ${ arg } )
endif ( )
endif ( )
endforeach ( )
if ( NOT _jar_names )
message ( FATAL_ERROR "find_jar: No name to search for given" )
endif ( )
foreach ( jar_name IN LISTS _jar_names )
foreach ( version IN LISTS _jar_versions )
set ( _jar_files ${ _jar_files } ${ jar_name } - ${ version } .jar )
endforeach ( )
set ( _jar_files ${ _jar_files } ${ jar_name } .jar )
endforeach ( )
find_file ( ${ VARIABLE }
N A M E S $ { _ j a r _ f i l e s }
P A T H S $ { _ j a r _ p a t h s }
D O C $ { _ j a r _ d o c }
N O _ D E F A U L T _ P A T H )
endfunction ( )
function ( create_javadoc _target )
set ( _javadoc_packages )
set ( _javadoc_files )
set ( _javadoc_sourcepath )
set ( _javadoc_classpath )
set ( _javadoc_installpath "${CMAKE_INSTALL_PREFIX}/share/javadoc" )
set ( _javadoc_doctitle )
set ( _javadoc_windowtitle )
set ( _javadoc_author FALSE )
set ( _javadoc_version FALSE )
set ( _javadoc_use FALSE )
set ( _state "package" )
foreach ( arg IN LISTS ARGN )
if ( _state STREQUAL "package" )
if ( arg STREQUAL "PACKAGES" )
set ( _state "packages" )
elseif ( arg STREQUAL "FILES" )
set ( _state "files" )
elseif ( arg STREQUAL "SOURCEPATH" )
set ( _state "sourcepath" )
elseif ( arg STREQUAL "CLASSPATH" )
set ( _state "classpath" )
elseif ( arg STREQUAL "INSTALLPATH" )
set ( _state "installpath" )
elseif ( arg STREQUAL "DOCTITLE" )
set ( _state "doctitle" )
elseif ( arg STREQUAL "WINDOWTITLE" )
set ( _state "windowtitle" )
elseif ( arg STREQUAL "AUTHOR" )
set ( _state "author" )
elseif ( arg STREQUAL "USE" )
set ( _state "use" )
elseif ( arg STREQUAL "VERSION" )
set ( _state "version" )
else ( )
set ( _javadoc_packages ${ arg } )
set ( _state "packages" )
endif ( )
elseif ( _state STREQUAL "packages" )
if ( arg STREQUAL "FILES" )
set ( _state "files" )
elseif ( arg STREQUAL "SOURCEPATH" )
set ( _state "sourcepath" )
elseif ( arg STREQUAL "CLASSPATH" )
set ( _state "classpath" )
elseif ( arg STREQUAL "INSTALLPATH" )
set ( _state "installpath" )
elseif ( arg STREQUAL "DOCTITLE" )
set ( _state "doctitle" )
elseif ( arg STREQUAL "WINDOWTITLE" )
set ( _state "windowtitle" )
elseif ( arg STREQUAL "AUTHOR" )
set ( _state "author" )
elseif ( arg STREQUAL "USE" )
set ( _state "use" )
elseif ( arg STREQUAL "VERSION" )
set ( _state "version" )
else ( )
list ( APPEND _javadoc_packages ${ arg } )
endif ( )
elseif ( _state STREQUAL "files" )
if ( arg STREQUAL "PACKAGES" )
set ( _state "packages" )
elseif ( arg STREQUAL "SOURCEPATH" )
set ( _state "sourcepath" )
elseif ( arg STREQUAL "CLASSPATH" )
set ( _state "classpath" )
elseif ( arg STREQUAL "INSTALLPATH" )
set ( _state "installpath" )
elseif ( arg STREQUAL "DOCTITLE" )
set ( _state "doctitle" )
elseif ( arg STREQUAL "WINDOWTITLE" )
set ( _state "windowtitle" )
elseif ( arg STREQUAL "AUTHOR" )
set ( _state "author" )
elseif ( arg STREQUAL "USE" )
set ( _state "use" )
elseif ( arg STREQUAL "VERSION" )
set ( _state "version" )
else ( )
list ( APPEND _javadoc_files ${ arg } )
endif ( )
elseif ( _state STREQUAL "sourcepath" )
if ( arg STREQUAL "PACKAGES" )
set ( _state "packages" )
elseif ( arg STREQUAL "FILES" )
set ( _state "files" )
elseif ( arg STREQUAL "CLASSPATH" )
set ( _state "classpath" )
elseif ( arg STREQUAL "INSTALLPATH" )
set ( _state "installpath" )
elseif ( arg STREQUAL "DOCTITLE" )
set ( _state "doctitle" )
elseif ( arg STREQUAL "WINDOWTITLE" )
set ( _state "windowtitle" )
elseif ( arg STREQUAL "AUTHOR" )
set ( _state "author" )
elseif ( arg STREQUAL "USE" )
set ( _state "use" )
elseif ( arg STREQUAL "VERSION" )
set ( _state "version" )
else ( )
list ( APPEND _javadoc_sourcepath ${ arg } )
endif ( )
elseif ( _state STREQUAL "classpath" )
if ( arg STREQUAL "PACKAGES" )
set ( _state "packages" )
elseif ( arg STREQUAL "FILES" )
set ( _state "files" )
elseif ( arg STREQUAL "SOURCEPATH" )
set ( _state "sourcepath" )
elseif ( arg STREQUAL "INSTALLPATH" )
set ( _state "installpath" )
elseif ( arg STREQUAL "DOCTITLE" )
set ( _state "doctitle" )
elseif ( arg STREQUAL "WINDOWTITLE" )
set ( _state "windowtitle" )
elseif ( arg STREQUAL "AUTHOR" )
set ( _state "author" )
elseif ( arg STREQUAL "USE" )
set ( _state "use" )
elseif ( arg STREQUAL "VERSION" )
set ( _state "version" )
else ( )
list ( APPEND _javadoc_classpath ${ arg } )
endif ( )
elseif ( _state STREQUAL "installpath" )
if ( arg STREQUAL "PACKAGES" )
set ( _state "packages" )
elseif ( arg STREQUAL "FILES" )
set ( _state "files" )
elseif ( arg STREQUAL "SOURCEPATH" )
set ( _state "sourcepath" )
elseif ( arg STREQUAL "DOCTITLE" )
set ( _state "doctitle" )
elseif ( arg STREQUAL "WINDOWTITLE" )
set ( _state "windowtitle" )
elseif ( arg STREQUAL "AUTHOR" )
set ( _state "author" )
elseif ( arg STREQUAL "USE" )
set ( _state "use" )
elseif ( arg STREQUAL "VERSION" )
set ( _state "version" )
else ( )
set ( _javadoc_installpath ${ arg } )
endif ( )
elseif ( _state STREQUAL "doctitle" )
if ( ${ arg } STREQUAL "PACKAGES" )
set ( _state "packages" )
elseif ( arg STREQUAL "FILES" )
set ( _state "files" )
elseif ( arg STREQUAL "SOURCEPATH" )
set ( _state "sourcepath" )
elseif ( arg STREQUAL "INSTALLPATH" )
set ( _state "installpath" )
elseif ( arg STREQUAL "CLASSPATH" )
set ( _state "classpath" )
elseif ( arg STREQUAL "WINDOWTITLE" )
set ( _state "windowtitle" )
elseif ( arg STREQUAL "AUTHOR" )
set ( _state "author" )
elseif ( arg STREQUAL "USE" )
set ( _state "use" )
elseif ( arg STREQUAL "VERSION" )
set ( _state "version" )
else ( )
set ( _javadoc_doctitle ${ arg } )
endif ( )
elseif ( _state STREQUAL "windowtitle" )
if ( ${ arg } STREQUAL "PACKAGES" )
set ( _state "packages" )
elseif ( arg STREQUAL "FILES" )
set ( _state "files" )
elseif ( arg STREQUAL "SOURCEPATH" )
set ( _state "sourcepath" )
elseif ( arg STREQUAL "CLASSPATH" )
set ( _state "classpath" )
elseif ( arg STREQUAL "INSTALLPATH" )
set ( _state "installpath" )
elseif ( arg STREQUAL "DOCTITLE" )
set ( _state "doctitle" )
elseif ( arg STREQUAL "AUTHOR" )
set ( _state "author" )
elseif ( arg STREQUAL "USE" )
set ( _state "use" )
elseif ( arg STREQUAL "VERSION" )
set ( _state "version" )
else ( )
set ( _javadoc_windowtitle ${ arg } )
endif ( )
elseif ( _state STREQUAL "author" )
if ( arg STREQUAL "PACKAGES" )
set ( _state "packages" )
elseif ( arg STREQUAL "FILES" )
set ( _state "files" )
elseif ( arg STREQUAL "SOURCEPATH" )
set ( _state "sourcepath" )
elseif ( arg STREQUAL "CLASSPATH" )
set ( _state "classpath" )
elseif ( arg STREQUAL "INSTALLPATH" )
set ( _state "installpath" )
elseif ( arg STREQUAL "DOCTITLE" )
set ( _state "doctitle" )
elseif ( arg STREQUAL "WINDOWTITLE" )
set ( _state "windowtitle" )
elseif ( arg STREQUAL "AUTHOR" )
set ( _state "author" )
elseif ( arg STREQUAL "USE" )
set ( _state "use" )
elseif ( arg STREQUAL "VERSION" )
set ( _state "version" )
else ( )
set ( _javadoc_author ${ arg } )
endif ( )
elseif ( _state STREQUAL "use" )
if ( arg STREQUAL "PACKAGES" )
set ( _state "packages" )
elseif ( arg STREQUAL "FILES" )
set ( _state "files" )
elseif ( arg STREQUAL "SOURCEPATH" )
set ( _state "sourcepath" )
elseif ( arg STREQUAL "CLASSPATH" )
set ( _state "classpath" )
elseif ( arg STREQUAL "INSTALLPATH" )
set ( _state "installpath" )
elseif ( arg STREQUAL "DOCTITLE" )
set ( _state "doctitle" )
elseif ( arg STREQUAL "WINDOWTITLE" )
set ( _state "windowtitle" )
elseif ( arg STREQUAL "AUTHOR" )
set ( _state "author" )
elseif ( arg STREQUAL "USE" )
set ( _state "use" )
elseif ( arg STREQUAL "VERSION" )
set ( _state "version" )
else ( )
set ( _javadoc_use ${ arg } )
endif ( )
elseif ( _state STREQUAL "version" )
if ( arg STREQUAL "PACKAGES" )
set ( _state "packages" )
elseif ( arg STREQUAL "FILES" )
set ( _state "files" )
elseif ( arg STREQUAL "SOURCEPATH" )
set ( _state "sourcepath" )
elseif ( arg STREQUAL "CLASSPATH" )
set ( _state "classpath" )
elseif ( arg STREQUAL "INSTALLPATH" )
set ( _state "installpath" )
elseif ( arg STREQUAL "DOCTITLE" )
set ( _state "doctitle" )
elseif ( arg STREQUAL "WINDOWTITLE" )
set ( _state "windowtitle" )
elseif ( arg STREQUAL "AUTHOR" )
set ( _state "author" )
elseif ( arg STREQUAL "USE" )
set ( _state "use" )
elseif ( arg STREQUAL "VERSION" )
set ( _state "version" )
else ( )
set ( _javadoc_version ${ arg } )
endif ( )
endif ( )
endforeach ( )
set ( _javadoc_builddir ${ CMAKE_CURRENT_BINARY_DIR } /javadoc/ ${ _target } )
set ( _javadoc_options -d ${ _javadoc_builddir } )
if ( _javadoc_sourcepath )
list ( JOIN _javadoc_sourcepath "${_UseJava_PATH_SEP}" _javadoc_sourcepath )
list ( APPEND _javadoc_options -sourcepath "\" ${ _javadoc_sourcepath } \"")
endif ( )
if ( _javadoc_classpath )
list ( JOIN _javadoc_classpath "${_UseJava_PATH_SEP}" _javadoc_classpath )
list ( APPEND _javadoc_options -classpath "\" ${ _javadoc_classpath } \"")
endif ( )
if ( _javadoc_doctitle )
list ( APPEND _javadoc_options -doctitle ' ${ _javadoc_doctitle } ' )
endif ( )
if ( _javadoc_windowtitle )
list ( APPEND _javadoc_options -windowtitle ' ${ _javadoc_windowtitle } ' )
endif ( )
if ( _javadoc_author )
list ( APPEND _javadoc_options -author )
endif ( )
if ( _javadoc_use )
list ( APPEND _javadoc_options -use )
endif ( )
if ( _javadoc_version )
list ( APPEND _javadoc_options -version )
endif ( )
add_custom_target ( ${ _target } _javadoc ALL
C O M M A N D $ { J a v a _ J A V A D O C _ E X E C U T A B L E }
$ { _ j a v a d o c _ o p t i o n s }
$ { _ j a v a d o c _ f i l e s }
$ { _ j a v a d o c _ p a c k a g e s }
W O R K I N G _ D I R E C T O R Y $ { C M A K E _ C U R R E N T _ S O U R C E _ D I R }
)
install (
D I R E C T O R Y $ { _ j a v a d o c _ b u i l d d i r }
D E S T I N A T I O N $ { _ j a v a d o c _ i n s t a l l p a t h }
)
endfunction ( )
function ( create_javah )
if ( Java_VERSION VERSION_GREATER_EQUAL 10 )
message ( FATAL_ERROR "create_javah: not supported with this Java version. Use add_jar(GENERATE_NATIVE_HEADERS) instead." )
elseif ( Java_VERSION VERSION_GREATER_EQUAL 1.8 )
message ( DEPRECATION "create_javah: this command will no longer be supported starting with version 10 of JDK. Update your project by using command add_jar(GENERATE_NATIVE_HEADERS) instead." )
endif ( )
cmake_parse_arguments ( _create_javah
" "
" T A R G E T ; G E N E R A T E D _ F I L E S ; O U T P U T _ N A M E ; O U T P U T _ D I R "
" C L A S S E S ; C L A S S P A T H ; D E P E N D S "
$ { A R G N } )
# check parameters
if ( NOT _create_javah_TARGET AND NOT _create_javah_GENERATED_FILES )
message ( FATAL_ERROR "create_javah: TARGET or GENERATED_FILES must be specified." )
endif ( )
if ( _create_javah_OUTPUT_NAME AND _create_javah_OUTPUT_DIR )
message ( FATAL_ERROR "create_javah: OUTPUT_NAME and OUTPUT_DIR are mutually exclusive." )
endif ( )
if ( NOT _create_javah_CLASSES )
message ( FATAL_ERROR "create_javah: CLASSES is a required parameter." )
endif ( )
set ( _output_files )
# handle javah options
set ( _javah_options )
if ( _create_javah_CLASSPATH )
# CLASSPATH can specify directories, jar files or targets created with add_jar command
set ( _classpath )
foreach ( _path IN LISTS _create_javah_CLASSPATH )
if ( TARGET ${ _path } )
get_target_property ( _jar_path ${ _path } JAR_FILE )
if ( _jar_path )
list ( APPEND _classpath "${_jar_path}" )
list ( APPEND _create_javah_DEPENDS "${_path}" )
else ( )
message ( SEND_ERROR "create_javah: CLASSPATH target ${_path} is not a jar." )
endif ( )
elseif ( EXISTS "${_path}" )
list ( APPEND _classpath "${_path}" )
if ( NOT IS_DIRECTORY "${_path}" )
list ( APPEND _create_javah_DEPENDS "${_path}" )
endif ( )
else ( )
message ( SEND_ERROR "create_javah: CLASSPATH entry ${_path} does not exist." )
endif ( )
endforeach ( )
string ( REPLACE ";" "${_UseJava_PATH_SEP}" _classpath "${_classpath}" )
list ( APPEND _javah_options -classpath "${_classpath}" )
endif ( )
if ( _create_javah_OUTPUT_DIR )
list ( APPEND _javah_options -d "${_create_javah_OUTPUT_DIR}" )
endif ( )
if ( _create_javah_OUTPUT_NAME )
list ( APPEND _javah_options -o "${_create_javah_OUTPUT_NAME}" )
set ( _output_files "${_create_javah_OUTPUT_NAME}" )
get_filename_component ( _create_javah_OUTPUT_DIR "${_create_javah_OUTPUT_NAME}" DIRECTORY )
get_filename_component ( _create_javah_OUTPUT_DIR "${_create_javah_OUTPUT_DIR}" ABSOLUTE )
endif ( )
if ( NOT _create_javah_OUTPUT_DIR )
set ( _create_javah_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}" )
endif ( )
if ( NOT _create_javah_OUTPUT_NAME )
# compute output names
foreach ( _class IN LISTS _create_javah_CLASSES )
string ( REPLACE "." "_" _c_header "${_class}" )
set ( _c_header "${_create_javah_OUTPUT_DIR}/${_c_header}.h" )
list ( APPEND _output_files "${_c_header}" )
endforeach ( )
endif ( )
# finalize custom command arguments
if ( _create_javah_DEPENDS )
list ( INSERT _create_javah_DEPENDS 0 DEPENDS )
endif ( )
add_custom_command ( OUTPUT ${ _output_files }
C O M M A N D " $ { J a v a _ J A V A H _ E X E C U T A B L E } " $ { _ j a v a h _ o p t i o n s } - j n i $ { _ c r e a t e _ j a v a h _ C L A S S E S }
$ { _ c r e a t e _ j a v a h _ D E P E N D S }
W O R K I N G _ D I R E C T O R Y $ { _ c r e a t e _ j a v a h _ O U T P U T _ D I R }
C O M M E N T " B u i l d i n g C h e a d e r f i l e s f r o m c l a s s e s . . . " )
if ( _create_javah_TARGET )
add_custom_target ( ${ _create_javah_TARGET } ALL DEPENDS ${ _output_files } )
endif ( )
if ( _create_javah_GENERATED_FILES )
set ( ${ _create_javah_GENERATED_FILES } ${ _output_files } PARENT_SCOPE )
endif ( )
endfunction ( )
function ( export_jars )
# Parse and validate arguments
cmake_parse_arguments ( _export_jars
" "
" F I L E ; N A M E S P A C E "
" T A R G E T S "
$ { A R G N }
)
if ( NOT _export_jars_FILE )
message ( SEND_ERROR "export_jars: FILE must be specified." )
endif ( )
if ( NOT _export_jars_TARGETS )
message ( SEND_ERROR "export_jars: TARGETS must be specified." )
endif ( )
set ( _jar_NAMESPACE "${_export_jars_NAMESPACE}" )
# Set content of generated exports file
string ( REPLACE ";" " " __targets__ "${_export_jars_TARGETS}" )
set ( __targetdefs__ "" )
foreach ( _target IN LISTS _export_jars_TARGETS )
get_target_property ( _jarpath ${ _target } JAR_FILE )
get_filename_component ( _jarpath ${ _jarpath } PATH )
__java_export_jar ( __targetdefs__ ${ _target } "${_jarpath}" )
endforeach ( )
# Generate exports file
configure_file (
$ { _ J A V A _ E X P O R T _ T A R G E T S _ S C R I P T }
$ { _ e x p o r t _ j a r s _ F I L E }
@ O N L Y
)
endfunction ( )
function ( install_jar_exports )
# Parse and validate arguments
cmake_parse_arguments ( _install_jar_exports
" "
" F I L E ; D E S T I N A T I O N ; C O M P O N E N T ; N A M E S P A C E "
" T A R G E T S "
$ { A R G N }
)
if ( NOT _install_jar_exports_FILE )
message ( SEND_ERROR "install_jar_exports: FILE must be specified." )
endif ( )
if ( NOT _install_jar_exports_DESTINATION )
message ( SEND_ERROR "install_jar_exports: DESTINATION must be specified." )
endif ( )
if ( NOT _install_jar_exports_TARGETS )
message ( SEND_ERROR "install_jar_exports: TARGETS must be specified." )
endif ( )
set ( _jar_NAMESPACE "${_install_jar_exports_NAMESPACE}" )
if ( _install_jar_exports_COMPONENT )
set ( _COMPONENT COMPONENT ${ _install_jar_exports_COMPONENT } )
endif ( )
# Determine relative path from installed export file to install prefix
if ( IS_ABSOLUTE "${_install_jar_exports_DESTINATION}" )
file ( RELATIVE_PATH _relpath
$ { _ i n s t a l l _ j a r _ e x p o r t s _ D E S T I N A T I O N }
$ { C M A K E _ I N S T A L L _ P R E F I X }
)
else ( )
file ( RELATIVE_PATH _relpath
$ { C M A K E _ I N S T A L L _ P R E F I X } / $ { _ i n s t a l l _ j a r _ e x p o r t s _ D E S T I N A T I O N }
$ { C M A K E _ I N S T A L L _ P R E F I X }
)
endif ( )
# Set up unique location for generated exports file
string ( SHA256 _hash "${_install_jar_exports_DESTINATION}" )
set ( _tmpdir ${ CMAKE_CURRENT_BINARY_DIR } /CMakeFiles/JavaExports/ ${ _hash } )
# Set content of generated exports file
string ( REPLACE ";" " " __targets__ "${_install_jar_exports_TARGETS}" )
set ( __targetdefs__ "set(_prefix \${CMAKE_CURRENT_LIST_DIR}/${_relpath})\n\n" )
foreach ( _target IN LISTS _install_jar_exports_TARGETS )
get_target_property ( _dir ${ _target } INSTALL_DESTINATION )
__java_export_jar ( __targetdefs__ ${ _target } "\${_prefix}/${_dir}" )
endforeach ( )
__java_lcat ( __targetdefs__ "\nunset(_prefix)" )
# Generate and install exports file
configure_file (
$ { _ J A V A _ E X P O R T _ T A R G E T S _ S C R I P T }
$ { _ t m p d i r } / $ { _ i n s t a l l _ j a r _ e x p o r t s _ F I L E }
@ O N L Y
)
install ( FILES ${ _tmpdir } / ${ _install_jar_exports_FILE }
D E S T I N A T I O N $ { _ i n s t a l l _ j a r _ e x p o r t s _ D E S T I N A T I O N }
$ { _ C O M P O N E N T } )
endfunction ( )