From: Erwin Janssen Date: Fri, 3 Feb 2017 16:50:02 +0000 (+0100) Subject: Add lib/common to CMake build X-Git-Tag: 2.42.0~183^2~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ebbeb91705d8e8c9ce3950abb93034c341319952;p=graphviz Add lib/common to CMake build The static library 'common' has no dependencies. The following checks have been added: - FindAWK (custom CMake module added) - FindPerl - FindEXPAT - FindZLIB - HAVE_SINCOS - HAVE_STRINGS_H - HAVE_SYS_TYPES_H - HAVE_STRNCASECMP_H The steps to generate `colortbl.h` and `ps_font_equiv.h` are the same as in the Autotools build. DEFAULT_DPI is now set in the config.h generated by CMake. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index a5c1d1245..27f1389fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,9 +33,11 @@ endif (with_smyrna) list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") # ============================= Build dependencies ============================= -find_package(Git REQUIRED) +find_package(AWK REQUIRED) find_package(BISON REQUIRED) find_package(FLEX REQUIRED) +find_package(Git REQUIRED) +find_package(Perl REQUIRED) # ================== Convenient values for CMake configuration ================= set(BINARY_INSTALL_DIR bin) @@ -57,6 +59,14 @@ else() endif() find_package(ANN) +find_package(EXPAT) +find_package(ZLIB) + +# Find DLLs on Windows +if (WIN32) + find_file(EXPAT_RUNTIME_LIBRARY NAMES libexpat.dll expat.dll) + find_file(ZLIB_RUNTIME_LIBRARY NAMES zlib1.dll zlib.dll) +endif() # ============================ Set Graphviz version ============================ set(GRAPHVIZ_VERSION_MAJROR 2) diff --git a/cmake/FindAWK.cmake b/cmake/FindAWK.cmake new file mode 100644 index 000000000..f5e599edc --- /dev/null +++ b/cmake/FindAWK.cmake @@ -0,0 +1,5 @@ +find_program(AWK_EXECUTABLE NAMES gawk awk) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(AWK DEFAULT_MSG + AWK_EXECUTABLE) diff --git a/cmake/config_checks.cmake b/cmake/config_checks.cmake index def19dc52..5ed6f9e9f 100644 --- a/cmake/config_checks.cmake +++ b/cmake/config_checks.cmake @@ -1,22 +1,27 @@ # Header checks include(CheckIncludeFile) -check_include_file( malloc.h HAVE_MALLOC_H ) -check_include_file( stat.h HAVE_STAT_H ) -check_include_file( sys/stat.h HAVE_SYS_STAT_H ) -check_include_file( unistd.h HAVE_UNISTD_H ) +check_include_file( malloc.h HAVE_MALLOC_H ) +check_include_file( stat.h HAVE_STAT_H ) +check_include_file( strings.h HAVE_STRINGS_H ) +check_include_file( sys/stat.h HAVE_SYS_STAT_H ) +check_include_file( sys/types.h HAVE_SYS_TYPES_H ) +check_include_file( unistd.h HAVE_UNISTD_H ) # Function checks include(CheckFunctionExists) -check_function_exists( drand48 HAVE_DRAND48 ) -check_function_exists( cbrt HAVE_CBRT ) -check_function_exists( getpagesize HAVE_GETPAGESIZE) -check_function_exists( mallinfo HAVE_MALLINFO ) -check_function_exists( mallopt HAVE_MALLOPT ) -check_function_exists( mstats HAVE_MSTATS ) -check_function_exists( srand48 HAVE_SRAND48 ) -check_function_exists( strcasecmp HAVE_STRCASECMP ) +check_function_exists( drand48 HAVE_DRAND48 ) +check_function_exists( cbrt HAVE_CBRT ) +check_function_exists( getpagesize HAVE_GETPAGESIZE ) +check_function_exists( mallinfo HAVE_MALLINFO ) +check_function_exists( mallopt HAVE_MALLOPT ) +check_function_exists( mstats HAVE_MSTATS ) +check_function_exists( sincos HAVE_SINCOS ) +check_function_exists( srand48 HAVE_SRAND48 ) +check_function_exists( strcasecmp HAVE_STRCASECMP ) +check_function_exists( strncasecmp HAVE_STRNCASECMP ) +check_function_exists( vsnprintf HAVE_VSNPRINTF ) # Type checks # The function check_size_type also checks if the type exists @@ -27,9 +32,12 @@ check_type_size( ssize_t SSIZE_T ) check_type_size( intptr_t INTPTR_T ) # Library checks -if (ANN_FOUND) - set(HAVE_ANN 1) -endif() +set( HAVE_ANN ${ANN_FOUND} ) +set( HAVE_EXPAT ${EXPAT_FOUND} ) +set( HAVE_ZLIB ${ZLIB_FOUND} ) + +# Values +set(DEFAULT_DPI 96) # Write check results to config.h header configure_file(config-cmake.h.in config.h) diff --git a/cmake/generate_color_lib.cmake.in b/cmake/generate_color_lib.cmake.in new file mode 100644 index 000000000..f32b80a37 --- /dev/null +++ b/cmake/generate_color_lib.cmake.in @@ -0,0 +1,14 @@ +file(READ @CMAKE_CURRENT_BINARY_DIR@/svgcolor_lib svgcolor_lib) +file(READ @CMAKE_CURRENT_BINARY_DIR@/brewer_lib brewer_lib) +file(READ @CMAKE_CURRENT_SOURCE_DIR@/color_names color_names) + +# Do not ignore empty elements in list +cmake_policy(SET CMP0007 NEW) + +# Make it a list for sorting +string(REPLACE "\n" ";" color_lib ${svgcolor_lib} ${brewer_lib} ${color_names}) +file(WRITE @CMAKE_CURRENT_BINARY_DIR@/color_lib-temp "${color_lib}") +list(SORT color_lib) +file(WRITE @CMAKE_CURRENT_BINARY_DIR@/color_lib-sort "${color_lib}") +string(REGEX REPLACE ";" "\\n" color_lib "${color_lib}") +file(WRITE @CMAKE_CURRENT_BINARY_DIR@/color_lib ${color_lib}) diff --git a/cmake/modify_common_htmlparse.cmake.in b/cmake/modify_common_htmlparse.cmake.in new file mode 100644 index 000000000..5e42fcc4e --- /dev/null +++ b/cmake/modify_common_htmlparse.cmake.in @@ -0,0 +1,11 @@ +file(READ @CMAKE_CURRENT_BINARY_DIR@/htmlparse.h file_contents) +string(REPLACE "yy" "html" file_contents "${file_contents}") +string(REPLACE "unsigned long int" "uint_64_t" file_contents "${file_contents}") +string(REPLACE "unsigned long" "uint_64_t" file_contents "${file_contents}") +file(WRITE @CMAKE_CURRENT_BINARY_DIR@/htmlparse.h "${file_contents}") + +file(READ @CMAKE_CURRENT_BINARY_DIR@/htmlparse.c file_contents) +string(REPLACE "yy" "html" file_contents "${file_contents}") +string(REPLACE "unsigned long int" "uint_64_t" file_contents "${file_contents}") +string(REPLACE "unsigned long" "uint_64_t" file_contents "${file_contents}") +file(WRITE @CMAKE_CURRENT_BINARY_DIR@/htmlparse.c "${file_contents}") diff --git a/config-cmake.h.in b/config-cmake.h.in index 4d7f35de8..b72755887 100644 --- a/config-cmake.h.in +++ b/config-cmake.h.in @@ -4,7 +4,9 @@ // Include headers #cmakedefine HAVE_MALLOC_H #cmakedefine HAVE_STAT_H +#cmakedefine HAVE_STRINGS_H #cmakedefine HAVE_SYS_STAT_H +#cmakedefine HAVE_SYS_TYPES_H #cmakedefine HAVE_UNISTD_H // Functions @@ -14,8 +16,11 @@ #cmakedefine HAVE_MALLINFO #cmakedefine HAVE_MALLOPT #cmakedefine HAVE_MSTATS +#cmakedefine HAVE_SINCOS #cmakedefine HAVE_SRAND48 #cmakedefine HAVE_STRCASECMP +#cmakedefine HAVE_STRNCASECMP +#cmakedefine HAVE_VSNPRINTF // Types #cmakedefine HAVE_SSIZE_T @@ -28,3 +33,8 @@ typedef int ssize_t; // Libraries #cmakedefine HAVE_ANN +#cmakedefine HAVE_EXPAT +#cmakedefine HAVE_ZLIB + +// Values +#define DEFAULT_DPI @DEFAULT_DPI@ diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 57434efd7..227df0db5 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -1,6 +1,7 @@ # No dependencies add_subdirectory(cdt) add_subdirectory(circogen) +add_subdirectory(common) add_subdirectory(dotgen) add_subdirectory(fdpgen) add_subdirectory(ingraphs) diff --git a/lib/common/CMakeLists.txt b/lib/common/CMakeLists.txt new file mode 100644 index 000000000..14b67ca2a --- /dev/null +++ b/lib/common/CMakeLists.txt @@ -0,0 +1,150 @@ +BISON_TARGET(HTMLparse htmlparse.y ${CMAKE_CURRENT_BINARY_DIR}/htmlparse.c) + +# Modify files generated by Bison, to match the Autotools build. +# - Replace "yy" with "aag" +# - Replace "unsigned long int" with "uint64_t" +# - Replace "unsigned long" with "uint64_t" +configure_file( + "${TOP_SOURCE_DIR}/cmake/modify_common_htmlparse.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/modify_common_htmlparse.cmake" + @ONLY +) +add_custom_command( + OUTPUT ${BISON_HTMLparse_OUTPUTS} + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/modify_common_htmlparse.cmake + APPEND +) + +add_definitions(-DGVC_EXPORTS -D_BLD_gvc=1) + +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_BINARY_DIR} + ${TOP_SOURCE_DIR} + ${GRAPHVIZ_LIB_DIR}/cdt + ${GRAPHVIZ_LIB_DIR}/cgraph + ${GRAPHVIZ_LIB_DIR}/gvc + ${GRAPHVIZ_LIB_DIR}/label + ${GRAPHVIZ_LIB_DIR}/pack + ${GRAPHVIZ_LIB_DIR}/pathplan + ${GRAPHVIZ_LIB_DIR}/fdpgen + ${GRAPHVIZ_LIB_DIR}/xdot +) + +if (WIN32) + include_directories(${WINDOWS_DEPENDENCY_DIR}/include) +endif() + +# Generate colortbl.h from sources +add_custom_command( + OUTPUT svgcolor_lib + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/svgcolor_names ${TOP_SOURCE_DIR}/awk/svgcolor.awk + COMMAND ${AWK_EXECUTABLE} -f ${TOP_SOURCE_DIR}/awk/svgcolor.awk + ${CMAKE_CURRENT_SOURCE_DIR}/svgcolor_names > ${CMAKE_CURRENT_BINARY_DIR}/svgcolor_lib +) +add_custom_command( + OUTPUT brewer_lib + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/brewer_colors ${TOP_SOURCE_DIR}/awk/brewer.awk + COMMAND ${AWK_EXECUTABLE} -f ${TOP_SOURCE_DIR}/awk/brewer.awk + ${CMAKE_CURRENT_SOURCE_DIR}/brewer_colors > ${CMAKE_CURRENT_BINARY_DIR}/brewer_lib +) +configure_file( + "${TOP_SOURCE_DIR}/cmake/generate_color_lib.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/generate_color_lib.cmake" + @ONLY +) +add_custom_command( + OUTPUT color_lib + DEPENDS svgcolor_lib brewer_lib ${CMAKE_CURRENT_SOURCE_DIR}/color_names + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/generate_color_lib.cmake +) +add_custom_command( + OUTPUT colortbl.h + DEPENDS color_lib + COMMAND ${AWK_EXECUTABLE} -f ${TOP_SOURCE_DIR}/awk/colortbl.awk + ${CMAKE_CURRENT_BINARY_DIR}/color_lib > ${CMAKE_CURRENT_BINARY_DIR}/colortbl.h +) + +# Generate ps_font_equiv.h from sources +add_custom_command( + OUTPUT ps_font_equiv.h + DEPENDS + ${CMAKE_CURRENT_SOURCE_DIR}/mksvgfonts.pl + ${CMAKE_CURRENT_SOURCE_DIR}/ps_font_equiv.txt + ${CMAKE_CURRENT_SOURCE_DIR}/fontmap.cfg + ${CMAKE_CURRENT_SOURCE_DIR}/ps_fontmap.txt + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/ps_fontmap.txt + ${CMAKE_CURRENT_BINARY_DIR}/ps_font_equiv.h + COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/mksvgfonts.pl + ${CMAKE_CURRENT_SOURCE_DIR}/fontmap.cfg + ${CMAKE_CURRENT_SOURCE_DIR}/ps_font_equiv.txt + >> ${CMAKE_CURRENT_BINARY_DIR}/ps_font_equiv.h +) + +add_library(common STATIC + # Header files + arith.h + color.h + colorprocs.h + colortbl.h + const.h + entities.h + geom.h + geomprocs.h + globals.h + intset.h + htmllex.h + htmltable.h + logic.h + macros.h + memory.h + pointset.h + ps_font_equiv.h + render.h + textspan.h + types.h + usershape.h + utils.h + + # Source files + args.c + arrows.c + colxlate.c + ellipse.c + emit.c + geom.c + globals.c + htmllex.c + htmltable.c + input.c + intset.c + labels.c + ns.c + memory.c + output.c + pointset.c + postproc.c + psusershape.c + routespl.c + shapes.c + splines.c + taper.c + textspan.c + timing.c + utils.c + + # Generated files + ${BISON_HTMLparse_OUTPUTS} +) + +# Specify headers to be installed +install( + FILES + arith.h + color.h + geom.h + textspan.h + types.h + usershape.h + DESTINATION ${HEADER_INSTALL_DIR} +)