Gyorgy Szing | 5b15f85 | 2018-09-24 17:07:36 +0200 | [diff] [blame^] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2018-2019, Arm Limited. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | # FindPlantuml |
| 9 | # ----------- |
| 10 | # PlantUML is a diagram generation tool. It can generate various UML and non-UML |
| 11 | # diagrams. See: http://plantuml.com/ |
| 12 | # |
| 13 | # This module checks PlantUML availability and checks if the Java runtime is |
| 14 | # available. |
| 15 | # For Windows PlantUML is distributed as a jar archive and thus there is no |
| 16 | # standard install location where it could be searched for. |
| 17 | # Most Linux distributions come with a proper PlantUML package which installs |
| 18 | # a shell script to easy starting PlantUML, but the location of the .jar file |
| 19 | # is hidden. |
| 20 | # Thus there is no standard location to search for the .jar file and this module |
| 21 | # depends on user input. |
| 22 | # |
| 23 | # This module has the following parameters: |
| 24 | # PLANTUML_JAR_PATH = variable specifying where the PlantUML java archive |
| 25 | # (plantuml.jar) can be found. If it is not defined, |
| 26 | # the environment variable with the same name is used. |
| 27 | # If both is missing, that is an error. |
| 28 | # |
| 29 | # This module defines the following variables: |
| 30 | # PLANTUML_VERSION = The version reported by "plantuml.jar -version" |
| 31 | # PLANTUML_FOUND = Was the .jar file found and sucesfuly executed. |
| 32 | # |
| 33 | |
| 34 | find_package(Java 1.8 COMPONENTS Runtime) |
| 35 | if(Java_Runtime_FOUND) |
| 36 | #Check if the jar file is at the user defined location. |
| 37 | #Prefer the cmake variable to the environment setting. |
| 38 | if (NOT DEFINED PLANTUML_JAR_PATH) |
| 39 | if (DEFINED ENV{PLANTUML_JAR_PATH}) |
| 40 | set(PLANTUML_JAR_PATH "$ENV{PLANTUML_JAR_PATH}") |
| 41 | endif() |
| 42 | endif() |
| 43 | |
| 44 | if (NOT DEFINED PLANTUML_JAR_PATH) |
| 45 | message(STATUS "PLANTUML_JAR_PATH variable is missing, PlantUML jar location is unknown.") |
| 46 | else() |
| 47 | #To avoid trouble on windows change directory separator. |
| 48 | if (CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows") |
| 49 | #Do not convert directory separator if there are forward slashes |
| 50 | #present. This is to avoid mixing up escaped characters in cygwin |
| 51 | #or mingw paths (i.e. c:/Program\ Files/something) |
| 52 | string(FIND "${PLANTUML_JAR_PATH}" "/" _is_found) |
| 53 | if (_is_found LESS 0) |
| 54 | string(REPLACE "\\" "/" PLANTUML_JAR_PATH "${PLANTUML_JAR_PATH}") |
| 55 | endif() |
| 56 | endif() |
| 57 | |
| 58 | #Get plantuml version |
| 59 | execute_process(COMMAND "${Java_JAVA_EXECUTABLE}" "-jar" "${PLANTUML_JAR_PATH}" "-version" OUTPUT_VARIABLE _PLANTUML_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET) |
| 60 | #Parse plantuml output |
| 61 | if(_PLANTUML_VERSION) |
| 62 | if(_PLANTUML_VERSION MATCHES ".*PlantUML version ([0-9.]+).*") |
| 63 | string(REGEX REPLACE ".*PlantUML version ([0-9.]+).*" "\\1" PLANTUML_VERSION "${_PLANTUML_VERSION}") |
| 64 | endif() |
| 65 | endif() |
| 66 | endif() |
| 67 | endif() |
| 68 | |
| 69 | #Set "standard" find module return values |
| 70 | include(FindPackageHandleStandardArgs) |
| 71 | find_package_handle_standard_args(Plantuml REQUIRED_VARS PLANTUML_JAR_PATH PLANTUML_VERSION VERSION_VAR PLANTUML_VERSION) |