Skip to content
This repository has been archived by the owner on Oct 13, 2020. It is now read-only.

Commit

Permalink
CDRIVER-2055 Compile libbson examples on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bjori committed Mar 27, 2017
1 parent 990c126 commit 8086fcf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .evergreen/compile-windows.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ CC=${CC:-"Visual Studio 14 2015 Win64"}
echo "CC: $CC"
echo "RELEASE: $RELEASE"

CONFIGURE_FLAGS="-DCMAKE_INSTALL_PREFIX=C:/libbson"
CONFIGURE_FLAGS="-DCMAKE_INSTALL_PREFIX=C:/libbson -DENABLE_EXAMPLES:BOOL=ON"
BUILD_FLAGS="/m" # Number of concurrent processes. No value=# of cpus

if [ "$RELEASE" ]; then
Expand Down
24 changes: 23 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8)
project (libbson)

option(ENABLE_TESTS "Build libbson tests." ON)
option(ENABLE_EXAMPLES "Build libbson examples." OFF)

include(CheckFunctionExists)
include(CheckIncludeFile)
Expand Down Expand Up @@ -271,9 +272,30 @@ if (ENABLE_TESTS)
DESTINATION ${PROJECT_BINARY_DIR}/tests)
endif () # ENABLE_TESTS

function (add_example bin src)
set (BSON_EXAMPLE_SOURCES ${SOURCE_DIR}/${src})
add_executable (${bin} ${BSON_EXAMPLE_SOURCES})

# Link against the shared lib like normal apps
target_link_libraries(${bin} bson_shared)

set (EXAMPLES ${EXAMPLES} ${bin})
endfunction ()

if (ENABLE_EXAMPLES)
add_example (bcon-col-view examples/bcon-col-view.c)
add_example (bcon-speed examples/bcon-speed.c)
add_example (bson-metrics examples/bson-metrics.c)
# Uses getopt ()
#add_example (bson-streaming-reader examples/bson-streaming-reader.c)
add_example (bson-to-json examples/bson-to-json.c)
add_example (bson-validate examples/bson-validate.c)
add_example (json-to-bson examples/json-to-bson.c)
endif () # ENABLE_EXAMPLES

set (BSON_HEADER_INSTALL_DIR "include/libbson-${BSON_API_VERSION}")
install(
TARGETS bson_shared bson_static
TARGETS bson_shared bson_static ${EXAMPLES}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
Expand Down
16 changes: 8 additions & 8 deletions examples/bson-metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,29 +271,29 @@ main (int argc, char *argv[])
printf (" \"file\": \"%s\",\n", filename);
printf (" \"secs\": %.2f,\n", dtime_delta);
printf (" \"docs_per_sec\": %" PRIu64 ",\n",
(uint64_t) round (state.doc_count / dtime_delta));
(uint64_t) floor (state.doc_count / dtime_delta));
printf (" \"docs\": %" PRIu64 ",\n", state.doc_count);
printf (" \"elements\": %" PRIu64 ",\n", state.element_count);
printf (" \"elements_per_doc\": %" PRIu64 ",\n",
(uint64_t) round ((double) state.element_count /
(uint64_t) floor ((double) state.element_count /
(double) BSON_MAX (state.doc_count, 1)));
printf (" \"aggregates\": %" PRIu64 ",\n", aggregate_count);
printf (" \"aggregates_per_doc\": %" PRIu64 ",\n",
(uint64_t) round ((double) aggregate_count /
(uint64_t) floor ((double) aggregate_count /
(double) BSON_MAX (state.doc_count, 1)));
printf (" \"degree\": %" PRIu64 ",\n",
(uint64_t) round (
(uint64_t) floor (
(double) state.element_count /
((double) BSON_MAX (state.doc_count + aggregate_count, 1))));
printf (" \"doc_size_max\": %" PRIu64 ",\n", state.doc_size_max);
printf (" \"doc_size_average\": %" PRIu64 ",\n",
(uint64_t) round ((double) bson_reader_tell (reader) /
(uint64_t) floor ((double) bson_reader_tell (reader) /
(double) BSON_MAX (state.doc_count, 1)));
printf (" \"key_size_average\": %" PRIu64 ",\n",
(uint64_t) round ((double) state.key_size_tally /
(uint64_t) floor ((double) state.key_size_tally /
(double) BSON_MAX (state.element_count, 1)));
printf (" \"string_size_average\": %" PRIu64 ",\n",
(uint64_t) round (
(uint64_t) floor (
(double) state.utf8_size_tally /
(double) BSON_MAX (
state.bson_type_metrics[BSON_TYPE_UTF8].count, 1)));
Expand All @@ -302,7 +302,7 @@ main (int argc, char *argv[])
bson_type_metrics_t bson_type_metrics = state.bson_type_metrics[j];
printf (" \"%s\": %" PRIu64 ",\n",
bson_type_metrics.description,
(uint64_t) round ((double) bson_type_metrics.count * 100.0 /
(uint64_t) floor ((double) bson_type_metrics.count * 100.0 /
(double) BSON_MAX (state.element_count, 1)));
}
printf (" }\n");
Expand Down
2 changes: 1 addition & 1 deletion examples/bson-streaming-reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <unistd.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/socket.h>
Expand Down
3 changes: 3 additions & 0 deletions examples/bson-to-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
#include <bson.h>
#include <stdio.h>

#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif

int
main (int argc, char *argv[])
Expand Down
4 changes: 4 additions & 0 deletions examples/json-to-bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include <stdio.h>


#ifndef STDIN_FILENO
#define STDIN_FILENO 0
#endif

int
main (int argc, char *argv[])
{
Expand Down

0 comments on commit 8086fcf

Please sign in to comment.