1
0

UseJava.cmake 37 KB

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