Debian Codegraph @

examples/ViewerExample/cmake/Modules/FindGraphviz.cmake

raw
1 # - Try to find Graphviz
2 # Once done this will define
3 #
4 # GRAPHVIZ_FOUND - system has Graphviz
5 # GRAPHVIZ_INCLUDE_DIRS - Graphviz include directories
6 # GRAPHVIZ_CDT_LIBRARY - Graphviz CDT library
7 # GRAPHVIZ_GVC_LIBRARY - Graphviz GVC library
8 # GRAPHVIZ_CGRAPH_LIBRARY - Graphviz CGRAPH library
9 # GRAPHVIZ_PATHPLAN_LIBRARY - Graphviz PATHPLAN library
10 # GRAPHVIZ_VERSION - Graphviz version
11 #
12 # This module reads hints about search locations from the following cmake variables:
13 # GRAPHVIZ_ROOT - Graphviz installation prefix
14 # (containing bin/, include/, etc.)
15
16 # Copyright (c) 2009, Adrien Bustany, <[email protected]>
17 # Copyright (c) 2013-2014 Kevin Funk <[email protected]>
18
19 # Version computation and some cleanups by Allen Winter <[email protected]>
20 # Copyright (c) 2012-2014 Klarälvdalens Datakonsult AB, a KDAB Group company <[email protected]>
21
22 # Simplified script by Dogan Can <[email protected]>
23 # Copyright (c) 2014 University of Southern California
24
25 # Redistribution and use is allowed according to the terms of the GPLv3+ license.
26
27
28 if(GRAPHVIZ_ROOT)
29 set(_GRAPHVIZ_INCLUDE_DIR ${GRAPHVIZ_ROOT}/include)
30 set(_GRAPHVIZ_LIBRARY_DIR ${GRAPHVIZ_ROOT}/lib)
31 endif()
32
33 find_path(GRAPHVIZ_INCLUDE_DIR NAMES graphviz/cgraph.h
34 HINTS ${_GRAPHVIZ_INCLUDE_DIR})
35 find_library(GRAPHVIZ_CDT_LIBRARY NAMES cdt
36 HINTS ${_GRAPHVIZ_LIBRARY_DIR} ${GRAPHVIZ_ROOT}/lib64 )
37 find_library(GRAPHVIZ_GVC_LIBRARY NAMES gvc
38 HINTS ${_GRAPHVIZ_LIBRARY_DIR} ${GRAPHVIZ_ROOT}/lib64 )
39 find_library(GRAPHVIZ_CGRAPH_LIBRARY NAMES cgraph
40 HINTS ${_GRAPHVIZ_LIBRARY_DIR} ${GRAPHVIZ_ROOT}/lib64 )
41 find_library(GRAPHVIZ_PATHPLAN_LIBRARY NAMES pathplan
42 HINTS ${_GRAPHVIZ_LIBRARY_DIR} ${GRAPHVIZ_ROOT}/lib64 )
43 find_library(GRAPHVIZ_GRAPH_LIBRARY NAMES graph
44 HINTS ${_GRAPHVIZ_LIBRARY_DIR} ${GRAPHVIZ_ROOT}/lib64 )
45
46
47 if(GRAPHVIZ_INCLUDE_DIR AND GRAPHVIZ_CDT_LIBRARY AND GRAPHVIZ_GVC_LIBRARY
48 AND GRAPHVIZ_CGRAPH_LIBRARY AND GRAPHVIZ_PATHPLAN_LIBRARY)
49 set(GRAPHVIZ_FOUND TRUE)
50 else()
51 set(GRAPHVIZ_FOUND FALSE)
52 endif()
53
54 # Ok, now compute the version
55 if(GRAPHVIZ_FOUND)
56 set(FIND_GRAPHVIZ_VERSION_SOURCE
57 "#include <graphviz/graphviz_version.h>\n#include <stdio.h>\n int main()\n {\n printf(\"%s\",PACKAGE_VERSION);return 1;\n }\n")
58 set(FIND_GRAPHVIZ_VERSION_SOURCE_FILE ${CMAKE_BINARY_DIR}/CMakeTmp/FindGRAPHVIZ.cxx)
59 file(WRITE "${FIND_GRAPHVIZ_VERSION_SOURCE_FILE}" "${FIND_GRAPHVIZ_VERSION_SOURCE}")
60
61 set(FIND_GRAPHVIZ_VERSION_ADD_INCLUDES
62 "-DINCLUDE_DIRECTORIES:STRING=${GRAPHVIZ_INCLUDE_DIR}")
63
64 try_run(RUN_RESULT COMPILE_RESULT
65 ${CMAKE_BINARY_DIR}
66 ${FIND_GRAPHVIZ_VERSION_SOURCE_FILE}
67 CMAKE_FLAGS "${FIND_GRAPHVIZ_VERSION_ADD_INCLUDES}"
68 RUN_OUTPUT_VARIABLE GRAPHVIZ_VERSION)
69
70 if(COMPILE_RESULT AND RUN_RESULT EQUAL 1)
71 message(STATUS "Graphviz version: ${GRAPHVIZ_VERSION}")
72 else()
73 message(FATAL_ERROR "Unable to compile or run the graphviz version detection program.")
74 endif()
75
76 set(GRAPHVIZ_INCLUDE_DIRS ${GRAPHVIZ_INCLUDE_DIR} ${GRAPHVIZ_INCLUDE_DIR}/graphviz)
77
78 if(NOT Graphviz_FIND_QUIETLY)
79 message(STATUS "Graphviz include: ${GRAPHVIZ_INCLUDE_DIRS}")
80 message(STATUS "Graphviz libraries: ${GRAPHVIZ_CDT_LIBRARY} ${GRAPHVIZ_GVC_LIBRARY} ${GRAPHVIZ_CGRAPH_LIBRARY} ${GRAPHVIZ_PATHPLAN_LIBRARY}")
81 endif()
82 endif()
83
84 if(Graphviz_FIND_REQUIRED AND NOT GRAPHVIZ_FOUND)
85 message(FATAL_ERROR "Could not find GraphViz.")
86 endif()