Salome HOME
Copyright update 2022
[tools/configuration.git] / cmake / FindGraphviz.cmake
1 # - Graphviz detection
2 #
3 # Output variables: GRAPHVIZ_EXECUTABLE   - where is executable 'dot' takes place.
4 #                   GRAPHVIZ_INCLUDE_DIRS - where to find headers.
5 #                   GRAPHVIZ_LIBRARIES    - where to get libraries.
6 #                   GRAPHVIZ_VERSION      - Graphviz version
7 #                   GRAPHVIZ_DEFINITIONS  - Graphviz definitions
8 #                   GRAPHVIZ_FOUND        - True if Graphviz was found.
9 #
10 ###########################################################################
11 # Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
12 #
13 # This library is free software; you can redistribute it and/or
14 # modify it under the terms of the GNU Lesser General Public
15 # License as published by the Free Software Foundation; either
16 # version 2.1 of the License, or (at your option) any later version.
17 #
18 # This library is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 # Lesser General Public License for more details.
22 #
23 # You should have received a copy of the GNU Lesser General Public
24 # License along with this library; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
26 #
27 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
28 #
29
30 FIND_PROGRAM(GRAPHVIZ_EXECUTABLE dot)
31
32 FIND_PATH(GRAPHVIZ_INCLUDE_DIR NAMES graphviz/cgraph.h)
33 SET(GRAPHVIZ_INCLUDE_DIRS ${GRAPHVIZ_INCLUDE_DIR} ${GRAPHVIZ_INCLUDE_DIR}/graphviz)
34
35 IF(GRAPHVIZ_EXECUTABLE)
36   IF(NOT CMAKE_PREFIX_PATH) # Case where dot is in the path and -DGRAPHVIZ_ROOT_DIR not defined.
37     GET_FILENAME_COMPONENT(GRAPHVIZ_EXECUTABLE_DIR ${GRAPHVIZ_EXECUTABLE} PATH)
38     GET_FILENAME_COMPONENT(GRAPHVIZ_EXECUTABLE_DIR ${GRAPHVIZ_EXECUTABLE_DIR} PATH)
39     SET(CMAKE_PREFIX_PATH "${GRAPHVIZ_EXECUTABLE_DIR}")
40   ENDIF(NOT CMAKE_PREFIX_PATH)
41 ENDIF(GRAPHVIZ_EXECUTABLE)
42
43 FIND_LIBRARY(GRAPHVIZ_cdt_LIBRARY      NAMES cdt PATH_SUFFIXES bin)
44 FIND_LIBRARY(GRAPHVIZ_graph_LIBRARY    NAMES cgraph PATH_SUFFIXES bin)
45 FIND_LIBRARY(GRAPHVIZ_gvc_LIBRARY      NAMES gvc PATH_SUFFIXES bin)
46 FIND_LIBRARY(GRAPHVIZ_pathplan_LIBRARY NAMES pathplan PATH_SUFFIXES bin)
47
48 SET(GRAPHVIZ_LIBRARIES 
49   ${GRAPHVIZ_cdt_LIBRARY}
50   ${GRAPHVIZ_graph_LIBRARY} 
51   ${GRAPHVIZ_gvc_LIBRARY}
52   ${GRAPHVIZ_pathplan_LIBRARY}
53   )
54
55 IF(GRAPHVIZ_EXECUTABLE)
56   EXECUTE_PROCESS(COMMAND ${GRAPHVIZ_EXECUTABLE} "-V" ERROR_VARIABLE GRAPHVIZ_VERSION ERROR_STRIP_TRAILING_WHITESPACE)
57   STRING(REGEX REPLACE ".* ([0-9.]+) .*" "\\1" GRAPHVIZ_VERSION "${GRAPHVIZ_VERSION}")
58 ENDIF()
59
60 SET(GRAPHVIZ_DEFINITIONS)
61 IF("${GRAPHVIZ_VERSION}" VERSION_LESS "2.36.0")
62   SET(GRAPHVIZ_DEFINITIONS -DWITH_CGRAPH)
63 ENDIF()
64
65 ## Don't detect cgraph on Windows
66 #IF(NOT WIN32)
67 #  FIND_LIBRARY(GRAPHVIZ_cgraph_LIBRARY   NAMES cgraph PATH_SUFFIXES bin)
68 #  SET(GRAPHVIZ_LIBRARIES ${GRAPHVIZ_cgraph_LIBRARY})
69 #ENDIF()
70
71 # Handle the standard arguments of the find_package() command:
72 INCLUDE(FindPackageHandleStandardArgs)
73 FIND_PACKAGE_HANDLE_STANDARD_ARGS(Graphviz REQUIRED_VARS 
74                                            GRAPHVIZ_EXECUTABLE 
75                                            GRAPHVIZ_LIBRARIES 
76                                            GRAPHVIZ_INCLUDE_DIRS)