UseJava.cmake 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443
  1. #.rst:
  2. # UseJava
  3. # -------
  4. #
  5. # Use Module for Java
  6. #
  7. # This file provides functions for Java. It is assumed that
  8. # FindJava.cmake has already been loaded. See FindJava.cmake for
  9. # information on how to load Java into your CMake project.
  10. #
  11. # ::
  12. #
  13. # add_jar(target_name
  14. # [SOURCES] source1 [source2 ...] [resource1 ...]
  15. # [INCLUDE_JARS jar1 [jar2 ...]]
  16. # [ENTRY_POINT entry]
  17. # [VERSION version]
  18. # [OUTPUT_NAME name]
  19. # [OUTPUT_DIR dir]
  20. # )
  21. #
  22. # This command creates a <target_name>.jar. It compiles the given
  23. # source files (source) and adds the given resource files (resource) to
  24. # the jar file. Source files can be java files or listing files
  25. # (prefixed by '@'). If only resource files are given then just a jar file
  26. # is created. The list of include jars are added to the classpath when
  27. # compiling the java sources and also to the dependencies of the target.
  28. # INCLUDE_JARS also accepts other target names created by add_jar. For
  29. # backwards compatibility, jar files listed as sources are ignored (as
  30. # they have been since the first version of this module).
  31. #
  32. # The default OUTPUT_DIR can also be changed by setting the variable
  33. # CMAKE_JAVA_TARGET_OUTPUT_DIR.
  34. #
  35. # Additional instructions:
  36. #
  37. # ::
  38. #
  39. # To add compile flags to the target you can set these flags with
  40. # the following variable:
  41. #
  42. #
  43. #
  44. # ::
  45. #
  46. # set(CMAKE_JAVA_COMPILE_FLAGS -nowarn)
  47. #
  48. #
  49. #
  50. # ::
  51. #
  52. # To add a path or a jar file to the class path you can do this
  53. # with the CMAKE_JAVA_INCLUDE_PATH variable.
  54. #
  55. #
  56. #
  57. # ::
  58. #
  59. # set(CMAKE_JAVA_INCLUDE_PATH /usr/share/java/shibboleet.jar)
  60. #
  61. #
  62. #
  63. # ::
  64. #
  65. # To use a different output name for the target you can set it with:
  66. #
  67. #
  68. #
  69. # ::
  70. #
  71. # add_jar(foobar foobar.java OUTPUT_NAME shibboleet.jar)
  72. #
  73. #
  74. #
  75. # ::
  76. #
  77. # To use a different output directory than CMAKE_CURRENT_BINARY_DIR
  78. # you can set it with:
  79. #
  80. #
  81. #
  82. # ::
  83. #
  84. # add_jar(foobar foobar.java OUTPUT_DIR ${PROJECT_BINARY_DIR}/bin)
  85. #
  86. #
  87. #
  88. # ::
  89. #
  90. # To define an entry point in your jar you can set it with the ENTRY_POINT
  91. # named argument:
  92. #
  93. #
  94. #
  95. # ::
  96. #
  97. # add_jar(example ENTRY_POINT com/examples/MyProject/Main)
  98. #
  99. #
  100. #
  101. # ::
  102. #
  103. # To define a custom manifest for the jar, you can set it with the manifest
  104. # named argument:
  105. #
  106. #
  107. #
  108. # ::
  109. #
  110. # add_jar(example MANIFEST /path/to/manifest)
  111. #
  112. #
  113. #
  114. # ::
  115. #
  116. # To add a VERSION to the target output name you can set it using
  117. # the VERSION named argument to add_jar. This will create a jar file with the
  118. # name shibboleet-1.0.0.jar and will create a symlink shibboleet.jar
  119. # pointing to the jar with the version information.
  120. #
  121. #
  122. #
  123. # ::
  124. #
  125. # add_jar(shibboleet shibbotleet.java VERSION 1.2.0)
  126. #
  127. #
  128. #
  129. # ::
  130. #
  131. # If the target is a JNI library, utilize the following commands to
  132. # create a JNI symbolic link:
  133. #
  134. #
  135. #
  136. # ::
  137. #
  138. # set(CMAKE_JNI_TARGET TRUE)
  139. # add_jar(shibboleet shibbotleet.java VERSION 1.2.0)
  140. # install_jar(shibboleet ${LIB_INSTALL_DIR}/shibboleet)
  141. # install_jni_symlink(shibboleet ${JAVA_LIB_INSTALL_DIR})
  142. #
  143. #
  144. #
  145. # ::
  146. #
  147. # If a single target needs to produce more than one jar from its
  148. # java source code, to prevent the accumulation of duplicate class
  149. # files in subsequent jars, set/reset CMAKE_JAR_CLASSES_PREFIX prior
  150. # to calling the add_jar() function:
  151. #
  152. #
  153. #
  154. # ::
  155. #
  156. # set(CMAKE_JAR_CLASSES_PREFIX com/redhat/foo)
  157. # add_jar(foo foo.java)
  158. #
  159. #
  160. #
  161. # ::
  162. #
  163. # set(CMAKE_JAR_CLASSES_PREFIX com/redhat/bar)
  164. # add_jar(bar bar.java)
  165. #
  166. #
  167. #
  168. # Target Properties:
  169. #
  170. # ::
  171. #
  172. # The add_jar() function sets some target properties. You can get these
  173. # properties with the
  174. # get_property(TARGET <target_name> PROPERTY <propery_name>)
  175. # command.
  176. #
  177. #
  178. #
  179. # ::
  180. #
  181. # INSTALL_FILES The files which should be installed. This is used by
  182. # install_jar().
  183. # JNI_SYMLINK The JNI symlink which should be installed.
  184. # This is used by install_jni_symlink().
  185. # JAR_FILE The location of the jar file so that you can include
  186. # it.
  187. # CLASSDIR The directory where the class files can be found. For
  188. # example to use them with javah.
  189. #
  190. # ::
  191. #
  192. # find_jar(<VAR>
  193. # name | NAMES name1 [name2 ...]
  194. # [PATHS path1 [path2 ... ENV var]]
  195. # [VERSIONS version1 [version2]]
  196. # [DOC "cache documentation string"]
  197. # )
  198. #
  199. # This command is used to find a full path to the named jar. A cache
  200. # entry named by <VAR> is created to stor the result of this command.
  201. # If the full path to a jar is found the result is stored in the
  202. # variable and the search will not repeated unless the variable is
  203. # cleared. If nothing is found, the result will be <VAR>-NOTFOUND, and
  204. # the search will be attempted again next time find_jar is invoked with
  205. # the same variable. The name of the full path to a file that is
  206. # searched for is specified by the names listed after NAMES argument.
  207. # Additional search locations can be specified after the PATHS argument.
  208. # If you require special a version of a jar file you can specify it with
  209. # the VERSIONS argument. The argument after DOC will be used for the
  210. # documentation string in the cache.
  211. #
  212. # ::
  213. #
  214. # install_jar(target_name destination)
  215. # install_jar(target_name DESTINATION destination [COMPONENT component])
  216. #
  217. # This command installs the TARGET_NAME files to the given DESTINATION.
  218. # It should be called in the same scope as add_jar() or it will fail.
  219. #
  220. # Target Properties:
  221. #
  222. # ::
  223. #
  224. # The install_jar() function sets the INSTALL_DESTINATION target property
  225. # on jars so installed. This property holds the DESTINATION as described
  226. # above, and is used by install_jar_exports(). You can get this property
  227. # with the
  228. # get_property(TARGET <target_name> PROPERTY INSTALL_DESTINATION)
  229. # command.
  230. #
  231. #
  232. #
  233. # ::
  234. #
  235. # install_jni_symlink(target_name destination)
  236. # install_jni_symlink(target_name DESTINATION destination [COMPONENT component])
  237. #
  238. # This command installs the TARGET_NAME JNI symlinks to the given
  239. # DESTINATION. It should be called in the same scope as add_jar() or it
  240. # will fail.
  241. #
  242. # ::
  243. #
  244. # install_jar_exports(TARGETS jar1 [jar2 ...]
  245. # FILE export_filename
  246. # DESTINATION destination [COMPONENT component])
  247. #
  248. # This command installs a target export file export_filename for the named jar
  249. # targets to the given DESTINATION. Its function is similar to that of
  250. # install(EXPORTS).
  251. #
  252. # ::
  253. #
  254. # export_jars(TARGETS jar1 [jar2 ...]
  255. # FILE export_filename)
  256. #
  257. # This command writes a target export file export_filename for the named jar
  258. # targets. Its function is similar to that of export().
  259. #
  260. # ::
  261. #
  262. # create_javadoc(<VAR>
  263. # PACKAGES pkg1 [pkg2 ...]
  264. # [SOURCEPATH <sourcepath>]
  265. # [CLASSPATH <classpath>]
  266. # [INSTALLPATH <install path>]
  267. # [DOCTITLE "the documentation title"]
  268. # [WINDOWTITLE "the title of the document"]
  269. # [AUTHOR TRUE|FALSE]
  270. # [USE TRUE|FALSE]
  271. # [VERSION TRUE|FALSE]
  272. # )
  273. #
  274. # Create java documentation based on files or packages. For more
  275. # details please read the javadoc manpage.
  276. #
  277. # There are two main signatures for create_javadoc. The first signature
  278. # works with package names on a path with source files:
  279. #
  280. # ::
  281. #
  282. # Example:
  283. # create_javadoc(my_example_doc
  284. # PACKAGES com.exmaple.foo com.example.bar
  285. # SOURCEPATH "${CMAKE_CURRENT_SOURCE_DIR}"
  286. # CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH}
  287. # WINDOWTITLE "My example"
  288. # DOCTITLE "<h1>My example</h1>"
  289. # AUTHOR TRUE
  290. # USE TRUE
  291. # VERSION TRUE
  292. # )
  293. #
  294. #
  295. #
  296. # The second signature for create_javadoc works on a given list of
  297. # files.
  298. #
  299. # ::
  300. #
  301. # create_javadoc(<VAR>
  302. # FILES file1 [file2 ...]
  303. # [CLASSPATH <classpath>]
  304. # [INSTALLPATH <install path>]
  305. # [DOCTITLE "the documentation title"]
  306. # [WINDOWTITLE "the title of the document"]
  307. # [AUTHOR TRUE|FALSE]
  308. # [USE TRUE|FALSE]
  309. # [VERSION TRUE|FALSE]
  310. # )
  311. #
  312. #
  313. #
  314. # Example:
  315. #
  316. # ::
  317. #
  318. # create_javadoc(my_example_doc
  319. # FILES ${example_SRCS}
  320. # CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH}
  321. # WINDOWTITLE "My example"
  322. # DOCTITLE "<h1>My example</h1>"
  323. # AUTHOR TRUE
  324. # USE TRUE
  325. # VERSION TRUE
  326. # )
  327. #
  328. #
  329. #
  330. # Both signatures share most of the options. These options are the same
  331. # as what you can find in the javadoc manpage. Please look at the
  332. # manpage for CLASSPATH, DOCTITLE, WINDOWTITLE, AUTHOR, USE and VERSION.
  333. #
  334. # The documentation will be by default installed to
  335. #
  336. # ::
  337. #
  338. # ${CMAKE_INSTALL_PREFIX}/share/javadoc/<VAR>
  339. #
  340. #
  341. #
  342. # if you don't set the INSTALLPATH.
  343. #
  344. # ::
  345. #
  346. # create_javah(TARGET <target>
  347. # GENERATED_FILES <VAR>
  348. # CLASSES <class>...
  349. # [CLASSPATH <classpath>...]
  350. # [DEPENDS <depend>...]
  351. # [OUTPUT_NAME <path>|OUTPUT_DIR <path>]
  352. # )
  353. #
  354. # Create C header files from java classes. These files provide the connective glue
  355. # that allow your Java and C code to interact.
  356. #
  357. # There are two main signatures for create_javah. The first signature
  358. # returns generated files through variable specified by GENERATED_FILES option:
  359. #
  360. # ::
  361. #
  362. # Example:
  363. # Create_javah(GENERATED_FILES files_headers
  364. # CLASSES org.cmake.HelloWorld
  365. # CLASSPATH hello.jar
  366. # )
  367. #
  368. #
  369. #
  370. # The second signature for create_javah creates a target which encapsulates
  371. # header files generation.
  372. #
  373. # ::
  374. #
  375. # Example:
  376. # Create_javah(TARGET target_headers
  377. # CLASSES org.cmake.HelloWorld
  378. # CLASSPATH hello.jar
  379. # )
  380. #
  381. #
  382. #
  383. # Both signatures share same options.
  384. #
  385. # ``CLASSES <class>...``
  386. # Specifies Java classes used to generate headers.
  387. #
  388. # ``CLASSPATH <classpath>...``
  389. # Specifies various paths to look up classes. Here .class files, jar files or targets
  390. # created by command add_jar can be used.
  391. #
  392. # ``DEPENDS <depend>...``
  393. # Targets on which the javah target depends
  394. #
  395. # ``OUTPUT_NAME <path>``
  396. # Concatenates the resulting header files for all the classes listed by option CLASSES
  397. # into <path>. Same behavior as option '-o' of javah tool.
  398. #
  399. # ``OUTPUT_DIR <path>``
  400. # Sets the directory where the header files will be generated. Same behavior as option
  401. # '-d' of javah tool. If not specified, ${CMAKE_CURRENT_BINARY_DIR} is used as output directory.
  402. #=============================================================================
  403. # Copyright 2013 OpenGamma Ltd. <[email protected]>
  404. # Copyright 2010-2011 Andreas schneider <[email protected]>
  405. # Copyright 2010-2013 Kitware, Inc.
  406. #
  407. # Distributed under the OSI-approved BSD License (the "License");
  408. # see accompanying file Copyright.txt for details.
  409. #
  410. # This software is distributed WITHOUT ANY WARRANTY; without even the
  411. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  412. # See the License for more information.
  413. #=============================================================================
  414. # (To distribute this file outside of CMake, substitute the full
  415. # License text for the above reference.)
  416. include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
  417. function (__java_copy_file src dest comment)
  418. add_custom_command(
  419. OUTPUT ${dest}
  420. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  421. ARGS ${src}
  422. ${dest}
  423. DEPENDS ${src}
  424. COMMENT ${comment})
  425. endfunction ()
  426. function(__java_lcat VAR)
  427. foreach(_line ${ARGN})
  428. set(${VAR} "${${VAR}}${_line}\n")
  429. endforeach()
  430. set(${VAR} "${${VAR}}" PARENT_SCOPE)
  431. endfunction()
  432. function(__java_export_jar VAR TARGET PATH)
  433. get_target_property(_jarpath ${TARGET} JAR_FILE)
  434. get_filename_component(_jarname ${_jarpath} NAME)
  435. __java_lcat(${VAR}
  436. "# Create imported target ${TARGET}"
  437. "add_custom_target(${TARGET})"
  438. "set_target_properties(${TARGET} PROPERTIES"
  439. " JAR_FILE \"${PATH}/${_jarname}\")"
  440. ""
  441. )
  442. set(${VAR} "${${VAR}}" PARENT_SCOPE)
  443. endfunction()
  444. # define helper scripts
  445. set(_JAVA_EXPORT_TARGETS_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/javaTargets.cmake.in)
  446. set(_JAVA_CLASS_FILELIST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaClassFilelist.cmake)
  447. set(_JAVA_SYMLINK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaSymlinks.cmake)
  448. function(add_jar _TARGET_NAME)
  449. cmake_parse_arguments(_add_jar
  450. ""
  451. "VERSION;OUTPUT_DIR;OUTPUT_NAME;ENTRY_POINT;MANIFEST"
  452. "SOURCES;INCLUDE_JARS"
  453. ${ARGN}
  454. )
  455. # In CMake < 2.8.12, add_jar used variables which were set prior to calling
  456. # add_jar for customizing the behavior of add_jar. In order to be backwards
  457. # compatible, check if any of those variables are set, and use them to
  458. # initialize values of the named arguments. (Giving the corresponding named
  459. # argument will override the value set here.)
  460. #
  461. # New features should use named arguments only.
  462. if(NOT DEFINED _add_jar_VERSION AND DEFINED CMAKE_JAVA_TARGET_VERSION)
  463. set(_add_jar_VERSION "${CMAKE_JAVA_TARGET_VERSION}")
  464. endif()
  465. if(NOT DEFINED _add_jar_OUTPUT_DIR AND DEFINED CMAKE_JAVA_TARGET_OUTPUT_DIR)
  466. set(_add_jar_OUTPUT_DIR "${CMAKE_JAVA_TARGET_OUTPUT_DIR}")
  467. endif()
  468. if(NOT DEFINED _add_jar_OUTPUT_NAME AND DEFINED CMAKE_JAVA_TARGET_OUTPUT_NAME)
  469. set(_add_jar_OUTPUT_NAME "${CMAKE_JAVA_TARGET_OUTPUT_NAME}")
  470. # reset
  471. set(CMAKE_JAVA_TARGET_OUTPUT_NAME)
  472. endif()
  473. if(NOT DEFINED _add_jar_ENTRY_POINT AND DEFINED CMAKE_JAVA_JAR_ENTRY_POINT)
  474. set(_add_jar_ENTRY_POINT "${CMAKE_JAVA_JAR_ENTRY_POINT}")
  475. endif()
  476. set(_JAVA_SOURCE_FILES ${_add_jar_SOURCES} ${_add_jar_UNPARSED_ARGUMENTS})
  477. if (NOT DEFINED _add_jar_OUTPUT_DIR)
  478. set(_add_jar_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
  479. else()
  480. get_filename_component(_add_jar_OUTPUT_DIR ${_add_jar_OUTPUT_DIR} ABSOLUTE)
  481. endif()
  482. if (_add_jar_ENTRY_POINT)
  483. set(_ENTRY_POINT_OPTION e)
  484. set(_ENTRY_POINT_VALUE ${_add_jar_ENTRY_POINT})
  485. endif ()
  486. if (_add_jar_MANIFEST)
  487. set(_MANIFEST_OPTION m)
  488. get_filename_component (_MANIFEST_VALUE "${_add_jar_MANIFEST}" ABSOLUTE)
  489. endif ()
  490. if (LIBRARY_OUTPUT_PATH)
  491. set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH})
  492. else ()
  493. set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${_add_jar_OUTPUT_DIR})
  494. endif ()
  495. set(CMAKE_JAVA_INCLUDE_PATH
  496. ${CMAKE_JAVA_INCLUDE_PATH}
  497. ${CMAKE_CURRENT_SOURCE_DIR}
  498. ${CMAKE_JAVA_OBJECT_OUTPUT_PATH}
  499. ${CMAKE_JAVA_LIBRARY_OUTPUT_PATH}
  500. )
  501. if (CMAKE_HOST_WIN32 AND NOT CYGWIN AND CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
  502. set(CMAKE_JAVA_INCLUDE_FLAG_SEP ";")
  503. else ()
  504. set(CMAKE_JAVA_INCLUDE_FLAG_SEP ":")
  505. endif()
  506. foreach (JAVA_INCLUDE_DIR ${CMAKE_JAVA_INCLUDE_PATH})
  507. set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${JAVA_INCLUDE_DIR}")
  508. endforeach()
  509. set(CMAKE_JAVA_CLASS_OUTPUT_PATH "${_add_jar_OUTPUT_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir")
  510. set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}.jar")
  511. if (_add_jar_OUTPUT_NAME AND _add_jar_VERSION)
  512. set(_JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}-${_add_jar_VERSION}.jar")
  513. set(_JAVA_TARGET_OUTPUT_LINK "${_add_jar_OUTPUT_NAME}.jar")
  514. elseif (_add_jar_VERSION)
  515. set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}-${_add_jar_VERSION}.jar")
  516. set(_JAVA_TARGET_OUTPUT_LINK "${_TARGET_NAME}.jar")
  517. elseif (_add_jar_OUTPUT_NAME)
  518. set(_JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}.jar")
  519. endif ()
  520. set(_JAVA_CLASS_FILES)
  521. set(_JAVA_COMPILE_FILES)
  522. set(_JAVA_COMPILE_FILELISTS)
  523. set(_JAVA_DEPENDS)
  524. set(_JAVA_COMPILE_DEPENDS)
  525. set(_JAVA_RESOURCE_FILES)
  526. set(_JAVA_RESOURCE_FILES_RELATIVE)
  527. foreach(_JAVA_SOURCE_FILE ${_JAVA_SOURCE_FILES})
  528. get_filename_component(_JAVA_EXT ${_JAVA_SOURCE_FILE} EXT)
  529. get_filename_component(_JAVA_FILE ${_JAVA_SOURCE_FILE} NAME_WE)
  530. get_filename_component(_JAVA_PATH ${_JAVA_SOURCE_FILE} PATH)
  531. get_filename_component(_JAVA_FULL ${_JAVA_SOURCE_FILE} ABSOLUTE)
  532. if (_JAVA_SOURCE_FILE MATCHES "^@(.+)$")
  533. get_filename_component(_JAVA_FULL ${CMAKE_MATCH_1} ABSOLUTE)
  534. list(APPEND _JAVA_COMPILE_FILELISTS ${_JAVA_FULL})
  535. elseif (_JAVA_EXT MATCHES ".java")
  536. file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${_add_jar_OUTPUT_DIR} ${_JAVA_FULL})
  537. file(RELATIVE_PATH _JAVA_REL_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${_JAVA_FULL})
  538. string(LENGTH ${_JAVA_REL_BINARY_PATH} _BIN_LEN)
  539. string(LENGTH ${_JAVA_REL_SOURCE_PATH} _SRC_LEN)
  540. if (${_BIN_LEN} LESS ${_SRC_LEN})
  541. set(_JAVA_REL_PATH ${_JAVA_REL_BINARY_PATH})
  542. else ()
  543. set(_JAVA_REL_PATH ${_JAVA_REL_SOURCE_PATH})
  544. endif ()
  545. get_filename_component(_JAVA_REL_PATH ${_JAVA_REL_PATH} PATH)
  546. list(APPEND _JAVA_COMPILE_FILES ${_JAVA_SOURCE_FILE})
  547. set(_JAVA_CLASS_FILE "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_REL_PATH}/${_JAVA_FILE}.class")
  548. set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES} ${_JAVA_CLASS_FILE})
  549. elseif (_JAVA_EXT MATCHES ".jar"
  550. OR _JAVA_EXT MATCHES ".war"
  551. OR _JAVA_EXT MATCHES ".ear"
  552. OR _JAVA_EXT MATCHES ".sar")
  553. # Ignored for backward compatibility
  554. elseif (_JAVA_EXT STREQUAL "")
  555. list(APPEND CMAKE_JAVA_INCLUDE_PATH ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}} ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}_CLASSPATH})
  556. list(APPEND _JAVA_DEPENDS ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}})
  557. else ()
  558. __java_copy_file(${CMAKE_CURRENT_SOURCE_DIR}/${_JAVA_SOURCE_FILE}
  559. ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE}
  560. "Copying ${_JAVA_SOURCE_FILE} to the build directory")
  561. list(APPEND _JAVA_RESOURCE_FILES ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE})
  562. list(APPEND _JAVA_RESOURCE_FILES_RELATIVE ${_JAVA_SOURCE_FILE})
  563. endif ()
  564. endforeach()
  565. foreach(_JAVA_INCLUDE_JAR ${_add_jar_INCLUDE_JARS})
  566. if (TARGET ${_JAVA_INCLUDE_JAR})
  567. get_target_property(_JAVA_JAR_PATH ${_JAVA_INCLUDE_JAR} JAR_FILE)
  568. if (_JAVA_JAR_PATH)
  569. set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_JAR_PATH}")
  570. list(APPEND CMAKE_JAVA_INCLUDE_PATH ${_JAVA_JAR_PATH})
  571. list(APPEND _JAVA_DEPENDS ${_JAVA_INCLUDE_JAR})
  572. list(APPEND _JAVA_COMPILE_DEPENDS ${_JAVA_INCLUDE_JAR})
  573. else ()
  574. message(SEND_ERROR "add_jar: INCLUDE_JARS target ${_JAVA_INCLUDE_JAR} is not a jar")
  575. endif ()
  576. else ()
  577. set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_INCLUDE_JAR}")
  578. list(APPEND CMAKE_JAVA_INCLUDE_PATH "${_JAVA_INCLUDE_JAR}")
  579. list(APPEND _JAVA_DEPENDS "${_JAVA_INCLUDE_JAR}")
  580. list(APPEND _JAVA_COMPILE_DEPENDS "${_JAVA_INCLUDE_JAR}")
  581. endif ()
  582. endforeach()
  583. # create an empty java_class_filelist
  584. if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist)
  585. file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "")
  586. endif()
  587. if (_JAVA_COMPILE_FILES OR _JAVA_COMPILE_FILELISTS)
  588. set (_JAVA_SOURCES_FILELISTS)
  589. if (_JAVA_COMPILE_FILES)
  590. # Create the list of files to compile.
  591. set(_JAVA_SOURCES_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_sources)
  592. string(REPLACE ";" "\"\n\"" _JAVA_COMPILE_STRING "\"${_JAVA_COMPILE_FILES}\"")
  593. file(WRITE ${_JAVA_SOURCES_FILE} ${_JAVA_COMPILE_STRING})
  594. list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_SOURCES_FILE}")
  595. endif()
  596. if (_JAVA_COMPILE_FILELISTS)
  597. foreach (_JAVA_FILELIST IN LISTS _JAVA_COMPILE_FILELISTS)
  598. list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_FILELIST}")
  599. endforeach()
  600. endif()
  601. # Compile the java files and create a list of class files
  602. add_custom_command(
  603. # NOTE: this command generates an artificial dependency file
  604. OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
  605. COMMAND ${Java_JAVAC_EXECUTABLE}
  606. ${CMAKE_JAVA_COMPILE_FLAGS}
  607. -classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}"
  608. -d ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  609. ${_JAVA_SOURCES_FILELISTS}
  610. COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
  611. DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_FILELISTS} ${_JAVA_COMPILE_DEPENDS}
  612. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  613. COMMENT "Building Java objects for ${_TARGET_NAME}.jar"
  614. )
  615. add_custom_command(
  616. OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
  617. COMMAND ${CMAKE_COMMAND}
  618. -DCMAKE_JAVA_CLASS_OUTPUT_PATH=${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  619. -DCMAKE_JAR_CLASSES_PREFIX="${CMAKE_JAR_CLASSES_PREFIX}"
  620. -P ${_JAVA_CLASS_FILELIST_SCRIPT}
  621. DEPENDS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
  622. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  623. )
  624. endif ()
  625. # create the jar file
  626. set(_JAVA_JAR_OUTPUT_PATH
  627. ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_NAME})
  628. if (CMAKE_JNI_TARGET)
  629. add_custom_command(
  630. OUTPUT ${_JAVA_JAR_OUTPUT_PATH}
  631. COMMAND ${Java_JAR_EXECUTABLE}
  632. -cf${_ENTRY_POINT_OPTION}${_MANIFEST_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_MANIFEST_VALUE}
  633. ${_JAVA_RESOURCE_FILES_RELATIVE} @java_class_filelist
  634. COMMAND ${CMAKE_COMMAND}
  635. -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
  636. -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME}
  637. -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
  638. -P ${_JAVA_SYMLINK_SCRIPT}
  639. COMMAND ${CMAKE_COMMAND}
  640. -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
  641. -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_JAR_OUTPUT_PATH}
  642. -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
  643. -P ${_JAVA_SYMLINK_SCRIPT}
  644. DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
  645. WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  646. COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}"
  647. )
  648. else ()
  649. add_custom_command(
  650. OUTPUT ${_JAVA_JAR_OUTPUT_PATH}
  651. COMMAND ${Java_JAR_EXECUTABLE}
  652. -cf${_ENTRY_POINT_OPTION}${_MANIFEST_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_MANIFEST_VALUE}
  653. ${_JAVA_RESOURCE_FILES_RELATIVE} @java_class_filelist
  654. COMMAND ${CMAKE_COMMAND}
  655. -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
  656. -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME}
  657. -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
  658. -P ${_JAVA_SYMLINK_SCRIPT}
  659. WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  660. DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
  661. COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}"
  662. )
  663. endif ()
  664. # Add the target and make sure we have the latest resource files.
  665. add_custom_target(${_TARGET_NAME} ALL DEPENDS ${_JAVA_JAR_OUTPUT_PATH})
  666. set_property(
  667. TARGET
  668. ${_TARGET_NAME}
  669. PROPERTY
  670. INSTALL_FILES
  671. ${_JAVA_JAR_OUTPUT_PATH}
  672. )
  673. if (_JAVA_TARGET_OUTPUT_LINK)
  674. set_property(
  675. TARGET
  676. ${_TARGET_NAME}
  677. PROPERTY
  678. INSTALL_FILES
  679. ${_JAVA_JAR_OUTPUT_PATH}
  680. ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK}
  681. )
  682. if (CMAKE_JNI_TARGET)
  683. set_property(
  684. TARGET
  685. ${_TARGET_NAME}
  686. PROPERTY
  687. JNI_SYMLINK
  688. ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK}
  689. )
  690. endif ()
  691. endif ()
  692. set_property(
  693. TARGET
  694. ${_TARGET_NAME}
  695. PROPERTY
  696. JAR_FILE
  697. ${_JAVA_JAR_OUTPUT_PATH}
  698. )
  699. set_property(
  700. TARGET
  701. ${_TARGET_NAME}
  702. PROPERTY
  703. CLASSDIR
  704. ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  705. )
  706. endfunction()
  707. function(INSTALL_JAR _TARGET_NAME)
  708. if (ARGC EQUAL 2)
  709. set (_DESTINATION ${ARGV1})
  710. else()
  711. cmake_parse_arguments(_install_jar
  712. ""
  713. "DESTINATION;COMPONENT"
  714. ""
  715. ${ARGN})
  716. if (_install_jar_DESTINATION)
  717. set (_DESTINATION ${_install_jar_DESTINATION})
  718. else()
  719. message(SEND_ERROR "install_jar: ${_TARGET_NAME}: DESTINATION must be specified.")
  720. endif()
  721. if (_install_jar_COMPONENT)
  722. set (_COMPONENT COMPONENT ${_install_jar_COMPONENT})
  723. endif()
  724. endif()
  725. get_property(__FILES
  726. TARGET
  727. ${_TARGET_NAME}
  728. PROPERTY
  729. INSTALL_FILES
  730. )
  731. set_property(
  732. TARGET
  733. ${_TARGET_NAME}
  734. PROPERTY
  735. INSTALL_DESTINATION
  736. ${_DESTINATION}
  737. )
  738. if (__FILES)
  739. install(
  740. FILES
  741. ${__FILES}
  742. DESTINATION
  743. ${_DESTINATION}
  744. ${_COMPONENT}
  745. )
  746. else ()
  747. message(SEND_ERROR "install_jar: The target ${_TARGET_NAME} is not known in this scope.")
  748. endif ()
  749. endfunction()
  750. function(INSTALL_JNI_SYMLINK _TARGET_NAME)
  751. if (ARGC EQUAL 2)
  752. set (_DESTINATION ${ARGV1})
  753. else()
  754. cmake_parse_arguments(_install_jni_symlink
  755. ""
  756. "DESTINATION;COMPONENT"
  757. ""
  758. ${ARGN})
  759. if (_install_jni_symlink_DESTINATION)
  760. set (_DESTINATION ${_install_jni_symlink_DESTINATION})
  761. else()
  762. message(SEND_ERROR "install_jni_symlink: ${_TARGET_NAME}: DESTINATION must be specified.")
  763. endif()
  764. if (_install_jni_symlink_COMPONENT)
  765. set (_COMPONENT COMPONENT ${_install_jni_symlink_COMPONENT})
  766. endif()
  767. endif()
  768. get_property(__SYMLINK
  769. TARGET
  770. ${_TARGET_NAME}
  771. PROPERTY
  772. JNI_SYMLINK
  773. )
  774. if (__SYMLINK)
  775. install(
  776. FILES
  777. ${__SYMLINK}
  778. DESTINATION
  779. ${_DESTINATION}
  780. ${_COMPONENT}
  781. )
  782. else ()
  783. message(SEND_ERROR "install_jni_symlink: The target ${_TARGET_NAME} is not known in this scope.")
  784. endif ()
  785. endfunction()
  786. function (find_jar VARIABLE)
  787. set(_jar_names)
  788. set(_jar_files)
  789. set(_jar_versions)
  790. set(_jar_paths
  791. /usr/share/java/
  792. /usr/local/share/java/
  793. ${Java_JAR_PATHS})
  794. set(_jar_doc "NOTSET")
  795. set(_state "name")
  796. foreach (arg ${ARGN})
  797. if (${_state} STREQUAL "name")
  798. if (${arg} STREQUAL "VERSIONS")
  799. set(_state "versions")
  800. elseif (${arg} STREQUAL "NAMES")
  801. set(_state "names")
  802. elseif (${arg} STREQUAL "PATHS")
  803. set(_state "paths")
  804. elseif (${arg} STREQUAL "DOC")
  805. set(_state "doc")
  806. else ()
  807. set(_jar_names ${arg})
  808. if (_jar_doc STREQUAL "NOTSET")
  809. set(_jar_doc "Finding ${arg} jar")
  810. endif ()
  811. endif ()
  812. elseif (${_state} STREQUAL "versions")
  813. if (${arg} STREQUAL "NAMES")
  814. set(_state "names")
  815. elseif (${arg} STREQUAL "PATHS")
  816. set(_state "paths")
  817. elseif (${arg} STREQUAL "DOC")
  818. set(_state "doc")
  819. else ()
  820. set(_jar_versions ${_jar_versions} ${arg})
  821. endif ()
  822. elseif (${_state} STREQUAL "names")
  823. if (${arg} STREQUAL "VERSIONS")
  824. set(_state "versions")
  825. elseif (${arg} STREQUAL "PATHS")
  826. set(_state "paths")
  827. elseif (${arg} STREQUAL "DOC")
  828. set(_state "doc")
  829. else ()
  830. set(_jar_names ${_jar_names} ${arg})
  831. if (_jar_doc STREQUAL "NOTSET")
  832. set(_jar_doc "Finding ${arg} jar")
  833. endif ()
  834. endif ()
  835. elseif (${_state} STREQUAL "paths")
  836. if (${arg} STREQUAL "VERSIONS")
  837. set(_state "versions")
  838. elseif (${arg} STREQUAL "NAMES")
  839. set(_state "names")
  840. elseif (${arg} STREQUAL "DOC")
  841. set(_state "doc")
  842. else ()
  843. set(_jar_paths ${_jar_paths} ${arg})
  844. endif ()
  845. elseif (${_state} STREQUAL "doc")
  846. if (${arg} STREQUAL "VERSIONS")
  847. set(_state "versions")
  848. elseif (${arg} STREQUAL "NAMES")
  849. set(_state "names")
  850. elseif (${arg} STREQUAL "PATHS")
  851. set(_state "paths")
  852. else ()
  853. set(_jar_doc ${arg})
  854. endif ()
  855. endif ()
  856. endforeach ()
  857. if (NOT _jar_names)
  858. message(FATAL_ERROR "find_jar: No name to search for given")
  859. endif ()
  860. foreach (jar_name ${_jar_names})
  861. foreach (version ${_jar_versions})
  862. set(_jar_files ${_jar_files} ${jar_name}-${version}.jar)
  863. endforeach ()
  864. set(_jar_files ${_jar_files} ${jar_name}.jar)
  865. endforeach ()
  866. find_file(${VARIABLE}
  867. NAMES ${_jar_files}
  868. PATHS ${_jar_paths}
  869. DOC ${_jar_doc}
  870. NO_DEFAULT_PATH)
  871. endfunction ()
  872. function(create_javadoc _target)
  873. set(_javadoc_packages)
  874. set(_javadoc_files)
  875. set(_javadoc_sourcepath)
  876. set(_javadoc_classpath)
  877. set(_javadoc_installpath "${CMAKE_INSTALL_PREFIX}/share/javadoc")
  878. set(_javadoc_doctitle)
  879. set(_javadoc_windowtitle)
  880. set(_javadoc_author FALSE)
  881. set(_javadoc_version FALSE)
  882. set(_javadoc_use FALSE)
  883. set(_state "package")
  884. foreach (arg ${ARGN})
  885. if (${_state} STREQUAL "package")
  886. if (${arg} STREQUAL "PACKAGES")
  887. set(_state "packages")
  888. elseif (${arg} STREQUAL "FILES")
  889. set(_state "files")
  890. elseif (${arg} STREQUAL "SOURCEPATH")
  891. set(_state "sourcepath")
  892. elseif (${arg} STREQUAL "CLASSPATH")
  893. set(_state "classpath")
  894. elseif (${arg} STREQUAL "INSTALLPATH")
  895. set(_state "installpath")
  896. elseif (${arg} STREQUAL "DOCTITLE")
  897. set(_state "doctitle")
  898. elseif (${arg} STREQUAL "WINDOWTITLE")
  899. set(_state "windowtitle")
  900. elseif (${arg} STREQUAL "AUTHOR")
  901. set(_state "author")
  902. elseif (${arg} STREQUAL "USE")
  903. set(_state "use")
  904. elseif (${arg} STREQUAL "VERSION")
  905. set(_state "version")
  906. else ()
  907. set(_javadoc_packages ${arg})
  908. set(_state "packages")
  909. endif ()
  910. elseif (${_state} STREQUAL "packages")
  911. if (${arg} STREQUAL "FILES")
  912. set(_state "files")
  913. elseif (${arg} STREQUAL "SOURCEPATH")
  914. set(_state "sourcepath")
  915. elseif (${arg} STREQUAL "CLASSPATH")
  916. set(_state "classpath")
  917. elseif (${arg} STREQUAL "INSTALLPATH")
  918. set(_state "installpath")
  919. elseif (${arg} STREQUAL "DOCTITLE")
  920. set(_state "doctitle")
  921. elseif (${arg} STREQUAL "WINDOWTITLE")
  922. set(_state "windowtitle")
  923. elseif (${arg} STREQUAL "AUTHOR")
  924. set(_state "author")
  925. elseif (${arg} STREQUAL "USE")
  926. set(_state "use")
  927. elseif (${arg} STREQUAL "VERSION")
  928. set(_state "version")
  929. else ()
  930. list(APPEND _javadoc_packages ${arg})
  931. endif ()
  932. elseif (${_state} STREQUAL "files")
  933. if (${arg} STREQUAL "PACKAGES")
  934. set(_state "packages")
  935. elseif (${arg} STREQUAL "SOURCEPATH")
  936. set(_state "sourcepath")
  937. elseif (${arg} STREQUAL "CLASSPATH")
  938. set(_state "classpath")
  939. elseif (${arg} STREQUAL "INSTALLPATH")
  940. set(_state "installpath")
  941. elseif (${arg} STREQUAL "DOCTITLE")
  942. set(_state "doctitle")
  943. elseif (${arg} STREQUAL "WINDOWTITLE")
  944. set(_state "windowtitle")
  945. elseif (${arg} STREQUAL "AUTHOR")
  946. set(_state "author")
  947. elseif (${arg} STREQUAL "USE")
  948. set(_state "use")
  949. elseif (${arg} STREQUAL "VERSION")
  950. set(_state "version")
  951. else ()
  952. list(APPEND _javadoc_files ${arg})
  953. endif ()
  954. elseif (${_state} STREQUAL "sourcepath")
  955. if (${arg} STREQUAL "PACKAGES")
  956. set(_state "packages")
  957. elseif (${arg} STREQUAL "FILES")
  958. set(_state "files")
  959. elseif (${arg} STREQUAL "CLASSPATH")
  960. set(_state "classpath")
  961. elseif (${arg} STREQUAL "INSTALLPATH")
  962. set(_state "installpath")
  963. elseif (${arg} STREQUAL "DOCTITLE")
  964. set(_state "doctitle")
  965. elseif (${arg} STREQUAL "WINDOWTITLE")
  966. set(_state "windowtitle")
  967. elseif (${arg} STREQUAL "AUTHOR")
  968. set(_state "author")
  969. elseif (${arg} STREQUAL "USE")
  970. set(_state "use")
  971. elseif (${arg} STREQUAL "VERSION")
  972. set(_state "version")
  973. else ()
  974. list(APPEND _javadoc_sourcepath ${arg})
  975. endif ()
  976. elseif (${_state} STREQUAL "classpath")
  977. if (${arg} STREQUAL "PACKAGES")
  978. set(_state "packages")
  979. elseif (${arg} STREQUAL "FILES")
  980. set(_state "files")
  981. elseif (${arg} STREQUAL "SOURCEPATH")
  982. set(_state "sourcepath")
  983. elseif (${arg} STREQUAL "INSTALLPATH")
  984. set(_state "installpath")
  985. elseif (${arg} STREQUAL "DOCTITLE")
  986. set(_state "doctitle")
  987. elseif (${arg} STREQUAL "WINDOWTITLE")
  988. set(_state "windowtitle")
  989. elseif (${arg} STREQUAL "AUTHOR")
  990. set(_state "author")
  991. elseif (${arg} STREQUAL "USE")
  992. set(_state "use")
  993. elseif (${arg} STREQUAL "VERSION")
  994. set(_state "version")
  995. else ()
  996. list(APPEND _javadoc_classpath ${arg})
  997. endif ()
  998. elseif (${_state} STREQUAL "installpath")
  999. if (${arg} STREQUAL "PACKAGES")
  1000. set(_state "packages")
  1001. elseif (${arg} STREQUAL "FILES")
  1002. set(_state "files")
  1003. elseif (${arg} STREQUAL "SOURCEPATH")
  1004. set(_state "sourcepath")
  1005. elseif (${arg} STREQUAL "DOCTITLE")
  1006. set(_state "doctitle")
  1007. elseif (${arg} STREQUAL "WINDOWTITLE")
  1008. set(_state "windowtitle")
  1009. elseif (${arg} STREQUAL "AUTHOR")
  1010. set(_state "author")
  1011. elseif (${arg} STREQUAL "USE")
  1012. set(_state "use")
  1013. elseif (${arg} STREQUAL "VERSION")
  1014. set(_state "version")
  1015. else ()
  1016. set(_javadoc_installpath ${arg})
  1017. endif ()
  1018. elseif (${_state} STREQUAL "doctitle")
  1019. if (${arg} STREQUAL "PACKAGES")
  1020. set(_state "packages")
  1021. elseif (${arg} STREQUAL "FILES")
  1022. set(_state "files")
  1023. elseif (${arg} STREQUAL "SOURCEPATH")
  1024. set(_state "sourcepath")
  1025. elseif (${arg} STREQUAL "INSTALLPATH")
  1026. set(_state "installpath")
  1027. elseif (${arg} STREQUAL "CLASSPATH")
  1028. set(_state "classpath")
  1029. elseif (${arg} STREQUAL "WINDOWTITLE")
  1030. set(_state "windowtitle")
  1031. elseif (${arg} STREQUAL "AUTHOR")
  1032. set(_state "author")
  1033. elseif (${arg} STREQUAL "USE")
  1034. set(_state "use")
  1035. elseif (${arg} STREQUAL "VERSION")
  1036. set(_state "version")
  1037. else ()
  1038. set(_javadoc_doctitle ${arg})
  1039. endif ()
  1040. elseif (${_state} STREQUAL "windowtitle")
  1041. if (${arg} STREQUAL "PACKAGES")
  1042. set(_state "packages")
  1043. elseif (${arg} STREQUAL "FILES")
  1044. set(_state "files")
  1045. elseif (${arg} STREQUAL "SOURCEPATH")
  1046. set(_state "sourcepath")
  1047. elseif (${arg} STREQUAL "CLASSPATH")
  1048. set(_state "classpath")
  1049. elseif (${arg} STREQUAL "INSTALLPATH")
  1050. set(_state "installpath")
  1051. elseif (${arg} STREQUAL "DOCTITLE")
  1052. set(_state "doctitle")
  1053. elseif (${arg} STREQUAL "AUTHOR")
  1054. set(_state "author")
  1055. elseif (${arg} STREQUAL "USE")
  1056. set(_state "use")
  1057. elseif (${arg} STREQUAL "VERSION")
  1058. set(_state "version")
  1059. else ()
  1060. set(_javadoc_windowtitle ${arg})
  1061. endif ()
  1062. elseif (${_state} STREQUAL "author")
  1063. if (${arg} STREQUAL "PACKAGES")
  1064. set(_state "packages")
  1065. elseif (${arg} STREQUAL "FILES")
  1066. set(_state "files")
  1067. elseif (${arg} STREQUAL "SOURCEPATH")
  1068. set(_state "sourcepath")
  1069. elseif (${arg} STREQUAL "CLASSPATH")
  1070. set(_state "classpath")
  1071. elseif (${arg} STREQUAL "INSTALLPATH")
  1072. set(_state "installpath")
  1073. elseif (${arg} STREQUAL "DOCTITLE")
  1074. set(_state "doctitle")
  1075. elseif (${arg} STREQUAL "WINDOWTITLE")
  1076. set(_state "windowtitle")
  1077. elseif (${arg} STREQUAL "AUTHOR")
  1078. set(_state "author")
  1079. elseif (${arg} STREQUAL "USE")
  1080. set(_state "use")
  1081. elseif (${arg} STREQUAL "VERSION")
  1082. set(_state "version")
  1083. else ()
  1084. set(_javadoc_author ${arg})
  1085. endif ()
  1086. elseif (${_state} STREQUAL "use")
  1087. if (${arg} STREQUAL "PACKAGES")
  1088. set(_state "packages")
  1089. elseif (${arg} STREQUAL "FILES")
  1090. set(_state "files")
  1091. elseif (${arg} STREQUAL "SOURCEPATH")
  1092. set(_state "sourcepath")
  1093. elseif (${arg} STREQUAL "CLASSPATH")
  1094. set(_state "classpath")
  1095. elseif (${arg} STREQUAL "INSTALLPATH")
  1096. set(_state "installpath")
  1097. elseif (${arg} STREQUAL "DOCTITLE")
  1098. set(_state "doctitle")
  1099. elseif (${arg} STREQUAL "WINDOWTITLE")
  1100. set(_state "windowtitle")
  1101. elseif (${arg} STREQUAL "AUTHOR")
  1102. set(_state "author")
  1103. elseif (${arg} STREQUAL "USE")
  1104. set(_state "use")
  1105. elseif (${arg} STREQUAL "VERSION")
  1106. set(_state "version")
  1107. else ()
  1108. set(_javadoc_use ${arg})
  1109. endif ()
  1110. elseif (${_state} STREQUAL "version")
  1111. if (${arg} STREQUAL "PACKAGES")
  1112. set(_state "packages")
  1113. elseif (${arg} STREQUAL "FILES")
  1114. set(_state "files")
  1115. elseif (${arg} STREQUAL "SOURCEPATH")
  1116. set(_state "sourcepath")
  1117. elseif (${arg} STREQUAL "CLASSPATH")
  1118. set(_state "classpath")
  1119. elseif (${arg} STREQUAL "INSTALLPATH")
  1120. set(_state "installpath")
  1121. elseif (${arg} STREQUAL "DOCTITLE")
  1122. set(_state "doctitle")
  1123. elseif (${arg} STREQUAL "WINDOWTITLE")
  1124. set(_state "windowtitle")
  1125. elseif (${arg} STREQUAL "AUTHOR")
  1126. set(_state "author")
  1127. elseif (${arg} STREQUAL "USE")
  1128. set(_state "use")
  1129. elseif (${arg} STREQUAL "VERSION")
  1130. set(_state "version")
  1131. else ()
  1132. set(_javadoc_version ${arg})
  1133. endif ()
  1134. endif ()
  1135. endforeach ()
  1136. set(_javadoc_builddir ${CMAKE_CURRENT_BINARY_DIR}/javadoc/${_target})
  1137. set(_javadoc_options -d ${_javadoc_builddir})
  1138. if (_javadoc_sourcepath)
  1139. set(_start TRUE)
  1140. foreach(_path ${_javadoc_sourcepath})
  1141. if (_start)
  1142. set(_sourcepath ${_path})
  1143. set(_start FALSE)
  1144. else ()
  1145. set(_sourcepath ${_sourcepath}:${_path})
  1146. endif ()
  1147. endforeach()
  1148. set(_javadoc_options ${_javadoc_options} -sourcepath ${_sourcepath})
  1149. endif ()
  1150. if (_javadoc_classpath)
  1151. set(_start TRUE)
  1152. foreach(_path ${_javadoc_classpath})
  1153. if (_start)
  1154. set(_classpath ${_path})
  1155. set(_start FALSE)
  1156. else ()
  1157. set(_classpath ${_classpath}:${_path})
  1158. endif ()
  1159. endforeach()
  1160. set(_javadoc_options ${_javadoc_options} -classpath "${_classpath}")
  1161. endif ()
  1162. if (_javadoc_doctitle)
  1163. set(_javadoc_options ${_javadoc_options} -doctitle '${_javadoc_doctitle}')
  1164. endif ()
  1165. if (_javadoc_windowtitle)
  1166. set(_javadoc_options ${_javadoc_options} -windowtitle '${_javadoc_windowtitle}')
  1167. endif ()
  1168. if (_javadoc_author)
  1169. set(_javadoc_options ${_javadoc_options} -author)
  1170. endif ()
  1171. if (_javadoc_use)
  1172. set(_javadoc_options ${_javadoc_options} -use)
  1173. endif ()
  1174. if (_javadoc_version)
  1175. set(_javadoc_options ${_javadoc_options} -version)
  1176. endif ()
  1177. add_custom_target(${_target}_javadoc ALL
  1178. COMMAND ${Java_JAVADOC_EXECUTABLE} ${_javadoc_options}
  1179. ${_javadoc_files}
  1180. ${_javadoc_packages}
  1181. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  1182. )
  1183. install(
  1184. DIRECTORY ${_javadoc_builddir}
  1185. DESTINATION ${_javadoc_installpath}
  1186. )
  1187. endfunction()
  1188. function (create_javah)
  1189. cmake_parse_arguments(_create_javah
  1190. ""
  1191. "TARGET;GENERATED_FILES;OUTPUT_NAME;OUTPUT_DIR"
  1192. "CLASSES;CLASSPATH;DEPENDS"
  1193. ${ARGN})
  1194. # ckeck parameters
  1195. if (NOT _create_javah_TARGET AND NOT _create_javah_GENERATED_FILES)
  1196. message (FATAL_ERROR "create_javah: TARGET or GENERATED_FILES must be specified.")
  1197. endif()
  1198. if (_create_javah_OUTPUT_NAME AND _create_javah_OUTPUT_DIR)
  1199. message (FATAL_ERROR "create_javah: OUTPUT_NAME and OUTPUT_DIR are mutually exclusive.")
  1200. endif()
  1201. if (NOT _create_javah_CLASSES)
  1202. message (FATAL_ERROR "create_javah: CLASSES is a required parameter.")
  1203. endif()
  1204. set (_output_files)
  1205. if (WIN32 AND NOT CYGWIN AND CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
  1206. set(_classpath_sep "$<SEMICOLON>")
  1207. else ()
  1208. set(_classpath_sep ":")
  1209. endif()
  1210. # handle javah options
  1211. set (_javah_options)
  1212. if (_create_javah_CLASSPATH)
  1213. # CLASSPATH can specify directories, jar files or targets created with add_jar command
  1214. set (_classpath)
  1215. foreach (_path IN LISTS _create_javah_CLASSPATH)
  1216. if (TARGET ${_path})
  1217. get_target_property (_jar_path ${_path} JAR_FILE)
  1218. if (_jar_path)
  1219. list (APPEND _classpath "${_jar_path}")
  1220. list (APPEND _create_javah_DEPENDS "${_path}")
  1221. else()
  1222. message(SEND_ERROR "create_javah: CLASSPATH target ${_path} is not a jar.")
  1223. endif()
  1224. elseif (EXISTS "${_path}")
  1225. list (APPEND _classpath "${_path}")
  1226. if (NOT IS_DIRECTORY "${_path}")
  1227. list (APPEND _create_javah_DEPENDS "${_path}")
  1228. endif()
  1229. else()
  1230. message(SEND_ERROR "create_javah: CLASSPATH entry ${_path} does not exist.")
  1231. endif()
  1232. endforeach()
  1233. string (REPLACE ";" "${_classpath_sep}" _classpath "${_classpath}")
  1234. list (APPEND _javah_options -classpath "${_classpath}")
  1235. endif()
  1236. if (_create_javah_OUTPUT_DIR)
  1237. list (APPEND _javah_options -d "${_create_javah_OUTPUT_DIR}")
  1238. endif()
  1239. if (_create_javah_OUTPUT_NAME)
  1240. list (APPEND _javah_options -o "${_create_javah_OUTPUT_NAME}")
  1241. set (_output_files "${_create_javah_OUTPUT_NAME}")
  1242. get_filename_component (_create_javah_OUTPUT_DIR "${_create_javah_OUTPUT_NAME}" DIRECTORY)
  1243. get_filename_component (_create_javah_OUTPUT_DIR "${_create_javah_OUTPUT_DIR}" ABSOLUTE)
  1244. endif()
  1245. if (NOT _create_javah_OUTPUT_DIR)
  1246. set (_create_javah_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
  1247. endif()
  1248. if (NOT _create_javah_OUTPUT_NAME)
  1249. # compute output names
  1250. foreach (_class IN LISTS _create_javah_CLASSES)
  1251. string (REPLACE "." "_" _c_header "${_class}")
  1252. set (_c_header "${_create_javah_OUTPUT_DIR}/${_c_header}.h")
  1253. list (APPEND _output_files "${_c_header}")
  1254. endforeach()
  1255. endif()
  1256. # finalize custom command arguments
  1257. if (_create_javah_DEPENDS)
  1258. list (INSERT _create_javah_DEPENDS 0 DEPENDS)
  1259. endif()
  1260. add_custom_command (OUTPUT ${_output_files}
  1261. COMMAND "${Java_JAVAH_EXECUTABLE}" ${_javah_options} -jni ${_create_javah_CLASSES}
  1262. ${_create_javah_DEPENDS}
  1263. WORKING_DIRECTORY ${_create_javah_OUTPUT_DIR}
  1264. COMMENT "Building C header files from classes...")
  1265. if (_create_javah_TARGET)
  1266. add_custom_target (${_create_javah_TARGET} ALL DEPENDS ${_output_files})
  1267. endif()
  1268. if (_create_javah_GENERATED_FILES)
  1269. set (${_create_javah_GENERATED_FILES} ${_output_files} PARENT_SCOPE)
  1270. endif()
  1271. endfunction()
  1272. function(export_jars)
  1273. # Parse and validate arguments
  1274. cmake_parse_arguments(_export_jars
  1275. ""
  1276. "FILE"
  1277. "TARGETS"
  1278. ${ARGN}
  1279. )
  1280. if (NOT _export_jars_FILE)
  1281. message(SEND_ERROR "export_jars: FILE must be specified.")
  1282. endif()
  1283. if (NOT _export_jars_TARGETS)
  1284. message(SEND_ERROR "export_jars: TARGETS must be specified.")
  1285. endif()
  1286. # Set content of generated exports file
  1287. string(REPLACE ";" " " __targets__ "${_export_jars_TARGETS}")
  1288. set(__targetdefs__ "")
  1289. foreach(_target ${_export_jars_TARGETS})
  1290. get_target_property(_jarpath ${_target} JAR_FILE)
  1291. get_filename_component(_jarpath ${_jarpath} PATH)
  1292. __java_export_jar(__targetdefs__ ${_target} "${_jarpath}")
  1293. endforeach()
  1294. # Generate exports file
  1295. configure_file(
  1296. ${_JAVA_EXPORT_TARGETS_SCRIPT}
  1297. ${_export_jars_FILE}
  1298. @ONLY
  1299. )
  1300. endfunction()
  1301. function(install_jar_exports)
  1302. # Parse and validate arguments
  1303. cmake_parse_arguments(_install_jar_exports
  1304. ""
  1305. "FILE;DESTINATION;COMPONENT"
  1306. "TARGETS"
  1307. ${ARGN}
  1308. )
  1309. if (NOT _install_jar_exports_FILE)
  1310. message(SEND_ERROR "install_jar_exports: FILE must be specified.")
  1311. endif()
  1312. if (NOT _install_jar_exports_DESTINATION)
  1313. message(SEND_ERROR "install_jar_exports: DESTINATION must be specified.")
  1314. endif()
  1315. if (NOT _install_jar_exports_TARGETS)
  1316. message(SEND_ERROR "install_jar_exports: TARGETS must be specified.")
  1317. endif()
  1318. if (_install_jar_exports_COMPONENT)
  1319. set (_COMPONENT COMPONENT ${_install_jar_exports_COMPONENT})
  1320. endif()
  1321. # Determine relative path from installed export file to install prefix
  1322. if(IS_ABSOLUTE ${_install_jar_exports_DESTINATION})
  1323. file(RELATIVE_PATH _relpath
  1324. ${_install_jar_exports_DESTINATION}
  1325. ${CMAKE_INSTALL_PREFIX}
  1326. )
  1327. else()
  1328. file(RELATIVE_PATH _relpath
  1329. ${CMAKE_INSTALL_PREFIX}/${_install_jar_exports_DESTINATION}
  1330. ${CMAKE_INSTALL_PREFIX}
  1331. )
  1332. endif()
  1333. # Set up unique location for generated exports file
  1334. string(SHA256 _hash "${_install_jar_exports_DESTINATION}")
  1335. set(_tmpdir ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/JavaExports/${_hash})
  1336. # Set content of generated exports file
  1337. string(REPLACE ";" " " __targets__ "${_install_jar_exports_TARGETS}")
  1338. set(__targetdefs__ "set(_prefix \${CMAKE_CURRENT_LIST_DIR}/${_relpath})\n\n")
  1339. foreach(_target ${_install_jar_exports_TARGETS})
  1340. get_target_property(_dir ${_target} INSTALL_DESTINATION)
  1341. __java_export_jar(__targetdefs__ ${_target} "\${_prefix}/${_dir}")
  1342. endforeach()
  1343. __java_lcat(__targetdefs__ "\nunset(_prefix)")
  1344. # Generate and install exports file
  1345. configure_file(
  1346. ${_JAVA_EXPORT_TARGETS_SCRIPT}
  1347. ${_tmpdir}/${_install_jar_exports_FILE}
  1348. @ONLY
  1349. )
  1350. install(FILES ${_tmpdir}/${_install_jar_exports_FILE}
  1351. DESTINATION ${_install_jar_exports_DESTINATION}
  1352. ${_COMPONENT})
  1353. endfunction()