diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fcd74d..ffb1db3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -166,12 +166,6 @@ message(STATUS "Written ${PROJECT_BINARY_DIR}/config.h") configure_file(${PROJECT_SOURCE_DIR}/cmake/json_config.h.in ${PROJECT_BINARY_DIR}/json_config.h) message(STATUS "Written ${PROJECT_BINARY_DIR}/json_config.h") -configure_package_config_file( - "cmake/Config.cmake.in" - ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake - INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" -) - if ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections") # There's a catch here. @@ -248,14 +242,35 @@ add_library(${PROJECT_NAME} # If json-c is used as subroject it set to target correct interface -I flags and allow # to build external target without extra include_directories(...) -set_property(TARGET ${PROJECT_NAME} PROPERTY - INTERFACE_INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR} ${PROJECT_BINARY_DIR} +target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ ) install(TARGETS ${PROJECT_NAME} - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib + EXPORT ${PROJECT_NAME}-targets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +) + +install(EXPORT ${PROJECT_NAME}-targets + FILE ${PROJECT_NAME}-targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} +) + +configure_package_config_file( + "cmake/Config.cmake.in" + ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +) + +install( + FILES ${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME} ) if (UNIX OR MINGW OR CYGWIN) diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in index 38bbde7..035dc0f 100644 --- a/cmake/Config.cmake.in +++ b/cmake/Config.cmake.in @@ -1,4 +1,4 @@ @PACKAGE_INIT@ -include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") check_required_components("@PROJECT_NAME@") diff --git a/configure.ac b/configure.ac index 272ea6a..120797e 100644 --- a/configure.ac +++ b/configure.ac @@ -165,8 +165,13 @@ AS_IF([test "x$enable_Bsymbolic" = "xcheck"], AS_IF([test "x$enable_Bsymbolic" = "xyes"], [JSON_BSYMBOLIC_LDFLAGS=-Wl[,]-Bsymbolic-functions]) AC_SUBST(JSON_BSYMBOLIC_LDFLAGS) -AX_APPEND_COMPILE_FLAGS([-Wall -Werror -Wcast-qual -Wno-error=deprecated-declarations]) -AX_APPEND_COMPILE_FLAGS([-Wextra -Wwrite-string -Wno-unused-parameter]) +AC_ARG_ENABLE([werror], + AS_HELP_STRING([--disable-werror], [avoid treating compiler warnings as fatal errors])) + +AS_IF([test "x$enable_werror" != "xno"], [AX_APPEND_COMPILE_FLAGS([-Werror])]) + +AX_APPEND_COMPILE_FLAGS([-Wall -Wcast-qual -Wno-error=deprecated-declarations]) +AX_APPEND_COMPILE_FLAGS([-Wextra -Wwrite-strings -Wno-unused-parameter]) AX_APPEND_COMPILE_FLAGS([-D_GNU_SOURCE]) AC_LANG_PUSH([C]) diff --git a/json_object.c b/json_object.c index 711a352..9a4d65f 100644 --- a/json_object.c +++ b/json_object.c @@ -810,6 +810,7 @@ static int json_object_double_to_json_string_format(struct json_object* jso, { const char *std_format = "%.17g"; int format_drops_decimals = 0; + int looks_numeric = 0; if (!format) { @@ -837,11 +838,15 @@ static int json_object_double_to_json_string_format(struct json_object* jso, if (format == std_format || strstr(format, ".0f") == NULL) format_drops_decimals = 1; + looks_numeric = /* Looks like *some* kind of number */ + isdigit((unsigned char)buf[0]) || + (size > 1 && buf[0] == '-' && isdigit((unsigned char)buf[1])); + if (size < (int)sizeof(buf) - 2 && - isdigit((unsigned char)buf[0]) && /* Looks like *some* kind of number */ - !p && /* Has no decimal point */ + looks_numeric && + !p && /* Has no decimal point */ strchr(buf, 'e') == NULL && /* Not scientific notation */ - format_drops_decimals) + format_drops_decimals) { // Ensure it looks like a float, even if snprintf didn't, // unless a custom format is set to omit the decimal. diff --git a/tests/test_deep_copy.c b/tests/test_deep_copy.c index 7a6e63f..63f882b 100644 --- a/tests/test_deep_copy.c +++ b/tests/test_deep_copy.c @@ -186,7 +186,8 @@ int main(int argc, char **argv) printf("\nTesting deep_copy with a custom serializer set\n"); json_object *with_serializer = json_object_new_string("notemitted"); - json_object_set_serializer(with_serializer, my_custom_serializer, "dummy userdata", NULL); + char udata[] = "dummy userdata"; + json_object_set_serializer(with_serializer, my_custom_serializer, udata, NULL); json_object_object_add(src1, "with_serializer", with_serializer); dst1 = NULL; /* With a custom serializer in use, a custom shallow_copy function must also be used */ diff --git a/tests/test_double_serializer.c b/tests/test_double_serializer.c index 0f7a60e..bb1b8a2 100644 --- a/tests/test_double_serializer.c +++ b/tests/test_double_serializer.c @@ -11,16 +11,17 @@ int main() { struct json_object *obj = json_object_new_double(0.5); + char udata[] = "test"; printf("Test default serializer:\n"); printf("obj.to_string(standard)=%s\n", json_object_to_json_string(obj)); printf("Test default serializer with custom userdata:\n"); - obj->_userdata = "test"; + obj->_userdata = udata; printf("obj.to_string(userdata)=%s\n", json_object_to_json_string(obj)); printf("Test explicit serializer with custom userdata:\n"); - json_object_set_serializer(obj, json_object_double_to_json_string, "test", NULL); + json_object_set_serializer(obj, json_object_double_to_json_string, udata, NULL); printf("obj.to_string(custom)=%s\n", json_object_to_json_string(obj)); printf("Test reset serializer:\n"); @@ -74,4 +75,8 @@ int main() printf("ERROR: json_c_set_serialization_double_format() failed"); json_object_put(obj); + + obj = json_object_new_double(-12.0); + printf("obj(-12.0).to_string(default format)=%s\n", json_object_to_json_string(obj)); + } diff --git a/tests/test_double_serializer.expected b/tests/test_double_serializer.expected index 98eea1e..d3aef72 100644 --- a/tests/test_double_serializer.expected +++ b/tests/test_double_serializer.expected @@ -16,3 +16,4 @@ obj(12.0).to_string(default format)=12.0 obj(12.0).to_string(%.0f)=12 obj(12.0).to_string(%.0g)=1e+01 obj(12.0).to_string(%.1g)=12.0 +obj(-12.0).to_string(default format)=-12.0