From e9afe4b6cfe87a6c2afdfd88e3af6618eff9a25b Mon Sep 17 00:00:00 2001 From: Michael Steinert Date: Sat, 30 Jun 2018 23:27:06 -0500 Subject: [PATCH 1/4] Fix -Wdiscarded-qualifiers warnings --- tests/check_slug.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/check_slug.c b/tests/check_slug.c index 0e9fe0b..52b8b4b 100644 --- a/tests/check_slug.c +++ b/tests/check_slug.c @@ -55,7 +55,7 @@ START_TEST (test_r3_slug_find_pattern) { int len; char *test_str = "{name:\\s+}"; - char * namerex = r3_slug_find_pattern(test_str, strlen(test_str), &len); + const char * namerex = r3_slug_find_pattern(test_str, strlen(test_str), &len); ck_assert( strncmp(namerex, "\\s+", len) == 0 ); } END_TEST @@ -64,7 +64,7 @@ START_TEST (test_r3_slug_find_name) { int len; char *test_str = "{name:\\s+}"; - char * namerex = r3_slug_find_name(test_str, strlen(test_str), &len); + const char * namerex = r3_slug_find_name(test_str, strlen(test_str), &len); ck_assert( strncmp(namerex, "name", len) == 0 ); } END_TEST @@ -73,7 +73,7 @@ START_TEST (test_r3_slug_find_name_without_pattern) { int len; char *test_str = "{name}"; - char * namerex = r3_slug_find_name(test_str, strlen(test_str), &len); + const char * namerex = r3_slug_find_name(test_str, strlen(test_str), &len); ck_assert( strncmp(namerex, "name", len) == 0 ); } END_TEST @@ -82,7 +82,7 @@ START_TEST (test_r3_slug_find_name_with_multiple_slug) { int len; char *test_str = "{name}/{name2}"; - char * namerex = r3_slug_find_name(test_str, strlen(test_str), &len); + const char * namerex = r3_slug_find_name(test_str, strlen(test_str), &len); ck_assert( strncmp(namerex, "name", len) == 0 ); } END_TEST @@ -90,7 +90,7 @@ END_TEST START_TEST (test_r3_slug_find_placeholder) { int slug_len = 0; - char * slug; + const char * slug; char *test_str = "/user/{name:\\s+}/to/{id}"; slug = r3_slug_find_placeholder(test_str, strlen(test_str), &slug_len); ck_assert( strncmp(slug, "{name:\\s+}", slug_len) == 0 ); @@ -193,7 +193,7 @@ START_TEST (test_r3_slug_find_placeholder_with_broken_slug) { int slug_len = 0; char *sl_test = "/user/{name:\\s+/to/{id"; - char * slug = r3_slug_find_placeholder(sl_test, strlen(sl_test), &slug_len); + const char * slug = r3_slug_find_placeholder(sl_test, strlen(sl_test), &slug_len); ck_assert(slug == 0); } END_TEST From 2be2a087506ffe2c72ce5210552c4a137e37a77c Mon Sep 17 00:00:00 2001 From: Michael Steinert Date: Sat, 30 Jun 2018 23:27:54 -0500 Subject: [PATCH 2/4] Fix -Wincompatible-pointer-types warning --- src/token.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/token.c b/src/token.c index 77f8cb2..6f5e4d3 100644 --- a/src/token.c +++ b/src/token.c @@ -21,9 +21,8 @@ void str_array_free(str_array *l) { } bool str_array_append(str_array * l, const char * token, unsigned int len) { - R3_VECTOR(r3_iovec_t) *tks = &l->tokens; - r3_vector_reserve(NULL, tks, tks->size + 1); - r3_iovec_t *temp = tks->entries + tks->size++; + r3_vector_reserve(NULL, &l->tokens, l->tokens.size + 1); + r3_iovec_t *temp = l->tokens.entries + l->tokens.size++; memset(temp, 0, sizeof(*temp)); temp->base = token; temp->len = len; From d1c06cd3e95e16a66962c2386d16925fd8493e66 Mon Sep 17 00:00:00 2001 From: Michael Steinert Date: Sat, 30 Jun 2018 23:31:49 -0500 Subject: [PATCH 3/4] Cleanup CMake build files --- 3rdparty/CMakeLists.txt | 6 --- CMakeLists.txt | 91 +++++++++++++++++------------------------ config.h.cmake | 89 ---------------------------------------- src/CMakeLists.txt | 31 +++++++++++--- tests/CMakeLists.txt | 37 ++++++++--------- 5 files changed, 80 insertions(+), 174 deletions(-) delete mode 100644 3rdparty/CMakeLists.txt diff --git a/3rdparty/CMakeLists.txt b/3rdparty/CMakeLists.txt deleted file mode 100644 index 4726cdb..0000000 --- a/3rdparty/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -include_directories("${PROJECT_SOURCE_DIR}/3rdparty ${PROJECT_SOURCE_DIR}") -set(lib3rdparty_SRCS zmalloc.c) -add_library(lib3rdparty STATIC ${lib3rdparty_SRCS}) -# add_library(r3 SHARED ${libr3_SRCS}) -# target_link_libraries(r3 cblas) -# install(FILES ${libswiftnav_HEADERS} DESTINATION include/libswiftnav) diff --git a/CMakeLists.txt b/CMakeLists.txt index 84a1e51..3c82633 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,62 +1,45 @@ -# cmake file examples -# https://code.google.com/p/opencv-feature-tracker/source/browse/CMakeLists.txt?r=f804b03e704147e65183c19a50f57abedb22f45c - - -# TODO: -# cmake clean... orz -# http://stackoverflow.com/questions/9680420/looking-for-a-cmake-clean-command-to-clear-up-cmake-output - -# load required modules -include(CheckIncludeFile) -include(CheckSymbolExists) -include(CheckTypeSize) - - cmake_minimum_required(VERSION 3.0) project(r3 VERSION 2.0.0) -SET(CMAKE_MODULE_PATH - ${PROJECT_SOURCE_DIR}/cmake/Modules - ${CMAKE_MODULE_PATH} -) - -# check for availability of certain headers -CHECK_INCLUDE_FILE(dlfcn.h HAVE_DLFCN_H) -CHECK_INCLUDE_FILE(inttypes.h HAVE_INTTYPES_H) -CHECK_INCLUDE_FILE(jemalloc/jemalloc.h HAVE_JEMALLOC_JEMALLOC_H) -CHECK_INCLUDE_FILE(memory.h HAVE_MEMORY_H) -CHECK_INCLUDE_FILE(stdlib.h HAVE_STDLIB_H) -CHECK_INCLUDE_FILE(string.h HAVE_STRING_H) -CHECK_INCLUDE_FILE(stdbool.h HAVE_STDBOOL_H) -CHECK_INCLUDE_FILE(strings.h HAVE_STRINGS_H) -CHECK_INCLUDE_FILE(sys/stat.h HAVE_SYS_STAT_H) -CHECK_INCLUDE_FILE(sys/time.h HAVE_SYS_TIME_H) -CHECK_INCLUDE_FILE(unistd.h HAVE_UNISTD_H) - -# check availability of certain system functions -CHECK_SYMBOL_EXISTS("gettimeofday" "sys/time.h" HAVE_GETTIMEOFDAY) -CHECK_SYMBOL_EXISTS("memset" "string.h" HAVE_MEMSET) -CHECK_SYMBOL_EXISTS("strchr" "string.h" HAVE_STRCHR) -CHECK_SYMBOL_EXISTS("strdup" "string.h" HAVE_STRDUP) -CHECK_SYMBOL_EXISTS("strndup" "string.h" HAVE_STRNDUP) -CHECK_SYMBOL_EXISTS("strnstr" "string.h" HAVE_STRNSTR) -CHECK_SYMBOL_EXISTS("strstr" "string.h" HAVE_STRSTR) - -# check availability of certain types -CHECK_TYPE_SIZE(_Bool _BOOL) - -# generate the configuration file -configure_file("${PROJECT_SOURCE_DIR}/config.h.cmake" "${PROJECT_BINARY_DIR}/config.h") - -include_directories(${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/3rdparty ${PROJECT_BINARY_DIR}) +list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules) +set(CMAKE_C_STANDARD 99) +find_package(Check) find_package(PCRE REQUIRED) -set(LIBS ${PCRE_LIBRARIES} r3 lib3rdparty) +include(CheckSymbolExists) +check_symbol_exists(strdup string.h HAVE_STRDUP) +check_symbol_exists(strndup string.h HAVE_STRNDUP) +configure_file(config.h.cmake config.h) -enable_testing() - -add_subdirectory(3rdparty) add_subdirectory(src) -add_subdirectory(tests) -# add_test(test_tree ${CMAKE_CURRENT_BINARY_DIR}/check_tree) + +install( + FILES + include/memory.h + include/r3.h + include/r3_list.h + include/r3_slug.h + include/r3_gvc.h + include/r3_json.h + include/str_array.h + include/r3.hpp + DESTINATION include) + +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix ${prefix}) +set(includedir ${prefix}/include) +set(libdir ${prefix}/lib) +set(PACKAGE_VERSION ${PROJECT_VERSION}) +configure_file(r3.pc.in r3.pc @ONLY) +install( + FILES + ${PROJECT_BINARY_DIR}/r3.pc + DESTINATION lib/pkgconfig) + +if(CHECK_FOUND) + enable_testing() + add_subdirectory(tests) +else() + message(STATUS "Skipping unit tests, Check library not found!") +endif() diff --git a/config.h.cmake b/config.h.cmake index b90341d..4a3a9da 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -1,91 +1,2 @@ -#cmakedefine HAVE_DLFCN_H @HAVE_STDLIB_H@ -#cmakedefine HAVE_GETTIMEOFDAY @HAVE_GETTIMEOFDAY@ -#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@ -#cmakedefine HAVE_JEMALLOC_JEMALLOC_H @HAVE_JEMALLOC_JEMALLOC_H@ -#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@ -#cmakedefine HAVE_MEMSET @HAVE_MEMSET@ -#cmakedefine HAVE_STDBOOL_H @HAVE_STDBOOL_H@ -#cmakedefine HAVE_STDINT_H @HAVE_STDINT_H@ -#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@ -#cmakedefine HAVE_STRCHR @HAVE_STRCHR@ #cmakedefine HAVE_STRDUP @HAVE_STRDUP@ -#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@ -#cmakedefine HAVE_STRING_H @HAVE_STRING_H@ #cmakedefine HAVE_STRNDUP @HAVE_STRNDUP@ -#cmakedefine HAVE_STRSTR @HAVE_STRSTR@ -#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@ -#cmakedefine HAVE_SYS_TIME_H @HAVE_SYS_TIME_H@ -#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ -#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@ -#cmakedefine HAVE__BOOL @HAVE__BOOL@ - -/* Name of package */ -#define PACKAGE "@PROJECT_NAME@" - -/* Define to the address where bug reports for this package should be sent. */ -#define PACKAGE_BUGREPORT "" - -/* Define to the full name of this package. */ -#define PACKAGE_NAME "@PROJECT_NAME@" - -/* Define to the full name and version of this package. */ -#define PACKAGE_STRING "@PROJECT_NAME@ @PROJECT_VERSION@" - -/* Define to the one symbol short name of this package. */ -#define PACKAGE_TARNAME "@PROJECT_NAME@" - -/* Define to the home page for this package. */ -#define PACKAGE_URL "" - -/* Define to the version of this package. */ -#define PACKAGE_VERSION "@PROJECT_VERSION@" - -/* Define to 1 if you have the ANSI C header files. */ -#define STDC_HEADERS 1 - -/* Define to 1 if you have the PATH_MAX macro. */ -/* #undef USE_JEMALLOC */ - -/* Enable extensions on AIX 3, Interix. */ -#ifndef _ALL_SOURCE -# define _ALL_SOURCE 1 -#endif -/* Enable GNU extensions on systems that have them. */ -#ifndef _GNU_SOURCE -# define _GNU_SOURCE 1 -#endif -/* Enable threading extensions on Solaris. */ -#ifndef _POSIX_PTHREAD_SEMANTICS -# define _POSIX_PTHREAD_SEMANTICS 1 -#endif -/* Enable extensions on HP NonStop. */ -#ifndef _TANDEM_SOURCE -# define _TANDEM_SOURCE 1 -#endif -/* Enable general extensions on Solaris. */ -#ifndef __EXTENSIONS__ -# define __EXTENSIONS__ 1 -#endif - - -/* Version number of package */ -#define VERSION "@PROJECT_VERSION@" - -/* Define to 1 if on MINIX. */ -/* #undef _MINIX */ - -/* Define to 2 if the system does not provide POSIX.1 features except with - this defined. */ -/* #undef _POSIX_1_SOURCE */ - -/* Define to 1 if you need to in order for `stat' and other things to work. */ -/* #undef _POSIX_SOURCE */ - -/* Define to `__inline__' or `__inline' if that's what the C compiler - calls it, or to nothing if 'inline' is not supported under any name. */ -#ifndef __cplusplus -/* #undef inline */ -#endif - -/* Define to `unsigned int' if does not define. */ -/* #undef size_t */ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dd9a47b..185d7d3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,8 +1,27 @@ -include_directories("${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/3rdparty ${PROJECT_SOURCE_DIR}") -set(SOURCES node.c edge.c str.c token.c match_entry.c slug.c memory.c) -set(LIBS ${LIBS} ${PCRE_LIBRARIES}) +add_library(r3 STATIC + ${PROJECT_SOURCE_DIR}/3rdparty/zmalloc.c + edge.c + match_entry.c + memory.c + node.c + slug.c + str.c + token.c) -add_library(r3 STATIC ${SOURCES}) +target_compile_definitions(r3 + PRIVATE + _GNU_SOURCE) -install(TARGETS r3 DESTINATION lib) -# install(FILES ${libswiftnav_HEADERS} DESTINATION include/libswiftnav) +target_include_directories(r3 + PUBLIC + ${PROJECT_BINARY_DIR} + ${PROJECT_SOURCE_DIR}/3rdparty + ${PROJECT_SOURCE_DIR}/include) + +target_link_libraries(r3 + PUBLIC + ${PCRE_LIBRARIES}) + +install( + TARGETS r3 + DESTINATION lib) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 3e7013c..f2643d7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,24 +1,23 @@ -# set(TEST_LIBS ${TEST_LIBS} ${CHECK_LIBRARIES} judy libr3) -include_directories("${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}") -find_package(Check REQUIRED) -find_package(PCRE REQUIRED) -# find_package(Judy REQUIRED) +function(add_r3_test NAME) + add_executable(${NAME} ${ARGN}) -if (NOT CHECK_FOUND) - message(STATUS "Skipping unit tests, Check library not found!") -else (NOT CHECK_FOUND) - set(TEST_LIBS ${LIBS} ${CHECK_LIBRARIES} ${PCRE_LIBRARIES} r3) + target_include_directories(${NAME} + PRIVATE + ${CHECK_INCLUDE_DIRS} + ${PROJECT_BINARY_DIR} + ${PROJECT_SOURCE_DIR}/src) - include_directories(${CHECK_INCLUDE_DIRS}) - # include_directories("${PROJECT_SOURCE_DIR}/include/r2") - add_executable(check_tree check_tree.c) - target_link_libraries(check_tree ${TEST_LIBS} ${CHECK_LDFLAGS_OTHER}) + target_link_libraries(${NAME} + ${CHECK_LDFLAGS} + r3) - add_custom_command( - TARGET check_tree POST_BUILD - COMMENT "Running unit tests" - COMMAND check_tree - ) -endif (NOT CHECK_FOUND) + add_test(NAME ${NAME} COMMAND ${NAME}) +endfunction() +add_r3_test(check_tree check_tree.c) +add_r3_test(check_slug check_slug.c) +add_r3_test(check_routes check_routes.c) +add_r3_test(check_str_array check_str_array.c) +add_executable(bench bench.c) +target_link_libraries(bench r3) From e701bfd596fc79fc7e35ce69341e26e85601ea80 Mon Sep 17 00:00:00 2001 From: Michael Steinert Date: Thu, 5 Jul 2018 11:52:34 -0500 Subject: [PATCH 4/4] Add CMake to the CI matrix --- .travis-ci/install.sh | 2 ++ .travis-ci/{script.sh => script-autotools.sh} | 0 .travis-ci/script-cmake.sh | 8 ++++++++ .travis.yml | 14 +++++++++++++- 4 files changed, 23 insertions(+), 1 deletion(-) rename .travis-ci/{script.sh => script-autotools.sh} (100%) create mode 100755 .travis-ci/script-cmake.sh diff --git a/.travis-ci/install.sh b/.travis-ci/install.sh index ba91136..577d1a5 100755 --- a/.travis-ci/install.sh +++ b/.travis-ci/install.sh @@ -7,10 +7,12 @@ apt-get install -qq \ build-essential \ check \ clang \ + cmake \ graphviz-dev \ libjemalloc-dev \ libpcre3-dev \ libtool \ + ninja-build \ pkg-config if [ x$COVERALLS == xyes ]; then diff --git a/.travis-ci/script.sh b/.travis-ci/script-autotools.sh similarity index 100% rename from .travis-ci/script.sh rename to .travis-ci/script-autotools.sh diff --git a/.travis-ci/script-cmake.sh b/.travis-ci/script-cmake.sh new file mode 100755 index 0000000..3a80810 --- /dev/null +++ b/.travis-ci/script-cmake.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +set -ev + +mkdir build && cd build +cmake -GNinja .. +ninja -v +ctest diff --git a/.travis.yml b/.travis.yml index 80ccbaa..6c4e186 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,6 +11,7 @@ matrix: include: - compiler: gcc env: + - TYPE=autotools - CONFIGURE_OPTION='--enable-debug --enable-gcov --with-malloc=jemalloc' - COVERALLS=yes - VALGRIND=no @@ -19,6 +20,7 @@ matrix: - CXX=g++ - compiler: gcc env: + - TYPE=autotools - CONFIGURE_OPTION='--enable-debug --enable-gcov' - COVERALLS=yes - VALGRIND=yes @@ -27,12 +29,22 @@ matrix: - CXX=g++ - compiler: clang env: + - TYPE=autotools - CONFIGURE_OPTION='--enable-debug --enable-gcov' - COVERALLS=yes - VALGRIND=yes - DEBUG=yes - CC=clang - CXX=clang++ + - compiler: gcc + env: + - TYPE=cmake + - CONFIGURE_OPTION='--enable-debug --enable-gcov' + - COVERALLS=yes + - VALGRIND=yes + - DEBUG=yes + - CC=gcc + - CXX=g++ before_install: - docker run -d @@ -52,7 +64,7 @@ install: - docker exec -t build bash -c "cd /travis && .travis-ci/install.sh" script: - - docker exec -t build bash -c "cd /travis && .travis-ci/script.sh" + - docker exec -t build bash -c "cd /travis && .travis-ci/script-$TYPE.sh" after_success: - docker exec -t build bash -c "cd /travis && .travis-ci/after_success.sh"