]> granicus.if.org Git - graphviz/commitdiff
Add lib/cgraph to the CMake build
authorErwin Janssen <erwinjanssen@outlook.com>
Sun, 1 Jan 2017 16:12:21 +0000 (17:12 +0100)
committerErwin Janssen <erwinjanssen@outlook.com>
Thu, 19 Jan 2017 11:53:49 +0000 (12:53 +0100)
Before lib/cgraph can be build, a few checks have to be done for available
headers and functions. This is done in the main CMakeLists.txt.
The generate the required files with BISON and FLEX, the build-in CMake
modules for BISON and FLEX can be used.

CMakeLists.txt
cmake/config_checks.cmake [new file with mode: 0644]
config-cmake.h.in [new file with mode: 0644]
lib/CMakeLists.txt
lib/cgraph/CMakeLists.txt [new file with mode: 0644]

index 482dcfb0d8675f3fd1dd0ec9b9c8929dd9c0ab42..2200d203727cf69166e40247eb6d647f03aee3ee 100644 (file)
@@ -1,4 +1,5 @@
 cmake_minimum_required (VERSION 2.8 FATAL_ERROR)
+list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
 
 # Required to set build version
 find_package(Git REQUIRED)
@@ -40,7 +41,12 @@ set(HEADER_INSTALL_DIR include/graphviz)
 set(MAN_INSTALL_DIR share/man/man3)
 # TODO: Find a way to check for groff and ps2pdf for manpage pdf generation
 # set(MAN_PDF_INSTALL_DIR share/graphviz/doc/pdf)
+set(GRAPHVIZ_LIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib)
 
+# Check avaiable headers, functions and libraries and write the result to config.h
+# ================================================================================
+include(config_checks)
+include_directories(${CMAKE_CURRENT_BINARY_DIR})
 
 # Packaging information
 # =====================
@@ -48,6 +54,8 @@ set(CPACK_GENERATOR ZIP)
 
 include(CPack)
 
+# Specify subdirectories to build
+# ===============================
 add_subdirectory(lib)
 
 # Uninstall target
diff --git a/cmake/config_checks.cmake b/cmake/config_checks.cmake
new file mode 100644 (file)
index 0000000..07efa8d
--- /dev/null
@@ -0,0 +1,12 @@
+# Header checks
+include(CheckIncludeFile)
+
+CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H)
+
+# Function checks
+include(CheckFunctionExists)
+
+CHECK_FUNCTION_EXISTS(strcasecmp HAVE_STRCASECMP)
+
+# Write check results to config.h header
+configure_file(config-cmake.h.in config.h)
diff --git a/config-cmake.h.in b/config-cmake.h.in
new file mode 100644 (file)
index 0000000..f783c30
--- /dev/null
@@ -0,0 +1,5 @@
+// Functions
+#cmakedefine HAVE_STRCASECMP
+
+// Include headers
+#cmakedefine HAVE_UNISTD_H
\ No newline at end of file
index 650cb7bbeaf323951e6271ada5576d603eff93d4..5d94cbcb5a1fd4064bd22bf23578639320846419 100644 (file)
@@ -1 +1,2 @@
 add_subdirectory(cdt)
+add_subdirectory(cgraph)
diff --git a/lib/cgraph/CMakeLists.txt b/lib/cgraph/CMakeLists.txt
new file mode 100644 (file)
index 0000000..b329b55
--- /dev/null
@@ -0,0 +1,74 @@
+BISON_TARGET(Grammar grammar.y ${CMAKE_CURRENT_BINARY_DIR}/grammar.c)
+FLEX_TARGET(Scan scan.l  ${CMAKE_CURRENT_BINARY_DIR}/scan.c)
+ADD_FLEX_BISON_DEPENDENCY(Scan Grammar)
+
+add_definitions(-DCGRAPH_EXPORTS -DYY_NO_UNISTD_H)
+
+include_directories(
+    .
+    ${GRAPHVIZ_LIB_DIR}/cdt
+    ${CMAKE_CURRENT_BINARY_DIR}
+)
+
+add_library(cgraph SHARED
+    # Header files
+    agxbuf.h
+    cghdr.h
+    cgraph.h
+
+    # Source files
+    agerror.c
+    agxbuf.c
+    apply.c
+    attr.c
+    edge.c
+    flatten.c
+    graph.c
+    id.c
+    imap.c
+    io.c
+    mem.c
+    node.c
+    obj.c
+    pend.c
+    rec.c
+    refstr.c
+    subg.c
+    utils.c
+    write.c
+
+    # Generated files
+    ${BISON_Grammar_OUTPUTS}
+    ${FLEX_Scan_OUTPUTS}
+
+    # Link definition file for Windows
+    cgraph.def
+)
+
+target_link_libraries(cgraph cdt)
+
+# Installation location of library files
+install(
+    TARGETS cgraph
+    RUNTIME DESTINATION ${BINARY_INSTALL_DIR}
+    LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR}
+    ARCHIVE DESTINATION ${LIBRARY_INSTALL_DIR}
+)
+
+# Specify headers to be installed
+install(
+    FILES cgraph.h
+    DESTINATION ${HEADER_INSTALL_DIR}
+)
+
+# Specify man pages to be installed
+install(
+    FILES cgraph.3
+    DESTINATION ${MAN_INSTALL_DIR}
+)
+
+# Specify library version and soversion
+set_target_properties(cgraph PROPERTIES
+    VERSION 6.0.0
+    SOVERSION 6
+)