UseJava.cmake 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  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. # ::
  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. # ::
  314. #
  315. # create_javah(TARGET <target>
  316. # GENERATED_FILES <VAR>
  317. # CLASSES <class>...
  318. # [CLASSPATH <classpath>...]
  319. # [DEPENDS <depend>...]
  320. # [OUTPUT_NAME <path>|OUTPUT_DIR <path>]
  321. # )
  322. #
  323. # Create C header files from java classes. These files provide the connective glue
  324. # that allow your Java and C code to interact.
  325. #
  326. # There are two main signatures for create_javah. The first signature
  327. # returns generated files through variable specified by GENERATED_FILES option:
  328. #
  329. # ::
  330. #
  331. # Example:
  332. # Create_javah(GENERATED_FILES files_headers
  333. # CLASSES org.cmake.HelloWorld
  334. # CLASSPATH hello.jar
  335. # )
  336. #
  337. #
  338. #
  339. # The second signature for create_javah creates a target which encapsulates
  340. # header files generation.
  341. #
  342. # ::
  343. #
  344. # Example:
  345. # Create_javah(TARGET target_headers
  346. # CLASSES org.cmake.HelloWorld
  347. # CLASSPATH hello.jar
  348. # )
  349. #
  350. #
  351. #
  352. # Both signatures share same options.
  353. #
  354. # ``CLASSES <class>...``
  355. # Specifies Java classes used to generate headers.
  356. #
  357. # ``CLASSPATH <classpath>...``
  358. # Specifies various paths to look up classes. Here .class files, jar files or targets
  359. # created by command add_jar can be used.
  360. #
  361. # ``DEPENDS <depend>...``
  362. # Targets on which the javah target depends
  363. #
  364. # ``OUTPUT_NAME <path>``
  365. # Concatenates the resulting header files for all the classes listed by option CLASSES
  366. # into <path>. Same behavior as option '-o' of javah tool.
  367. #
  368. # ``OUTPUT_DIR <path>``
  369. # Sets the directory where the header files will be generated. Same behavior as option
  370. # '-d' of javah tool. If not specified, ${CMAKE_CURRENT_BINARY_DIR} is used as output directory.
  371. #=============================================================================
  372. # Copyright 2013 OpenGamma Ltd. <graham@opengamma.com>
  373. # Copyright 2010-2011 Andreas schneider <asn@redhat.com>
  374. # Copyright 2010-2013 Kitware, Inc.
  375. #
  376. # Distributed under the OSI-approved BSD License (the "License");
  377. # see accompanying file Copyright.txt for details.
  378. #
  379. # This software is distributed WITHOUT ANY WARRANTY; without even the
  380. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  381. # See the License for more information.
  382. #=============================================================================
  383. # (To distribute this file outside of CMake, substitute the full
  384. # License text for the above reference.)
  385. include(${CMAKE_CURRENT_LIST_DIR}/CMakeParseArguments.cmake)
  386. function (__java_copy_file src dest comment)
  387. add_custom_command(
  388. OUTPUT ${dest}
  389. COMMAND ${CMAKE_COMMAND} -E copy_if_different
  390. ARGS ${src}
  391. ${dest}
  392. DEPENDS ${src}
  393. COMMENT ${comment})
  394. endfunction ()
  395. # define helper scripts
  396. set(_JAVA_CLASS_FILELIST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaClassFilelist.cmake)
  397. set(_JAVA_SYMLINK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaSymlinks.cmake)
  398. function(add_jar _TARGET_NAME)
  399. cmake_parse_arguments(_add_jar
  400. ""
  401. "VERSION;OUTPUT_DIR;OUTPUT_NAME;ENTRY_POINT;MANIFEST"
  402. "SOURCES;INCLUDE_JARS"
  403. ${ARGN}
  404. )
  405. # In CMake < 2.8.12, add_jar used variables which were set prior to calling
  406. # add_jar for customizing the behavior of add_jar. In order to be backwards
  407. # compatible, check if any of those variables are set, and use them to
  408. # initialize values of the named arguments. (Giving the corresponding named
  409. # argument will override the value set here.)
  410. #
  411. # New features should use named arguments only.
  412. if(NOT DEFINED _add_jar_VERSION AND DEFINED CMAKE_JAVA_TARGET_VERSION)
  413. set(_add_jar_VERSION "${CMAKE_JAVA_TARGET_VERSION}")
  414. endif()
  415. if(NOT DEFINED _add_jar_OUTPUT_DIR AND DEFINED CMAKE_JAVA_TARGET_OUTPUT_DIR)
  416. set(_add_jar_OUTPUT_DIR "${CMAKE_JAVA_TARGET_OUTPUT_DIR}")
  417. endif()
  418. if(NOT DEFINED _add_jar_OUTPUT_NAME AND DEFINED CMAKE_JAVA_TARGET_OUTPUT_NAME)
  419. set(_add_jar_OUTPUT_NAME "${CMAKE_JAVA_TARGET_OUTPUT_NAME}")
  420. # reset
  421. set(CMAKE_JAVA_TARGET_OUTPUT_NAME)
  422. endif()
  423. if(NOT DEFINED _add_jar_ENTRY_POINT AND DEFINED CMAKE_JAVA_JAR_ENTRY_POINT)
  424. set(_add_jar_ENTRY_POINT "${CMAKE_JAVA_JAR_ENTRY_POINT}")
  425. endif()
  426. set(_JAVA_SOURCE_FILES ${_add_jar_SOURCES} ${_add_jar_UNPARSED_ARGUMENTS})
  427. if (NOT DEFINED _add_jar_OUTPUT_DIR)
  428. set(_add_jar_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
  429. endif()
  430. if (_add_jar_ENTRY_POINT)
  431. set(_ENTRY_POINT_OPTION e)
  432. set(_ENTRY_POINT_VALUE ${_add_jar_ENTRY_POINT})
  433. endif ()
  434. if (_add_jar_MANIFEST)
  435. set(_MANIFEST_OPTION m)
  436. get_filename_component (_MANIFEST_VALUE "${_add_jar_MANIFEST}" ABSOLUTE)
  437. endif ()
  438. if (LIBRARY_OUTPUT_PATH)
  439. set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH})
  440. else ()
  441. set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${_add_jar_OUTPUT_DIR})
  442. endif ()
  443. set(CMAKE_JAVA_INCLUDE_PATH
  444. ${CMAKE_JAVA_INCLUDE_PATH}
  445. ${CMAKE_CURRENT_SOURCE_DIR}
  446. ${CMAKE_JAVA_OBJECT_OUTPUT_PATH}
  447. ${CMAKE_JAVA_LIBRARY_OUTPUT_PATH}
  448. )
  449. if (CMAKE_HOST_WIN32 AND NOT CYGWIN AND CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
  450. set(CMAKE_JAVA_INCLUDE_FLAG_SEP ";")
  451. else ()
  452. set(CMAKE_JAVA_INCLUDE_FLAG_SEP ":")
  453. endif()
  454. foreach (JAVA_INCLUDE_DIR ${CMAKE_JAVA_INCLUDE_PATH})
  455. set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${JAVA_INCLUDE_DIR}")
  456. endforeach()
  457. set(CMAKE_JAVA_CLASS_OUTPUT_PATH "${_add_jar_OUTPUT_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir")
  458. set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}.jar")
  459. if (_add_jar_OUTPUT_NAME AND _add_jar_VERSION)
  460. set(_JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}-${_add_jar_VERSION}.jar")
  461. set(_JAVA_TARGET_OUTPUT_LINK "${_add_jar_OUTPUT_NAME}.jar")
  462. elseif (_add_jar_VERSION)
  463. set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}-${_add_jar_VERSION}.jar")
  464. set(_JAVA_TARGET_OUTPUT_LINK "${_TARGET_NAME}.jar")
  465. elseif (_add_jar_OUTPUT_NAME)
  466. set(_JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}.jar")
  467. endif ()
  468. set(_JAVA_CLASS_FILES)
  469. set(_JAVA_COMPILE_FILES)
  470. set(_JAVA_COMPILE_FILELISTS)
  471. set(_JAVA_DEPENDS)
  472. set(_JAVA_COMPILE_DEPENDS)
  473. set(_JAVA_RESOURCE_FILES)
  474. set(_JAVA_RESOURCE_FILES_RELATIVE)
  475. foreach(_JAVA_SOURCE_FILE ${_JAVA_SOURCE_FILES})
  476. get_filename_component(_JAVA_EXT ${_JAVA_SOURCE_FILE} EXT)
  477. get_filename_component(_JAVA_FILE ${_JAVA_SOURCE_FILE} NAME_WE)
  478. get_filename_component(_JAVA_PATH ${_JAVA_SOURCE_FILE} PATH)
  479. get_filename_component(_JAVA_FULL ${_JAVA_SOURCE_FILE} ABSOLUTE)
  480. if (_JAVA_SOURCE_FILE MATCHES "^@(.+)$")
  481. get_filename_component(_JAVA_FULL ${CMAKE_MATCH_1} ABSOLUTE)
  482. list(APPEND _JAVA_COMPILE_FILELISTS ${_JAVA_FULL})
  483. elseif (_JAVA_EXT MATCHES ".java")
  484. file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${_add_jar_OUTPUT_DIR} ${_JAVA_FULL})
  485. file(RELATIVE_PATH _JAVA_REL_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${_JAVA_FULL})
  486. string(LENGTH ${_JAVA_REL_BINARY_PATH} _BIN_LEN)
  487. string(LENGTH ${_JAVA_REL_SOURCE_PATH} _SRC_LEN)
  488. if (${_BIN_LEN} LESS ${_SRC_LEN})
  489. set(_JAVA_REL_PATH ${_JAVA_REL_BINARY_PATH})
  490. else ()
  491. set(_JAVA_REL_PATH ${_JAVA_REL_SOURCE_PATH})
  492. endif ()
  493. get_filename_component(_JAVA_REL_PATH ${_JAVA_REL_PATH} PATH)
  494. list(APPEND _JAVA_COMPILE_FILES ${_JAVA_SOURCE_FILE})
  495. set(_JAVA_CLASS_FILE "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_REL_PATH}/${_JAVA_FILE}.class")
  496. set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES} ${_JAVA_CLASS_FILE})
  497. elseif (_JAVA_EXT MATCHES ".jar"
  498. OR _JAVA_EXT MATCHES ".war"
  499. OR _JAVA_EXT MATCHES ".ear"
  500. OR _JAVA_EXT MATCHES ".sar")
  501. # Ignored for backward compatibility
  502. elseif (_JAVA_EXT STREQUAL "")
  503. list(APPEND CMAKE_JAVA_INCLUDE_PATH ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}} ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}_CLASSPATH})
  504. list(APPEND _JAVA_DEPENDS ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}})
  505. else ()
  506. __java_copy_file(${CMAKE_CURRENT_SOURCE_DIR}/${_JAVA_SOURCE_FILE}
  507. ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE}
  508. "Copying ${_JAVA_SOURCE_FILE} to the build directory")
  509. list(APPEND _JAVA_RESOURCE_FILES ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE})
  510. list(APPEND _JAVA_RESOURCE_FILES_RELATIVE ${_JAVA_SOURCE_FILE})
  511. endif ()
  512. endforeach()
  513. foreach(_JAVA_INCLUDE_JAR ${_add_jar_INCLUDE_JARS})
  514. if (TARGET ${_JAVA_INCLUDE_JAR})
  515. get_target_property(_JAVA_JAR_PATH ${_JAVA_INCLUDE_JAR} JAR_FILE)
  516. if (_JAVA_JAR_PATH)
  517. set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_JAR_PATH}")
  518. list(APPEND CMAKE_JAVA_INCLUDE_PATH ${_JAVA_JAR_PATH})
  519. list(APPEND _JAVA_DEPENDS ${_JAVA_INCLUDE_JAR})
  520. list(APPEND _JAVA_COMPILE_DEPENDS ${_JAVA_INCLUDE_JAR})
  521. else ()
  522. message(SEND_ERROR "add_jar: INCLUDE_JARS target ${_JAVA_INCLUDE_JAR} is not a jar")
  523. endif ()
  524. else ()
  525. set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_INCLUDE_JAR}")
  526. list(APPEND CMAKE_JAVA_INCLUDE_PATH "${_JAVA_INCLUDE_JAR}")
  527. list(APPEND _JAVA_DEPENDS "${_JAVA_INCLUDE_JAR}")
  528. list(APPEND _JAVA_COMPILE_DEPENDS "${_JAVA_INCLUDE_JAR}")
  529. endif ()
  530. endforeach()
  531. # create an empty java_class_filelist
  532. if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist)
  533. file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "")
  534. endif()
  535. if (_JAVA_COMPILE_FILES OR _JAVA_COMPILE_FILELISTS)
  536. set (_JAVA_SOURCES_FILELISTS)
  537. if (_JAVA_COMPILE_FILES)
  538. # Create the list of files to compile.
  539. set(_JAVA_SOURCES_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_sources)
  540. string(REPLACE ";" "\"\n\"" _JAVA_COMPILE_STRING "\"${_JAVA_COMPILE_FILES}\"")
  541. file(WRITE ${_JAVA_SOURCES_FILE} ${_JAVA_COMPILE_STRING})
  542. list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_SOURCES_FILE}")
  543. endif()
  544. if (_JAVA_COMPILE_FILELISTS)
  545. foreach (_JAVA_FILELIST IN LISTS _JAVA_COMPILE_FILELISTS)
  546. list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_FILELIST}")
  547. endforeach()
  548. endif()
  549. # Compile the java files and create a list of class files
  550. add_custom_command(
  551. # NOTE: this command generates an artificial dependency file
  552. OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
  553. COMMAND ${Java_JAVAC_EXECUTABLE}
  554. ${CMAKE_JAVA_COMPILE_FLAGS}
  555. -classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}"
  556. -d ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  557. ${_JAVA_SOURCES_FILELISTS}
  558. COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
  559. DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_FILELISTS} ${_JAVA_COMPILE_DEPENDS}
  560. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  561. COMMENT "Building Java objects for ${_TARGET_NAME}.jar"
  562. )
  563. add_custom_command(
  564. OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
  565. COMMAND ${CMAKE_COMMAND}
  566. -DCMAKE_JAVA_CLASS_OUTPUT_PATH=${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  567. -DCMAKE_JAR_CLASSES_PREFIX="${CMAKE_JAR_CLASSES_PREFIX}"
  568. -P ${_JAVA_CLASS_FILELIST_SCRIPT}
  569. DEPENDS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
  570. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  571. )
  572. endif ()
  573. # create the jar file
  574. set(_JAVA_JAR_OUTPUT_PATH
  575. ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_NAME})
  576. if (CMAKE_JNI_TARGET)
  577. add_custom_command(
  578. OUTPUT ${_JAVA_JAR_OUTPUT_PATH}
  579. COMMAND ${Java_JAR_EXECUTABLE}
  580. -cf${_ENTRY_POINT_OPTION}${_MANIFEST_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_MANIFEST_VALUE}
  581. ${_JAVA_RESOURCE_FILES_RELATIVE} @java_class_filelist
  582. COMMAND ${CMAKE_COMMAND}
  583. -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
  584. -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME}
  585. -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
  586. -P ${_JAVA_SYMLINK_SCRIPT}
  587. COMMAND ${CMAKE_COMMAND}
  588. -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
  589. -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_JAR_OUTPUT_PATH}
  590. -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
  591. -P ${_JAVA_SYMLINK_SCRIPT}
  592. DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
  593. WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  594. COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}"
  595. )
  596. else ()
  597. add_custom_command(
  598. OUTPUT ${_JAVA_JAR_OUTPUT_PATH}
  599. COMMAND ${Java_JAR_EXECUTABLE}
  600. -cf${_ENTRY_POINT_OPTION}${_MANIFEST_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_MANIFEST_VALUE}
  601. ${_JAVA_RESOURCE_FILES_RELATIVE} @java_class_filelist
  602. COMMAND ${CMAKE_COMMAND}
  603. -D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
  604. -D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME}
  605. -D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
  606. -P ${_JAVA_SYMLINK_SCRIPT}
  607. WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  608. DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
  609. COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}"
  610. )
  611. endif ()
  612. # Add the target and make sure we have the latest resource files.
  613. add_custom_target(${_TARGET_NAME} ALL DEPENDS ${_JAVA_JAR_OUTPUT_PATH})
  614. set_property(
  615. TARGET
  616. ${_TARGET_NAME}
  617. PROPERTY
  618. INSTALL_FILES
  619. ${_JAVA_JAR_OUTPUT_PATH}
  620. )
  621. if (_JAVA_TARGET_OUTPUT_LINK)
  622. set_property(
  623. TARGET
  624. ${_TARGET_NAME}
  625. PROPERTY
  626. INSTALL_FILES
  627. ${_JAVA_JAR_OUTPUT_PATH}
  628. ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK}
  629. )
  630. if (CMAKE_JNI_TARGET)
  631. set_property(
  632. TARGET
  633. ${_TARGET_NAME}
  634. PROPERTY
  635. JNI_SYMLINK
  636. ${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK}
  637. )
  638. endif ()
  639. endif ()
  640. set_property(
  641. TARGET
  642. ${_TARGET_NAME}
  643. PROPERTY
  644. JAR_FILE
  645. ${_JAVA_JAR_OUTPUT_PATH}
  646. )
  647. set_property(
  648. TARGET
  649. ${_TARGET_NAME}
  650. PROPERTY
  651. CLASSDIR
  652. ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
  653. )
  654. endfunction()
  655. function(INSTALL_JAR _TARGET_NAME)
  656. if (ARGC EQUAL 2)
  657. set (_DESTINATION ${ARGV1})
  658. else()
  659. cmake_parse_arguments(_install_jar
  660. ""
  661. "DESTINATION;COMPONENT"
  662. ""
  663. ${ARGN})
  664. if (_install_jar_DESTINATION)
  665. set (_DESTINATION ${_install_jar_DESTINATION})
  666. else()
  667. message(SEND_ERROR "install_jar: ${_TARGET_NAME}: DESTINATION must be specified.")
  668. endif()
  669. if (_install_jar_COMPONENT)
  670. set (_COMPONENT COMPONENT ${_install_jar_COMPONENT})
  671. endif()
  672. endif()
  673. get_property(__FILES
  674. TARGET
  675. ${_TARGET_NAME}
  676. PROPERTY
  677. INSTALL_FILES
  678. )
  679. if (__FILES)
  680. install(
  681. FILES
  682. ${__FILES}
  683. DESTINATION
  684. ${_DESTINATION}
  685. ${_COMPONENT}
  686. )
  687. else ()
  688. message(SEND_ERROR "install_jar: The target ${_TARGET_NAME} is not known in this scope.")
  689. endif ()
  690. endfunction()
  691. function(INSTALL_JNI_SYMLINK _TARGET_NAME)
  692. if (ARGC EQUAL 2)
  693. set (_DESTINATION ${ARGV1})
  694. else()
  695. cmake_parse_arguments(_install_jni_symlink
  696. ""
  697. "DESTINATION;COMPONENT"
  698. ""
  699. ${ARGN})
  700. if (_install_jni_symlink_DESTINATION)
  701. set (_DESTINATION ${_install_jni_symlink_DESTINATION})
  702. else()
  703. message(SEND_ERROR "install_jni_symlink: ${_TARGET_NAME}: DESTINATION must be specified.")
  704. endif()
  705. if (_install_jni_symlink_COMPONENT)
  706. set (_COMPONENT COMPONENT ${_install_jni_symlink_COMPONENT})
  707. endif()
  708. endif()
  709. get_property(__SYMLINK
  710. TARGET
  711. ${_TARGET_NAME}
  712. PROPERTY
  713. JNI_SYMLINK
  714. )
  715. if (__SYMLINK)
  716. install(
  717. FILES
  718. ${__SYMLINK}
  719. DESTINATION
  720. ${_DESTINATION}
  721. ${_COMPONENT}
  722. )
  723. else ()
  724. message(SEND_ERROR "install_jni_symlink: The target ${_TARGET_NAME} is not known in this scope.")
  725. endif ()
  726. endfunction()
  727. function (find_jar VARIABLE)
  728. set(_jar_names)
  729. set(_jar_files)
  730. set(_jar_versions)
  731. set(_jar_paths
  732. /usr/share/java/
  733. /usr/local/share/java/
  734. ${Java_JAR_PATHS})
  735. set(_jar_doc "NOTSET")
  736. set(_state "name")
  737. foreach (arg ${ARGN})
  738. if (${_state} STREQUAL "name")
  739. if (${arg} STREQUAL "VERSIONS")
  740. set(_state "versions")
  741. elseif (${arg} STREQUAL "NAMES")
  742. set(_state "names")
  743. elseif (${arg} STREQUAL "PATHS")
  744. set(_state "paths")
  745. elseif (${arg} STREQUAL "DOC")
  746. set(_state "doc")
  747. else ()
  748. set(_jar_names ${arg})
  749. if (_jar_doc STREQUAL "NOTSET")
  750. set(_jar_doc "Finding ${arg} jar")
  751. endif ()
  752. endif ()
  753. elseif (${_state} STREQUAL "versions")
  754. if (${arg} STREQUAL "NAMES")
  755. set(_state "names")
  756. elseif (${arg} STREQUAL "PATHS")
  757. set(_state "paths")
  758. elseif (${arg} STREQUAL "DOC")
  759. set(_state "doc")
  760. else ()
  761. set(_jar_versions ${_jar_versions} ${arg})
  762. endif ()
  763. elseif (${_state} STREQUAL "names")
  764. if (${arg} STREQUAL "VERSIONS")
  765. set(_state "versions")
  766. elseif (${arg} STREQUAL "PATHS")
  767. set(_state "paths")
  768. elseif (${arg} STREQUAL "DOC")
  769. set(_state "doc")
  770. else ()
  771. set(_jar_names ${_jar_names} ${arg})
  772. if (_jar_doc STREQUAL "NOTSET")
  773. set(_jar_doc "Finding ${arg} jar")
  774. endif ()
  775. endif ()
  776. elseif (${_state} STREQUAL "paths")
  777. if (${arg} STREQUAL "VERSIONS")
  778. set(_state "versions")
  779. elseif (${arg} STREQUAL "NAMES")
  780. set(_state "names")
  781. elseif (${arg} STREQUAL "DOC")
  782. set(_state "doc")
  783. else ()
  784. set(_jar_paths ${_jar_paths} ${arg})
  785. endif ()
  786. elseif (${_state} STREQUAL "doc")
  787. if (${arg} STREQUAL "VERSIONS")
  788. set(_state "versions")
  789. elseif (${arg} STREQUAL "NAMES")
  790. set(_state "names")
  791. elseif (${arg} STREQUAL "PATHS")
  792. set(_state "paths")
  793. else ()
  794. set(_jar_doc ${arg})
  795. endif ()
  796. endif ()
  797. endforeach ()
  798. if (NOT _jar_names)
  799. message(FATAL_ERROR "find_jar: No name to search for given")
  800. endif ()
  801. foreach (jar_name ${_jar_names})
  802. foreach (version ${_jar_versions})
  803. set(_jar_files ${_jar_files} ${jar_name}-${version}.jar)
  804. endforeach ()
  805. set(_jar_files ${_jar_files} ${jar_name}.jar)
  806. endforeach ()
  807. find_file(${VARIABLE}
  808. NAMES ${_jar_files}
  809. PATHS ${_jar_paths}
  810. DOC ${_jar_doc}
  811. NO_DEFAULT_PATH)
  812. endfunction ()
  813. function(create_javadoc _target)
  814. set(_javadoc_packages)
  815. set(_javadoc_files)
  816. set(_javadoc_sourcepath)
  817. set(_javadoc_classpath)
  818. set(_javadoc_installpath "${CMAKE_INSTALL_PREFIX}/share/javadoc")
  819. set(_javadoc_doctitle)
  820. set(_javadoc_windowtitle)
  821. set(_javadoc_author FALSE)
  822. set(_javadoc_version FALSE)
  823. set(_javadoc_use FALSE)
  824. set(_state "package")
  825. foreach (arg ${ARGN})
  826. if (${_state} STREQUAL "package")
  827. if (${arg} STREQUAL "PACKAGES")
  828. set(_state "packages")
  829. elseif (${arg} STREQUAL "FILES")
  830. set(_state "files")
  831. elseif (${arg} STREQUAL "SOURCEPATH")
  832. set(_state "sourcepath")
  833. elseif (${arg} STREQUAL "CLASSPATH")
  834. set(_state "classpath")
  835. elseif (${arg} STREQUAL "INSTALLPATH")
  836. set(_state "installpath")
  837. elseif (${arg} STREQUAL "DOCTITLE")
  838. set(_state "doctitle")
  839. elseif (${arg} STREQUAL "WINDOWTITLE")
  840. set(_state "windowtitle")
  841. elseif (${arg} STREQUAL "AUTHOR")
  842. set(_state "author")
  843. elseif (${arg} STREQUAL "USE")
  844. set(_state "use")
  845. elseif (${arg} STREQUAL "VERSION")
  846. set(_state "version")
  847. else ()
  848. set(_javadoc_packages ${arg})
  849. set(_state "packages")
  850. endif ()
  851. elseif (${_state} STREQUAL "packages")
  852. if (${arg} STREQUAL "FILES")
  853. set(_state "files")
  854. elseif (${arg} STREQUAL "SOURCEPATH")
  855. set(_state "sourcepath")
  856. elseif (${arg} STREQUAL "CLASSPATH")
  857. set(_state "classpath")
  858. elseif (${arg} STREQUAL "INSTALLPATH")
  859. set(_state "installpath")
  860. elseif (${arg} STREQUAL "DOCTITLE")
  861. set(_state "doctitle")
  862. elseif (${arg} STREQUAL "WINDOWTITLE")
  863. set(_state "windowtitle")
  864. elseif (${arg} STREQUAL "AUTHOR")
  865. set(_state "author")
  866. elseif (${arg} STREQUAL "USE")
  867. set(_state "use")
  868. elseif (${arg} STREQUAL "VERSION")
  869. set(_state "version")
  870. else ()
  871. list(APPEND _javadoc_packages ${arg})
  872. endif ()
  873. elseif (${_state} STREQUAL "files")
  874. if (${arg} STREQUAL "PACKAGES")
  875. set(_state "packages")
  876. elseif (${arg} STREQUAL "SOURCEPATH")
  877. set(_state "sourcepath")
  878. elseif (${arg} STREQUAL "CLASSPATH")
  879. set(_state "classpath")
  880. elseif (${arg} STREQUAL "INSTALLPATH")
  881. set(_state "installpath")
  882. elseif (${arg} STREQUAL "DOCTITLE")
  883. set(_state "doctitle")
  884. elseif (${arg} STREQUAL "WINDOWTITLE")
  885. set(_state "windowtitle")
  886. elseif (${arg} STREQUAL "AUTHOR")
  887. set(_state "author")
  888. elseif (${arg} STREQUAL "USE")
  889. set(_state "use")
  890. elseif (${arg} STREQUAL "VERSION")
  891. set(_state "version")
  892. else ()
  893. list(APPEND _javadoc_files ${arg})
  894. endif ()
  895. elseif (${_state} STREQUAL "sourcepath")
  896. if (${arg} STREQUAL "PACKAGES")
  897. set(_state "packages")
  898. elseif (${arg} STREQUAL "FILES")
  899. set(_state "files")
  900. elseif (${arg} STREQUAL "CLASSPATH")
  901. set(_state "classpath")
  902. elseif (${arg} STREQUAL "INSTALLPATH")
  903. set(_state "installpath")
  904. elseif (${arg} STREQUAL "DOCTITLE")
  905. set(_state "doctitle")
  906. elseif (${arg} STREQUAL "WINDOWTITLE")
  907. set(_state "windowtitle")
  908. elseif (${arg} STREQUAL "AUTHOR")
  909. set(_state "author")
  910. elseif (${arg} STREQUAL "USE")
  911. set(_state "use")
  912. elseif (${arg} STREQUAL "VERSION")
  913. set(_state "version")
  914. else ()
  915. list(APPEND _javadoc_sourcepath ${arg})
  916. endif ()
  917. elseif (${_state} STREQUAL "classpath")
  918. if (${arg} STREQUAL "PACKAGES")
  919. set(_state "packages")
  920. elseif (${arg} STREQUAL "FILES")
  921. set(_state "files")
  922. elseif (${arg} STREQUAL "SOURCEPATH")
  923. set(_state "sourcepath")
  924. elseif (${arg} STREQUAL "INSTALLPATH")
  925. set(_state "installpath")
  926. elseif (${arg} STREQUAL "DOCTITLE")
  927. set(_state "doctitle")
  928. elseif (${arg} STREQUAL "WINDOWTITLE")
  929. set(_state "windowtitle")
  930. elseif (${arg} STREQUAL "AUTHOR")
  931. set(_state "author")
  932. elseif (${arg} STREQUAL "USE")
  933. set(_state "use")
  934. elseif (${arg} STREQUAL "VERSION")
  935. set(_state "version")
  936. else ()
  937. list(APPEND _javadoc_classpath ${arg})
  938. endif ()
  939. elseif (${_state} STREQUAL "installpath")
  940. if (${arg} STREQUAL "PACKAGES")
  941. set(_state "packages")
  942. elseif (${arg} STREQUAL "FILES")
  943. set(_state "files")
  944. elseif (${arg} STREQUAL "SOURCEPATH")
  945. set(_state "sourcepath")
  946. elseif (${arg} STREQUAL "DOCTITLE")
  947. set(_state "doctitle")
  948. elseif (${arg} STREQUAL "WINDOWTITLE")
  949. set(_state "windowtitle")
  950. elseif (${arg} STREQUAL "AUTHOR")
  951. set(_state "author")
  952. elseif (${arg} STREQUAL "USE")
  953. set(_state "use")
  954. elseif (${arg} STREQUAL "VERSION")
  955. set(_state "version")
  956. else ()
  957. set(_javadoc_installpath ${arg})
  958. endif ()
  959. elseif (${_state} STREQUAL "doctitle")
  960. if (${arg} STREQUAL "PACKAGES")
  961. set(_state "packages")
  962. elseif (${arg} STREQUAL "FILES")
  963. set(_state "files")
  964. elseif (${arg} STREQUAL "SOURCEPATH")
  965. set(_state "sourcepath")
  966. elseif (${arg} STREQUAL "INSTALLPATH")
  967. set(_state "installpath")
  968. elseif (${arg} STREQUAL "CLASSPATH")
  969. set(_state "classpath")
  970. elseif (${arg} STREQUAL "WINDOWTITLE")
  971. set(_state "windowtitle")
  972. elseif (${arg} STREQUAL "AUTHOR")
  973. set(_state "author")
  974. elseif (${arg} STREQUAL "USE")
  975. set(_state "use")
  976. elseif (${arg} STREQUAL "VERSION")
  977. set(_state "version")
  978. else ()
  979. set(_javadoc_doctitle ${arg})
  980. endif ()
  981. elseif (${_state} STREQUAL "windowtitle")
  982. if (${arg} STREQUAL "PACKAGES")
  983. set(_state "packages")
  984. elseif (${arg} STREQUAL "FILES")
  985. set(_state "files")
  986. elseif (${arg} STREQUAL "SOURCEPATH")
  987. set(_state "sourcepath")
  988. elseif (${arg} STREQUAL "CLASSPATH")
  989. set(_state "classpath")
  990. elseif (${arg} STREQUAL "INSTALLPATH")
  991. set(_state "installpath")
  992. elseif (${arg} STREQUAL "DOCTITLE")
  993. set(_state "doctitle")
  994. elseif (${arg} STREQUAL "AUTHOR")
  995. set(_state "author")
  996. elseif (${arg} STREQUAL "USE")
  997. set(_state "use")
  998. elseif (${arg} STREQUAL "VERSION")
  999. set(_state "version")
  1000. else ()
  1001. set(_javadoc_windowtitle ${arg})
  1002. endif ()
  1003. elseif (${_state} STREQUAL "author")
  1004. if (${arg} STREQUAL "PACKAGES")
  1005. set(_state "packages")
  1006. elseif (${arg} STREQUAL "FILES")
  1007. set(_state "files")
  1008. elseif (${arg} STREQUAL "SOURCEPATH")
  1009. set(_state "sourcepath")
  1010. elseif (${arg} STREQUAL "CLASSPATH")
  1011. set(_state "classpath")
  1012. elseif (${arg} STREQUAL "INSTALLPATH")
  1013. set(_state "installpath")
  1014. elseif (${arg} STREQUAL "DOCTITLE")
  1015. set(_state "doctitle")
  1016. elseif (${arg} STREQUAL "WINDOWTITLE")
  1017. set(_state "windowtitle")
  1018. elseif (${arg} STREQUAL "AUTHOR")
  1019. set(_state "author")
  1020. elseif (${arg} STREQUAL "USE")
  1021. set(_state "use")
  1022. elseif (${arg} STREQUAL "VERSION")
  1023. set(_state "version")
  1024. else ()
  1025. set(_javadoc_author ${arg})
  1026. endif ()
  1027. elseif (${_state} STREQUAL "use")
  1028. if (${arg} STREQUAL "PACKAGES")
  1029. set(_state "packages")
  1030. elseif (${arg} STREQUAL "FILES")
  1031. set(_state "files")
  1032. elseif (${arg} STREQUAL "SOURCEPATH")
  1033. set(_state "sourcepath")
  1034. elseif (${arg} STREQUAL "CLASSPATH")
  1035. set(_state "classpath")
  1036. elseif (${arg} STREQUAL "INSTALLPATH")
  1037. set(_state "installpath")
  1038. elseif (${arg} STREQUAL "DOCTITLE")
  1039. set(_state "doctitle")
  1040. elseif (${arg} STREQUAL "WINDOWTITLE")
  1041. set(_state "windowtitle")
  1042. elseif (${arg} STREQUAL "AUTHOR")
  1043. set(_state "author")
  1044. elseif (${arg} STREQUAL "USE")
  1045. set(_state "use")
  1046. elseif (${arg} STREQUAL "VERSION")
  1047. set(_state "version")
  1048. else ()
  1049. set(_javadoc_use ${arg})
  1050. endif ()
  1051. elseif (${_state} STREQUAL "version")
  1052. if (${arg} STREQUAL "PACKAGES")
  1053. set(_state "packages")
  1054. elseif (${arg} STREQUAL "FILES")
  1055. set(_state "files")
  1056. elseif (${arg} STREQUAL "SOURCEPATH")
  1057. set(_state "sourcepath")
  1058. elseif (${arg} STREQUAL "CLASSPATH")
  1059. set(_state "classpath")
  1060. elseif (${arg} STREQUAL "INSTALLPATH")
  1061. set(_state "installpath")
  1062. elseif (${arg} STREQUAL "DOCTITLE")
  1063. set(_state "doctitle")
  1064. elseif (${arg} STREQUAL "WINDOWTITLE")
  1065. set(_state "windowtitle")
  1066. elseif (${arg} STREQUAL "AUTHOR")
  1067. set(_state "author")
  1068. elseif (${arg} STREQUAL "USE")
  1069. set(_state "use")
  1070. elseif (${arg} STREQUAL "VERSION")
  1071. set(_state "version")
  1072. else ()
  1073. set(_javadoc_version ${arg})
  1074. endif ()
  1075. endif ()
  1076. endforeach ()
  1077. set(_javadoc_builddir ${CMAKE_CURRENT_BINARY_DIR}/javadoc/${_target})
  1078. set(_javadoc_options -d ${_javadoc_builddir})
  1079. if (_javadoc_sourcepath)
  1080. set(_start TRUE)
  1081. foreach(_path ${_javadoc_sourcepath})
  1082. if (_start)
  1083. set(_sourcepath ${_path})
  1084. set(_start FALSE)
  1085. else ()
  1086. set(_sourcepath ${_sourcepath}:${_path})
  1087. endif ()
  1088. endforeach()
  1089. set(_javadoc_options ${_javadoc_options} -sourcepath ${_sourcepath})
  1090. endif ()
  1091. if (_javadoc_classpath)
  1092. set(_start TRUE)
  1093. foreach(_path ${_javadoc_classpath})
  1094. if (_start)
  1095. set(_classpath ${_path})
  1096. set(_start FALSE)
  1097. else ()
  1098. set(_classpath ${_classpath}:${_path})
  1099. endif ()
  1100. endforeach()
  1101. set(_javadoc_options ${_javadoc_options} -classpath "${_classpath}")
  1102. endif ()
  1103. if (_javadoc_doctitle)
  1104. set(_javadoc_options ${_javadoc_options} -doctitle '${_javadoc_doctitle}')
  1105. endif ()
  1106. if (_javadoc_windowtitle)
  1107. set(_javadoc_options ${_javadoc_options} -windowtitle '${_javadoc_windowtitle}')
  1108. endif ()
  1109. if (_javadoc_author)
  1110. set(_javadoc_options ${_javadoc_options} -author)
  1111. endif ()
  1112. if (_javadoc_use)
  1113. set(_javadoc_options ${_javadoc_options} -use)
  1114. endif ()
  1115. if (_javadoc_version)
  1116. set(_javadoc_options ${_javadoc_options} -version)
  1117. endif ()
  1118. add_custom_target(${_target}_javadoc ALL
  1119. COMMAND ${Java_JAVADOC_EXECUTABLE} ${_javadoc_options}
  1120. ${_javadoc_files}
  1121. ${_javadoc_packages}
  1122. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  1123. )
  1124. install(
  1125. DIRECTORY ${_javadoc_builddir}
  1126. DESTINATION ${_javadoc_installpath}
  1127. )
  1128. endfunction()
  1129. function (create_javah)
  1130. cmake_parse_arguments(_create_javah
  1131. ""
  1132. "TARGET;GENERATED_FILES;OUTPUT_NAME;OUTPUT_DIR"
  1133. "CLASSES;CLASSPATH;DEPENDS"
  1134. ${ARGN})
  1135. # ckeck parameters
  1136. if (NOT _create_javah_TARGET AND NOT _create_javah_GENERATED_FILES)
  1137. message (FATAL_ERROR "create_javah: TARGET or GENERATED_FILES must be specified.")
  1138. endif()
  1139. if (_create_javah_OUTPUT_NAME AND _create_javah_OUTPUT_DIR)
  1140. message (FATAL_ERROR "create_javah: OUTPUT_NAME and OUTPUT_DIR are mutually exclusive.")
  1141. endif()
  1142. if (NOT _create_javah_CLASSES)
  1143. message (FATAL_ERROR "create_javah: CLASSES is a required parameter.")
  1144. endif()
  1145. set (_output_files)
  1146. if (WIN32 AND NOT CYGWIN AND CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
  1147. set(_classpath_sep "$<SEMICOLON>")
  1148. else ()
  1149. set(_classpath_sep ":")
  1150. endif()
  1151. # handle javah options
  1152. set (_javah_options)
  1153. if (_create_javah_CLASSPATH)
  1154. # CLASSPATH can specify directories, jar files or targets created with add_jar command
  1155. set (_classpath)
  1156. foreach (_path IN LISTS _create_javah_CLASSPATH)
  1157. if (TARGET ${_path})
  1158. get_target_property (_jar_path ${_path} JAR_FILE)
  1159. if (_jar_path)
  1160. list (APPEND _classpath "${_jar_path}")
  1161. list (APPEND _create_javah_DEPENDS "${_path}")
  1162. else()
  1163. message(SEND_ERROR "create_javah: CLASSPATH target ${_path} is not a jar.")
  1164. endif()
  1165. elseif (EXISTS "${_path}")
  1166. list (APPEND _classpath "${_path}")
  1167. if (NOT IS_DIRECTORY "${_path}")
  1168. list (APPEND _create_javah_DEPENDS "${_path}")
  1169. endif()
  1170. else()
  1171. message(SEND_ERROR "create_javah: CLASSPATH entry ${_path} does not exist.")
  1172. endif()
  1173. endforeach()
  1174. string (REPLACE ";" "${_classpath_sep}" _classpath "${_classpath}")
  1175. list (APPEND _javah_options -classpath "${_classpath}")
  1176. endif()
  1177. if (_create_javah_OUTPUT_DIR)
  1178. list (APPEND _javah_options -d "${_create_javah_OUTPUT_DIR}")
  1179. endif()
  1180. if (_create_javah_OUTPUT_NAME)
  1181. list (APPEND _javah_options -o "${_create_javah_OUTPUT_NAME}")
  1182. set (_output_files "${_create_javah_OUTPUT_NAME}")
  1183. get_filename_component (_create_javah_OUTPUT_DIR "${_create_javah_OUTPUT_NAME}" DIRECTORY)
  1184. get_filename_component (_create_javah_OUTPUT_DIR "${_create_javah_OUTPUT_DIR}" ABSOLUTE)
  1185. endif()
  1186. if (NOT _create_javah_OUTPUT_DIR)
  1187. set (_create_javah_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
  1188. endif()
  1189. if (NOT _create_javah_OUTPUT_NAME)
  1190. # compute output names
  1191. foreach (_class IN LISTS _create_javah_CLASSES)
  1192. string (REPLACE "." "_" _c_header "${_class}")
  1193. set (_c_header "${_create_javah_OUTPUT_DIR}/${_c_header}.h")
  1194. list (APPEND _output_files "${_c_header}")
  1195. endforeach()
  1196. endif()
  1197. # finalize custom command arguments
  1198. if (_create_javah_DEPENDS)
  1199. list (INSERT _create_javah_DEPENDS 0 DEPENDS)
  1200. endif()
  1201. add_custom_command (OUTPUT ${_output_files}
  1202. COMMAND "${Java_JAVAH_EXECUTABLE}" ${_javah_options} -jni ${_create_javah_CLASSES}
  1203. ${_create_javah_DEPENDS}
  1204. WORKING_DIRECTORY ${_create_javah_OUTPUT_DIR}
  1205. COMMENT "Building C header files from classes...")
  1206. if (_create_javah_TARGET)
  1207. add_custom_target (${_create_javah_TARGET} ALL DEPENDS ${_output_files})
  1208. endif()
  1209. if (_create_javah_GENERATED_FILES)
  1210. set (${_create_javah_GENERATED_FILES} ${_output_files} PARENT_SCOPE)
  1211. endif()
  1212. endfunction()