UseJava.cmake 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  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() functions 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. # CLASS_DIR 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. # ::
  221. #
  222. # install_jni_symlink(target_name destination)
  223. # install_jni_symlink(target_name DESTINATION destination [COMPONENT component])
  224. #
  225. # This command installs the TARGET_NAME JNI symlinks to the given
  226. # DESTINATION. It should be called in the same scope as add_jar() or it
  227. # will fail.
  228. #
  229. # ::
  230. #
  231. # create_javadoc(<VAR>
  232. # PACKAGES pkg1 [pkg2 ...]
  233. # [SOURCEPATH <sourcepath>]
  234. # [CLASSPATH <classpath>]
  235. # [INSTALLPATH <install path>]
  236. # [DOCTITLE "the documentation title"]
  237. # [WINDOWTITLE "the title of the document"]
  238. # [AUTHOR TRUE|FALSE]
  239. # [USE TRUE|FALSE]
  240. # [VERSION TRUE|FALSE]
  241. # )
  242. #
  243. # Create java documentation based on files or packages. For more
  244. # details please read the javadoc manpage.
  245. #
  246. # There are two main signatures for create_javadoc. The first signature
  247. # works with package names on a path with source files:
  248. #
  249. # ::
  250. #
  251. # Example:
  252. # create_javadoc(my_example_doc
  253. # PACKAGES com.exmaple.foo com.example.bar
  254. # SOURCEPATH "${CMAKE_CURRENT_SOURCE_DIR}"
  255. # CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH}
  256. # WINDOWTITLE "My example"
  257. # DOCTITLE "<h1>My example</h1>"
  258. # AUTHOR TRUE
  259. # USE TRUE
  260. # VERSION TRUE
  261. # )
  262. #
  263. #
  264. #
  265. # The second signature for create_javadoc works on a given list of
  266. # files.
  267. #
  268. # ::
  269. #
  270. # create_javadoc(<VAR>
  271. # FILES file1 [file2 ...]
  272. # [CLASSPATH <classpath>]
  273. # [INSTALLPATH <install path>]
  274. # [DOCTITLE "the documentation title"]
  275. # [WINDOWTITLE "the title of the document"]
  276. # [AUTHOR TRUE|FALSE]
  277. # [USE TRUE|FALSE]
  278. # [VERSION TRUE|FALSE]
  279. # )
  280. #
  281. #
  282. #
  283. # Example:
  284. #
  285. # ::
  286. #
  287. # create_javadoc(my_example_doc
  288. # FILES ${example_SRCS}
  289. # CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH}
  290. # WINDOWTITLE "My example"
  291. # DOCTITLE "<h1>My example</h1>"
  292. # AUTHOR TRUE
  293. # USE TRUE
  294. # VERSION TRUE
  295. # )
  296. #
  297. #
  298. #
  299. # Both signatures share most of the options. These options are the same
  300. # as what you can find in the javadoc manpage. Please look at the
  301. # manpage for CLASSPATH, DOCTITLE, WINDOWTITLE, AUTHOR, USE and VERSION.
  302. #
  303. # The documentation will be by default installed to
  304. #
  305. # ::
  306. #
  307. # ${CMAKE_INSTALL_PREFIX}/share/javadoc/<VAR>
  308. #
  309. #
  310. #
  311. # if you don't set the INSTALLPATH.
  312. #=============================================================================
  313. # Copyright 2013 OpenGamma Ltd. <[email protected]>
  314. # Copyright 2010-2011 Andreas schneider <[email protected]>
  315. # Copyright 2010-2013 Kitware, Inc.
  316. #
  317. # Distributed under the OSI-approved BSD License (the "License");
  318. # see accompanying file Copyright.txt for details.
  319. #
  320. # This software is distributed WITHOUT ANY WARRANTY; without even the
  321. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  322. # See the License for more information.
  323. #=============================================================================
  324. # (To distribute this file outside of CMake, substitute the full
  325. # License text for the above reference.)
  326. include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
  327. function (__java_copy_file src dest comment)
  328. add_custom_command(
  329. OUTPUT ${dest}
  330. COMMAND cmake -E copy_if_different
  331. ARGS ${src}
  332. ${dest}
  333. DEPENDS ${src}
  334. COMMENT ${comment})
  335. endfunction ()
  336. # define helper scripts
  337. set(_JAVA_CLASS_FILELIST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaClassFilelist.cmake)
  338. set(_JAVA_SYMLINK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaSymlinks.cmake)
  339. function(add_jar _TARGET_NAME)
  340. cmake_parse_arguments(_add_jar
  341. ""
  342. "VERSION;OUTPUT_DIR;OUTPUT_NAME;ENTRY_POINT;MANIFEST"
  343. "SOURCES;INCLUDE_JARS"
  344. ${ARGN}
  345. )
  346. # In CMake < 2.8.12, add_jar used variables which were set prior to calling
  347. # add_jar for customizing the behavior of add_jar. In order to be backwards
  348. # compatible, check if any of those variables are set, and use them to
  349. # initialize values of the named arguments. (Giving the corresponding named
  350. # argument will override the value set here.)
  351. #
  352. # New features should use named arguments only.
  353. if(NOT DEFINED _add_jar_VERSION AND DEFINED CMAKE_JAVA_TARGET_VERSION)
  354. set(_add_jar_VERSION "${CMAKE_JAVA_TARGET_VERSION}")
  355. endif()
  356. if(NOT DEFINED _add_jar_OUTPUT_DIR AND DEFINED CMAKE_JAVA_TARGET_OUTPUT_DIR)
  357. set(_add_jar_OUTPUT_DIR "${CMAKE_JAVA_TARGET_OUTPUT_DIR}")
  358. endif()
  359. if(NOT DEFINED _add_jar_OUTPUT_NAME AND DEFINED CMAKE_JAVA_TARGET_OUTPUT_NAME)
  360. set(_add_jar_OUTPUT_NAME "${CMAKE_JAVA_TARGET_OUTPUT_NAME}")
  361. # reset
  362. set(CMAKE_JAVA_TARGET_OUTPUT_NAME)
  363. endif()
  364. if(NOT DEFINED _add_jar_ENTRY_POINT AND DEFINED CMAKE_JAVA_JAR_ENTRY_POINT)
  365. set(_add_jar_ENTRY_POINT "${CMAKE_JAVA_JAR_ENTRY_POINT}")
  366. endif()
  367. set(_JAVA_SOURCE_FILES ${_add_jar_SOURCES} ${_add_jar_UNPARSED_ARGUMENTS})
  368. if (NOT DEFINED _add_jar_OUTPUT_DIR)
  369. set(_add_jar_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
  370. endif()
  371. if (_add_jar_ENTRY_POINT)
  372. set(_ENTRY_POINT_OPTION e)
  373. set(_ENTRY_POINT_VALUE ${_add_jar_ENTRY_POINT})
  374. endif ()
  375. if (_add_jar_MANIFEST)
  376. set(_MANIFEST_OPTION m)
  377. set(_MANIFEST_VALUE ${_add_jar_MANIFEST})
  378. endif ()
  379. if (LIBRARY_OUTPUT_PATH)
  380. set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH})
  381. else ()
  382. set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${_add_jar_OUTPUT_DIR})
  383. endif ()
  384. set(CMAKE_JAVA_INCLUDE_PATH
  385. ${CMAKE_JAVA_INCLUDE_PATH}
  386. ${CMAKE_CURRENT_SOURCE_DIR}
  387. ${CMAKE_JAVA_OBJECT_OUTPUT_PATH}
  388. ${CMAKE_JAVA_LIBRARY_OUTPUT_PATH}
  389. )
  390. if (CMAKE_HOST_WIN32 AND NOT CYGWIN AND CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
  391. set(CMAKE_JAVA_INCLUDE_FLAG_SEP ";")
  392. else ()
  393. set(CMAKE_JAVA_INCLUDE_FLAG_SEP ":")
  394. endif()
  395. foreach (JAVA_INCLUDE_DIR ${CMAKE_JAVA_INCLUDE_PATH})
  396. set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${JAVA_INCLUDE_DIR}")
  397. endforeach()
  398. set(CMAKE_JAVA_CLASS_OUTPUT_PATH "${_add_jar_OUTPUT_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir")
  399. set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}.jar")
  400. if (_add_jar_OUTPUT_NAME AND _add_jar_VERSION)
  401. set(_JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}-${_add_jar_VERSION}.jar")
  402. set(_JAVA_TARGET_OUTPUT_LINK "${_add_jar_OUTPUT_NAME}.jar")
  403. elseif (_add_jar_VERSION)
  404. set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}-${_add_jar_VERSION}.jar")
  405. set(_JAVA_TARGET_OUTPUT_LINK "${_TARGET_NAME}.jar")
  406. elseif (_add_jar_OUTPUT_NAME)
  407. set(_JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}.jar")
  408. endif ()
  409. set(_JAVA_CLASS_FILES)
  410. set(_JAVA_COMPILE_FILES)
  411. set(_JAVA_COMPILE_FILELISTS)
  412. set(_JAVA_DEPENDS)
  413. set(_JAVA_COMPILE_DEPENDS)
  414. set(_JAVA_RESOURCE_FILES)
  415. set(_JAVA_RESOURCE_FILES_RELATIVE)
  416. foreach(_JAVA_SOURCE_FILE ${_JAVA_SOURCE_FILES})
  417. get_filename_component(_JAVA_EXT ${_JAVA_SOURCE_FILE} EXT)
  418. get_filename_component(_JAVA_FILE ${_JAVA_SOURCE_FILE} NAME_WE)
  419. get_filename_component(_JAVA_PATH ${_JAVA_SOURCE_FILE} PATH)
  420. get_filename_component(_JAVA_FULL ${_JAVA_SOURCE_FILE} ABSOLUTE)
  421. if (_JAVA_SOURCE_FILE MATCHES "^@(.+)$")
  422. get_filename_component(_JAVA_FULL ${CMAKE_MATCH_1} ABSOLUTE)
  423. list(APPEND _JAVA_COMPILE_FILELISTS ${_JAVA_FULL})
  424. elseif (_JAVA_EXT MATCHES ".java")
  425. file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${_add_jar_OUTPUT_DIR} ${_JAVA_FULL})
  426. file(RELATIVE_PATH _JAVA_REL_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${_JAVA_FULL})
  427. string(LENGTH ${_JAVA_REL_BINARY_PATH} _BIN_LEN)
  428. string(LENGTH ${_JAVA_REL_SOURCE_PATH} _SRC_LEN)
  429. if (${_BIN_LEN} LESS ${_SRC_LEN})
  430. set(_JAVA_REL_PATH ${_JAVA_REL_BINARY_PATH})
  431. else ()
  432. set(_JAVA_REL_PATH ${_JAVA_REL_SOURCE_PATH})
  433. endif ()
  434. get_filename_component(_JAVA_REL_PATH ${_JAVA_REL_PATH} PATH)
  435. list(APPEND _JAVA_COMPILE_FILES ${_JAVA_SOURCE_FILE})
  436. set(_JAVA_CLASS_FILE "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_REL_PATH}/${_JAVA_FILE}.class")
  437. set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES} ${_JAVA_CLASS_FILE})
  438. elseif (_JAVA_EXT MATCHES ".jar"
  439. OR _JAVA_EXT MATCHES ".war"
  440. OR _JAVA_EXT MATCHES ".ear"
  441. OR _JAVA_EXT MATCHES ".sar")
  442. # Ignored for backward compatibility
  443. elseif (_JAVA_EXT STREQUAL "")
  444. list(APPEND CMAKE_JAVA_INCLUDE_PATH ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}} ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}_CLASSPATH})
  445. list(APPEND _JAVA_DEPENDS ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}})
  446. else ()
  447. __java_copy_file(${CMAKE_CURRENT_SOURCE_DIR}/${_JAVA_SOURCE_FILE}
  448. ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE}
  449. "Copying ${_JAVA_SOURCE_FILE} to the build directory")
  450. list(APPEND _JAVA_RESOURCE_FILES ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE})
  451. list(APPEND _JAVA_RESOURCE_FILES_RELATIVE ${_JAVA_SOURCE_FILE})
  452. endif ()
  453. endforeach()
  454. foreach(_JAVA_INCLUDE_JAR ${_add_jar_INCLUDE_JARS})
  455. if (TARGET ${_JAVA_INCLUDE_JAR})
  456. get_target_property(_JAVA_JAR_PATH ${_JAVA_INCLUDE_JAR} JAR_FILE)
  457. if (_JAVA_JAR_PATH)
  458. set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_JAR_PATH}")
  459. list(APPEND CMAKE_JAVA_INCLUDE_PATH ${_JAVA_JAR_PATH})
  460. list(APPEND _JAVA_DEPENDS ${_JAVA_INCLUDE_JAR})
  461. list(APPEND _JAVA_COMPILE_DEPENDS ${_JAVA_INCLUDE_JAR})
  462. else ()
  463. message(SEND_ERROR "add_jar: INCLUDE_JARS target ${_JAVA_INCLUDE_JAR} is not a jar")
  464. endif ()
  465. else ()
  466. set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_INCLUDE_JAR}")
  467. list(APPEND CMAKE_JAVA_INCLUDE_PATH "${_JAVA_INCLUDE_JAR}")
  468. list(APPEND _JAVA_DEPENDS "${_JAVA_INCLUDE_JAR}")
  469. list(APPEND _JAVA_COMPILE_DEPENDS "${_JAVA_INCLUDE_JAR}")
  470. endif ()
  471. endforeach()
  472. # create an empty java_class_filelist
  473. if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist)
  474. file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "")
  475. endif()
  476. if (_JAVA_COMPILE_FILES OR _JAVA_COMPILE_FILELISTS)
  477. set (_JAVA_SOURCES_FILELISTS)
  478. if (_JAVA_COMPILE_FILES)
  479. # Create the list of files to compile.
  480. set(_JAVA_SOURCES_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_sources)
  481. string(REPLACE ";" "\"\n\"" _JAVA_COMPILE_STRING "\"${_JAVA_COMPILE_FILES}\"")
  482. file(WRITE ${_JAVA_SOURCES_FILE} ${_JAVA_COMPILE_STRING})
  483. list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_SOURCES_FILE}")
  484. endif()
  485. if (_JAVA_COMPILE_FILELISTS)
  486. foreach (_JAVA_FILELIST IN LISTS _JAVA_COMPILE_FILELISTS)
  487. list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_FILELIST}")
  488. endforeach()
  489. endif()
  490. # Compile the java files and create a list of class files
  491. add_custom_command(
  492. # NOTE: this command generates an artificial dependency file
  493. OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
  494. COMMAND ${Java_JAVAC_EXECUTABLE}
  495. ${CMAKE_JAVA_COMPILE_FLAGS}
  496. -classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}"
  497. -d ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  498. ${_JAVA_SOURCES_FILELISTS}
  499. COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
  500. DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_FILELISTS} ${_JAVA_COMPILE_DEPENDS}
  501. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  502. COMMENT "Building Java objects for ${_TARGET_NAME}.jar"
  503. )
  504. add_custom_command(
  505. OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
  506. COMMAND ${CMAKE_COMMAND}
  507. -DCMAKE_JAVA_CLASS_OUTPUT_PATH=${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  508. -DCMAKE_JAR_CLASSES_PREFIX="${CMAKE_JAR_CLASSES_PREFIX}"
  509. -P ${_JAVA_CLASS_FILELIST_SCRIPT}
  510. DEPENDS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
  511. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  512. )
  513. endif ()
  514. # create the jar file
  515. set(_JAVA_JAR_OUTPUT_PATH
  516. ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_NAME})
  517. if (CMAKE_JNI_TARGET)
  518. add_custom_command(
  519. OUTPUT ${_JAVA_JAR_OUTPUT_PATH}
  520. COMMAND ${Java_JAR_EXECUTABLE}
  521. -cf${_ENTRY_POINT_OPTION}${_MANIFEST_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_MANIFEST_VALUE}
  522. ${_JAVA_RESOURCE_FILES_RELATIVE} @java_class_filelist
  523. COMMAND ${CMAKE_COMMAND}
  524. -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
  525. -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME}
  526. -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
  527. -P ${_JAVA_SYMLINK_SCRIPT}
  528. COMMAND ${CMAKE_COMMAND}
  529. -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
  530. -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_JAR_OUTPUT_PATH}
  531. -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
  532. -P ${_JAVA_SYMLINK_SCRIPT}
  533. DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
  534. WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  535. COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}"
  536. )
  537. else ()
  538. add_custom_command(
  539. OUTPUT ${_JAVA_JAR_OUTPUT_PATH}
  540. COMMAND ${Java_JAR_EXECUTABLE}
  541. -cf${_ENTRY_POINT_OPTION}${_MANIFEST_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_MANIFEST_VALUE}
  542. ${_JAVA_RESOURCE_FILES_RELATIVE} @java_class_filelist
  543. COMMAND ${CMAKE_COMMAND}
  544. -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
  545. -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME}
  546. -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
  547. -P ${_JAVA_SYMLINK_SCRIPT}
  548. WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  549. DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
  550. COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}"
  551. )
  552. endif ()
  553. # Add the target and make sure we have the latest resource files.
  554. add_custom_target(${_TARGET_NAME} ALL DEPENDS ${_JAVA_JAR_OUTPUT_PATH})
  555. set_property(
  556. TARGET
  557. ${_TARGET_NAME}
  558. PROPERTY
  559. INSTALL_FILES
  560. ${_JAVA_JAR_OUTPUT_PATH}
  561. )
  562. if (_JAVA_TARGET_OUTPUT_LINK)
  563. set_property(
  564. TARGET
  565. ${_TARGET_NAME}
  566. PROPERTY
  567. INSTALL_FILES
  568. ${_JAVA_JAR_OUTPUT_PATH}
  569. ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK}
  570. )
  571. if (CMAKE_JNI_TARGET)
  572. set_property(
  573. TARGET
  574. ${_TARGET_NAME}
  575. PROPERTY
  576. JNI_SYMLINK
  577. ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK}
  578. )
  579. endif ()
  580. endif ()
  581. set_property(
  582. TARGET
  583. ${_TARGET_NAME}
  584. PROPERTY
  585. JAR_FILE
  586. ${_JAVA_JAR_OUTPUT_PATH}
  587. )
  588. set_property(
  589. TARGET
  590. ${_TARGET_NAME}
  591. PROPERTY
  592. CLASSDIR
  593. ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  594. )
  595. endfunction()
  596. function(INSTALL_JAR _TARGET_NAME)
  597. if (ARGC EQUAL 2)
  598. set (_DESTINATION ${ARGV1})
  599. else()
  600. cmake_parse_arguments(_install_jar
  601. ""
  602. "DESTINATION;COMPONENT"
  603. ""
  604. ${ARGN})
  605. if (_install_jar_DESTINATION)
  606. set (_DESTINATION ${_install_jar_DESTINATION})
  607. else()
  608. message(SEND_ERROR "install_jar: ${_TARGET_NAME}: DESTINATION must be specified.")
  609. endif()
  610. if (_install_jar_COMPONENT)
  611. set (_COMPONENT COMPONENT ${_install_jar_COMPONENT})
  612. endif()
  613. endif()
  614. get_property(__FILES
  615. TARGET
  616. ${_TARGET_NAME}
  617. PROPERTY
  618. INSTALL_FILES
  619. )
  620. if (__FILES)
  621. install(
  622. FILES
  623. ${__FILES}
  624. DESTINATION
  625. ${_DESTINATION}
  626. ${_COMPONENT}
  627. )
  628. else ()
  629. message(SEND_ERROR "install_jar: The target ${_TARGET_NAME} is not known in this scope.")
  630. endif ()
  631. endfunction()
  632. function(INSTALL_JNI_SYMLINK _TARGET_NAME)
  633. if (ARGC EQUAL 2)
  634. set (_DESTINATION ${ARGV1})
  635. else()
  636. cmake_parse_arguments(_install_jni_symlink
  637. ""
  638. "DESTINATION;COMPONENT"
  639. ""
  640. ${ARGN})
  641. if (_install_jni_symlink_DESTINATION)
  642. set (_DESTINATION ${_install_jni_symlink_DESTINATION})
  643. else()
  644. message(SEND_ERROR "install_jni_symlink: ${_TARGET_NAME}: DESTINATION must be specified.")
  645. endif()
  646. if (_install_jni_symlink_COMPONENT)
  647. set (_COMPONENT COMPONENT ${_install_jni_symlink_COMPONENT})
  648. endif()
  649. endif()
  650. get_property(__SYMLINK
  651. TARGET
  652. ${_TARGET_NAME}
  653. PROPERTY
  654. JNI_SYMLINK
  655. )
  656. if (__SYMLINK)
  657. install(
  658. FILES
  659. ${__SYMLINK}
  660. DESTINATION
  661. ${_DESTINATION}
  662. ${_COMPONENT}
  663. )
  664. else ()
  665. message(SEND_ERROR "install_jni_symlink: The target ${_TARGET_NAME} is not known in this scope.")
  666. endif ()
  667. endfunction()
  668. function (find_jar VARIABLE)
  669. set(_jar_names)
  670. set(_jar_files)
  671. set(_jar_versions)
  672. set(_jar_paths
  673. /usr/share/java/
  674. /usr/local/share/java/
  675. ${Java_JAR_PATHS})
  676. set(_jar_doc "NOTSET")
  677. set(_state "name")
  678. foreach (arg ${ARGN})
  679. if (${_state} STREQUAL "name")
  680. if (${arg} STREQUAL "VERSIONS")
  681. set(_state "versions")
  682. elseif (${arg} STREQUAL "NAMES")
  683. set(_state "names")
  684. elseif (${arg} STREQUAL "PATHS")
  685. set(_state "paths")
  686. elseif (${arg} STREQUAL "DOC")
  687. set(_state "doc")
  688. else ()
  689. set(_jar_names ${arg})
  690. if (_jar_doc STREQUAL "NOTSET")
  691. set(_jar_doc "Finding ${arg} jar")
  692. endif ()
  693. endif ()
  694. elseif (${_state} STREQUAL "versions")
  695. if (${arg} STREQUAL "NAMES")
  696. set(_state "names")
  697. elseif (${arg} STREQUAL "PATHS")
  698. set(_state "paths")
  699. elseif (${arg} STREQUAL "DOC")
  700. set(_state "doc")
  701. else ()
  702. set(_jar_versions ${_jar_versions} ${arg})
  703. endif ()
  704. elseif (${_state} STREQUAL "names")
  705. if (${arg} STREQUAL "VERSIONS")
  706. set(_state "versions")
  707. elseif (${arg} STREQUAL "PATHS")
  708. set(_state "paths")
  709. elseif (${arg} STREQUAL "DOC")
  710. set(_state "doc")
  711. else ()
  712. set(_jar_names ${_jar_names} ${arg})
  713. if (_jar_doc STREQUAL "NOTSET")
  714. set(_jar_doc "Finding ${arg} jar")
  715. endif ()
  716. endif ()
  717. elseif (${_state} STREQUAL "paths")
  718. if (${arg} STREQUAL "VERSIONS")
  719. set(_state "versions")
  720. elseif (${arg} STREQUAL "NAMES")
  721. set(_state "names")
  722. elseif (${arg} STREQUAL "DOC")
  723. set(_state "doc")
  724. else ()
  725. set(_jar_paths ${_jar_paths} ${arg})
  726. endif ()
  727. elseif (${_state} STREQUAL "doc")
  728. if (${arg} STREQUAL "VERSIONS")
  729. set(_state "versions")
  730. elseif (${arg} STREQUAL "NAMES")
  731. set(_state "names")
  732. elseif (${arg} STREQUAL "PATHS")
  733. set(_state "paths")
  734. else ()
  735. set(_jar_doc ${arg})
  736. endif ()
  737. endif ()
  738. endforeach ()
  739. if (NOT _jar_names)
  740. message(FATAL_ERROR "find_jar: No name to search for given")
  741. endif ()
  742. foreach (jar_name ${_jar_names})
  743. foreach (version ${_jar_versions})
  744. set(_jar_files ${_jar_files} ${jar_name}-${version}.jar)
  745. endforeach ()
  746. set(_jar_files ${_jar_files} ${jar_name}.jar)
  747. endforeach ()
  748. find_file(${VARIABLE}
  749. NAMES ${_jar_files}
  750. PATHS ${_jar_paths}
  751. DOC ${_jar_doc}
  752. NO_DEFAULT_PATH)
  753. endfunction ()
  754. function(create_javadoc _target)
  755. set(_javadoc_packages)
  756. set(_javadoc_files)
  757. set(_javadoc_sourcepath)
  758. set(_javadoc_classpath)
  759. set(_javadoc_installpath "${CMAKE_INSTALL_PREFIX}/share/javadoc")
  760. set(_javadoc_doctitle)
  761. set(_javadoc_windowtitle)
  762. set(_javadoc_author FALSE)
  763. set(_javadoc_version FALSE)
  764. set(_javadoc_use FALSE)
  765. set(_state "package")
  766. foreach (arg ${ARGN})
  767. if (${_state} STREQUAL "package")
  768. if (${arg} STREQUAL "PACKAGES")
  769. set(_state "packages")
  770. elseif (${arg} STREQUAL "FILES")
  771. set(_state "files")
  772. elseif (${arg} STREQUAL "SOURCEPATH")
  773. set(_state "sourcepath")
  774. elseif (${arg} STREQUAL "CLASSPATH")
  775. set(_state "classpath")
  776. elseif (${arg} STREQUAL "INSTALLPATH")
  777. set(_state "installpath")
  778. elseif (${arg} STREQUAL "DOCTITLE")
  779. set(_state "doctitle")
  780. elseif (${arg} STREQUAL "WINDOWTITLE")
  781. set(_state "windowtitle")
  782. elseif (${arg} STREQUAL "AUTHOR")
  783. set(_state "author")
  784. elseif (${arg} STREQUAL "USE")
  785. set(_state "use")
  786. elseif (${arg} STREQUAL "VERSION")
  787. set(_state "version")
  788. else ()
  789. set(_javadoc_packages ${arg})
  790. set(_state "packages")
  791. endif ()
  792. elseif (${_state} STREQUAL "packages")
  793. if (${arg} STREQUAL "FILES")
  794. set(_state "files")
  795. elseif (${arg} STREQUAL "SOURCEPATH")
  796. set(_state "sourcepath")
  797. elseif (${arg} STREQUAL "CLASSPATH")
  798. set(_state "classpath")
  799. elseif (${arg} STREQUAL "INSTALLPATH")
  800. set(_state "installpath")
  801. elseif (${arg} STREQUAL "DOCTITLE")
  802. set(_state "doctitle")
  803. elseif (${arg} STREQUAL "WINDOWTITLE")
  804. set(_state "windowtitle")
  805. elseif (${arg} STREQUAL "AUTHOR")
  806. set(_state "author")
  807. elseif (${arg} STREQUAL "USE")
  808. set(_state "use")
  809. elseif (${arg} STREQUAL "VERSION")
  810. set(_state "version")
  811. else ()
  812. list(APPEND _javadoc_packages ${arg})
  813. endif ()
  814. elseif (${_state} STREQUAL "files")
  815. if (${arg} STREQUAL "PACKAGES")
  816. set(_state "packages")
  817. elseif (${arg} STREQUAL "SOURCEPATH")
  818. set(_state "sourcepath")
  819. elseif (${arg} STREQUAL "CLASSPATH")
  820. set(_state "classpath")
  821. elseif (${arg} STREQUAL "INSTALLPATH")
  822. set(_state "installpath")
  823. elseif (${arg} STREQUAL "DOCTITLE")
  824. set(_state "doctitle")
  825. elseif (${arg} STREQUAL "WINDOWTITLE")
  826. set(_state "windowtitle")
  827. elseif (${arg} STREQUAL "AUTHOR")
  828. set(_state "author")
  829. elseif (${arg} STREQUAL "USE")
  830. set(_state "use")
  831. elseif (${arg} STREQUAL "VERSION")
  832. set(_state "version")
  833. else ()
  834. list(APPEND _javadoc_files ${arg})
  835. endif ()
  836. elseif (${_state} STREQUAL "sourcepath")
  837. if (${arg} STREQUAL "PACKAGES")
  838. set(_state "packages")
  839. elseif (${arg} STREQUAL "FILES")
  840. set(_state "files")
  841. elseif (${arg} STREQUAL "CLASSPATH")
  842. set(_state "classpath")
  843. elseif (${arg} STREQUAL "INSTALLPATH")
  844. set(_state "installpath")
  845. elseif (${arg} STREQUAL "DOCTITLE")
  846. set(_state "doctitle")
  847. elseif (${arg} STREQUAL "WINDOWTITLE")
  848. set(_state "windowtitle")
  849. elseif (${arg} STREQUAL "AUTHOR")
  850. set(_state "author")
  851. elseif (${arg} STREQUAL "USE")
  852. set(_state "use")
  853. elseif (${arg} STREQUAL "VERSION")
  854. set(_state "version")
  855. else ()
  856. list(APPEND _javadoc_sourcepath ${arg})
  857. endif ()
  858. elseif (${_state} STREQUAL "classpath")
  859. if (${arg} STREQUAL "PACKAGES")
  860. set(_state "packages")
  861. elseif (${arg} STREQUAL "FILES")
  862. set(_state "files")
  863. elseif (${arg} STREQUAL "SOURCEPATH")
  864. set(_state "sourcepath")
  865. elseif (${arg} STREQUAL "INSTALLPATH")
  866. set(_state "installpath")
  867. elseif (${arg} STREQUAL "DOCTITLE")
  868. set(_state "doctitle")
  869. elseif (${arg} STREQUAL "WINDOWTITLE")
  870. set(_state "windowtitle")
  871. elseif (${arg} STREQUAL "AUTHOR")
  872. set(_state "author")
  873. elseif (${arg} STREQUAL "USE")
  874. set(_state "use")
  875. elseif (${arg} STREQUAL "VERSION")
  876. set(_state "version")
  877. else ()
  878. list(APPEND _javadoc_classpath ${arg})
  879. endif ()
  880. elseif (${_state} STREQUAL "installpath")
  881. if (${arg} STREQUAL "PACKAGES")
  882. set(_state "packages")
  883. elseif (${arg} STREQUAL "FILES")
  884. set(_state "files")
  885. elseif (${arg} STREQUAL "SOURCEPATH")
  886. set(_state "sourcepath")
  887. elseif (${arg} STREQUAL "DOCTITLE")
  888. set(_state "doctitle")
  889. elseif (${arg} STREQUAL "WINDOWTITLE")
  890. set(_state "windowtitle")
  891. elseif (${arg} STREQUAL "AUTHOR")
  892. set(_state "author")
  893. elseif (${arg} STREQUAL "USE")
  894. set(_state "use")
  895. elseif (${arg} STREQUAL "VERSION")
  896. set(_state "version")
  897. else ()
  898. set(_javadoc_installpath ${arg})
  899. endif ()
  900. elseif (${_state} STREQUAL "doctitle")
  901. if (${arg} STREQUAL "PACKAGES")
  902. set(_state "packages")
  903. elseif (${arg} STREQUAL "FILES")
  904. set(_state "files")
  905. elseif (${arg} STREQUAL "SOURCEPATH")
  906. set(_state "sourcepath")
  907. elseif (${arg} STREQUAL "INSTALLPATH")
  908. set(_state "installpath")
  909. elseif (${arg} STREQUAL "CLASSPATH")
  910. set(_state "classpath")
  911. elseif (${arg} STREQUAL "WINDOWTITLE")
  912. set(_state "windowtitle")
  913. elseif (${arg} STREQUAL "AUTHOR")
  914. set(_state "author")
  915. elseif (${arg} STREQUAL "USE")
  916. set(_state "use")
  917. elseif (${arg} STREQUAL "VERSION")
  918. set(_state "version")
  919. else ()
  920. set(_javadoc_doctitle ${arg})
  921. endif ()
  922. elseif (${_state} STREQUAL "windowtitle")
  923. if (${arg} STREQUAL "PACKAGES")
  924. set(_state "packages")
  925. elseif (${arg} STREQUAL "FILES")
  926. set(_state "files")
  927. elseif (${arg} STREQUAL "SOURCEPATH")
  928. set(_state "sourcepath")
  929. elseif (${arg} STREQUAL "CLASSPATH")
  930. set(_state "classpath")
  931. elseif (${arg} STREQUAL "INSTALLPATH")
  932. set(_state "installpath")
  933. elseif (${arg} STREQUAL "DOCTITLE")
  934. set(_state "doctitle")
  935. elseif (${arg} STREQUAL "AUTHOR")
  936. set(_state "author")
  937. elseif (${arg} STREQUAL "USE")
  938. set(_state "use")
  939. elseif (${arg} STREQUAL "VERSION")
  940. set(_state "version")
  941. else ()
  942. set(_javadoc_windowtitle ${arg})
  943. endif ()
  944. elseif (${_state} STREQUAL "author")
  945. if (${arg} STREQUAL "PACKAGES")
  946. set(_state "packages")
  947. elseif (${arg} STREQUAL "FILES")
  948. set(_state "files")
  949. elseif (${arg} STREQUAL "SOURCEPATH")
  950. set(_state "sourcepath")
  951. elseif (${arg} STREQUAL "CLASSPATH")
  952. set(_state "classpath")
  953. elseif (${arg} STREQUAL "INSTALLPATH")
  954. set(_state "installpath")
  955. elseif (${arg} STREQUAL "DOCTITLE")
  956. set(_state "doctitle")
  957. elseif (${arg} STREQUAL "WINDOWTITLE")
  958. set(_state "windowtitle")
  959. elseif (${arg} STREQUAL "AUTHOR")
  960. set(_state "author")
  961. elseif (${arg} STREQUAL "USE")
  962. set(_state "use")
  963. elseif (${arg} STREQUAL "VERSION")
  964. set(_state "version")
  965. else ()
  966. set(_javadoc_author ${arg})
  967. endif ()
  968. elseif (${_state} STREQUAL "use")
  969. if (${arg} STREQUAL "PACKAGES")
  970. set(_state "packages")
  971. elseif (${arg} STREQUAL "FILES")
  972. set(_state "files")
  973. elseif (${arg} STREQUAL "SOURCEPATH")
  974. set(_state "sourcepath")
  975. elseif (${arg} STREQUAL "CLASSPATH")
  976. set(_state "classpath")
  977. elseif (${arg} STREQUAL "INSTALLPATH")
  978. set(_state "installpath")
  979. elseif (${arg} STREQUAL "DOCTITLE")
  980. set(_state "doctitle")
  981. elseif (${arg} STREQUAL "WINDOWTITLE")
  982. set(_state "windowtitle")
  983. elseif (${arg} STREQUAL "AUTHOR")
  984. set(_state "author")
  985. elseif (${arg} STREQUAL "USE")
  986. set(_state "use")
  987. elseif (${arg} STREQUAL "VERSION")
  988. set(_state "version")
  989. else ()
  990. set(_javadoc_use ${arg})
  991. endif ()
  992. elseif (${_state} STREQUAL "version")
  993. if (${arg} STREQUAL "PACKAGES")
  994. set(_state "packages")
  995. elseif (${arg} STREQUAL "FILES")
  996. set(_state "files")
  997. elseif (${arg} STREQUAL "SOURCEPATH")
  998. set(_state "sourcepath")
  999. elseif (${arg} STREQUAL "CLASSPATH")
  1000. set(_state "classpath")
  1001. elseif (${arg} STREQUAL "INSTALLPATH")
  1002. set(_state "installpath")
  1003. elseif (${arg} STREQUAL "DOCTITLE")
  1004. set(_state "doctitle")
  1005. elseif (${arg} STREQUAL "WINDOWTITLE")
  1006. set(_state "windowtitle")
  1007. elseif (${arg} STREQUAL "AUTHOR")
  1008. set(_state "author")
  1009. elseif (${arg} STREQUAL "USE")
  1010. set(_state "use")
  1011. elseif (${arg} STREQUAL "VERSION")
  1012. set(_state "version")
  1013. else ()
  1014. set(_javadoc_version ${arg})
  1015. endif ()
  1016. endif ()
  1017. endforeach ()
  1018. set(_javadoc_builddir ${CMAKE_CURRENT_BINARY_DIR}/javadoc/${_target})
  1019. set(_javadoc_options -d ${_javadoc_builddir})
  1020. if (_javadoc_sourcepath)
  1021. set(_start TRUE)
  1022. foreach(_path ${_javadoc_sourcepath})
  1023. if (_start)
  1024. set(_sourcepath ${_path})
  1025. set(_start FALSE)
  1026. else ()
  1027. set(_sourcepath ${_sourcepath}:${_path})
  1028. endif ()
  1029. endforeach()
  1030. set(_javadoc_options ${_javadoc_options} -sourcepath ${_sourcepath})
  1031. endif ()
  1032. if (_javadoc_classpath)
  1033. set(_start TRUE)
  1034. foreach(_path ${_javadoc_classpath})
  1035. if (_start)
  1036. set(_classpath ${_path})
  1037. set(_start FALSE)
  1038. else ()
  1039. set(_classpath ${_classpath}:${_path})
  1040. endif ()
  1041. endforeach()
  1042. set(_javadoc_options ${_javadoc_options} -classpath "${_classpath}")
  1043. endif ()
  1044. if (_javadoc_doctitle)
  1045. set(_javadoc_options ${_javadoc_options} -doctitle '${_javadoc_doctitle}')
  1046. endif ()
  1047. if (_javadoc_windowtitle)
  1048. set(_javadoc_options ${_javadoc_options} -windowtitle '${_javadoc_windowtitle}')
  1049. endif ()
  1050. if (_javadoc_author)
  1051. set(_javadoc_options ${_javadoc_options} -author)
  1052. endif ()
  1053. if (_javadoc_use)
  1054. set(_javadoc_options ${_javadoc_options} -use)
  1055. endif ()
  1056. if (_javadoc_version)
  1057. set(_javadoc_options ${_javadoc_options} -version)
  1058. endif ()
  1059. add_custom_target(${_target}_javadoc ALL
  1060. COMMAND ${Java_JAVADOC_EXECUTABLE} ${_javadoc_options}
  1061. ${_javadoc_files}
  1062. ${_javadoc_packages}
  1063. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  1064. )
  1065. install(
  1066. DIRECTORY ${_javadoc_builddir}
  1067. DESTINATION ${_javadoc_installpath}
  1068. )
  1069. endfunction()