diff --git a/.appveyor.yml b/.appveyor.yml
new file mode 100644
index 0000000..c4223c7
--- /dev/null
+++ b/.appveyor.yml
@@ -0,0 +1,26 @@
+version: '{build}'
+
+image: Visual Studio 2017
+
+init:
+ - cmd: git config --global core.autocrlf true
+
+platform:
+ - x64
+
+configuration:
+ - Debug
+ - Release
+
+before_build:
+ - cmake -H. -Bbuild -A%PLATFORM% -DBUILD_TESTING=ON
+
+build:
+ project: build\opentracing-cpp.sln
+ parallel: false
+ verbosity: normal
+
+test_script:
+- ps: |
+ cd build
+ ctest -V -C $env:configuration --timeout 600 --output-on-failure
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index c09aba1..a9424d3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -31,6 +31,9 @@
*.out
*.app
+# Cmake Build Directory
+build
+
# Ignore all bazel-* symlinks. There is no full list since this can change
# based on the name of the directory bazel is cloned into.
/bazel-*
diff --git a/BUILD.bazel b/BUILD.bazel
index d01d631..c57dc9f 100644
--- a/BUILD.bazel
+++ b/BUILD.bazel
@@ -1,6 +1,6 @@
cc_library(
name = "opentracing",
- srcs = glob(["src/**/*.cpp"], exclude=["src/dynamic_load_unsupported.cpp"]),
+ srcs = glob(["src/**/*.cpp"], exclude=["src/dynamic_load_unsupported.cpp", "src/dynamic_load_windows.cpp"]),
hdrs = glob(["include/opentracing/**/*.h"]) + [
":include/opentracing/config.h",
":include/opentracing/version.h",
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0cf3c88..4fa5829 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -25,6 +25,10 @@ SET(CPACK_PACKAGE_VERSION_MINOR ${OPENTRACING_VERSION_MINOR})
SET(CPACK_PACKAGE_VERSION_PATCH ${OPENTRACING_VERSION_PATCH})
include(CPack)
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output)
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output)
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output)
+
# ==============================================================================
# Configure compilers
@@ -40,6 +44,8 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
-Wno-padded")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
+elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_RELEASE} -D_SCL_SECURE_NO_WARNINGS")
endif()
# ==============================================================================
@@ -74,9 +80,11 @@ option(BUILD_MOCKTRACER "Build mocktracer library" ON)
option(BUILD_DYNAMIC_LOADING "Build with dynamic loading support" ON)
if (BUILD_DYNAMIC_LOADING)
- if (NOT SUPPORTS_WEAK_SYMBOLS OR NOT UNIX)
- message(WARNING "Building without dynamic loading support.")
- set(BUILD_DYNAMIC_LOADING OFF)
+ if (NOT WIN32)
+ if (NOT SUPPORTS_WEAK_SYMBOLS OR NOT UNIX)
+ message(WARNING "Building without dynamic loading support.")
+ set(BUILD_DYNAMIC_LOADING OFF)
+ endif()
endif()
endif()
@@ -116,7 +124,11 @@ set(SRCS src/propagation.cpp
src/ext/tags.cpp)
if (BUILD_DYNAMIC_LOADING)
- list(APPEND SRCS src/dynamic_load_unix.cpp)
+ if (WIN32)
+ list(APPEND SRCS src/dynamic_load_windows.cpp)
+ else()
+ list(APPEND SRCS src/dynamic_load_unix.cpp)
+ endif()
else()
list(APPEND SRCS src/dynamic_load_unsupported.cpp)
endif()
@@ -133,7 +145,9 @@ if (BUILD_SHARED_LIBS)
target_include_directories(opentracing INTERFACE "$")
set_target_properties(opentracing PROPERTIES VERSION ${OPENTRACING_VERSION_STRING}
SOVERSION ${OPENTRACING_VERSION_MAJOR})
+ target_compile_definitions(opentracing PRIVATE OPENTRACING_EXPORTS)
install(TARGETS opentracing EXPORT OpenTracingTargets
+ RUNTIME DESTINATION ${LIB_INSTALL_DIR}
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
if (CLANG_TIDY_EXE)
@@ -145,7 +159,11 @@ endif()
if (BUILD_STATIC_LIBS)
add_library(opentracing-static STATIC ${SRCS})
target_link_libraries(opentracing-static ${LIBRARIES})
- set_target_properties(opentracing-static PROPERTIES OUTPUT_NAME opentracing)
+ # Windows generates a lib and dll files for a shared library. using the same name will override the lib file generated by the shared target
+ if (NOT WIN32)
+ set_target_properties(opentracing-static PROPERTIES OUTPUT_NAME opentracing)
+ endif()
+ target_compile_definitions(opentracing-static PRIVATE OPENTRACING_STATIC)
target_include_directories(opentracing-static INTERFACE "$")
install(TARGETS opentracing-static EXPORT OpenTracingTargets
ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
diff --git a/README.md b/README.md
index 94c27e6..2df6aaf 100644
--- a/README.md
+++ b/README.md
@@ -11,6 +11,8 @@ In order to understand the C++ platform API, one must first be familiar with the
## Compile and install
+#### Linux/MacOS
+
```bash
mkdir .build
cd .build
@@ -25,6 +27,32 @@ To test:
make test
```
+#### Windows
+
+```bash
+mkdir .build
+cd .build
+cmake -G "Visual Studio 15 2017 Win64" ..
+```
+To build the targets in debug mode
+```bash
+MSBuild.exe opentracing-cpp.sln /p:Configuration=Debug /Target=Build
+```
+To build the targets in release mode
+```bash
+MSBuild.exe opentracing-cpp.sln /p:Configuration=Release /Target=Build
+```
+
+To test:
+Run the below command to run the tests with the debug targets
+```bash
+ctest -C Debug
+```
+Run the below command to run the tests with the release targets
+```bash
+ctest -C Release
+```
+
## API overview for those adding instrumentation
Everyday consumers of this `opentracing` package really only need to worry
diff --git a/example/dynamic_load/dynamic_load-example.cpp b/example/dynamic_load/dynamic_load-example.cpp
index 8ef1cb1..f49996f 100644
--- a/example/dynamic_load/dynamic_load-example.cpp
+++ b/example/dynamic_load/dynamic_load-example.cpp
@@ -13,6 +13,11 @@
#include
#include
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable : 4996)
+#endif
+
int main(int argc, char* argv[]) {
if (argc != 3) {
std::cerr << "Usage: \n";
diff --git a/example/tutorial/CMakeLists.txt b/example/tutorial/CMakeLists.txt
index e72cce7..11daf16 100644
--- a/example/tutorial/CMakeLists.txt
+++ b/example/tutorial/CMakeLists.txt
@@ -1,6 +1,6 @@
if (BUILD_MOCKTRACER AND BUILD_SHARED_LIBS)
include_directories(../../mocktracer/include)
add_executable(tutorial-example tutorial-example.cpp)
- target_link_libraries(tutorial-example opentracing_mocktracer)
- add_test(tutorial-example tutorial-example)
+ target_link_libraries(tutorial-example opentracing_mocktracer)
+ add_test(NAME tutorial-example COMMAND tutorial-example)
endif()
diff --git a/include/opentracing/dynamic_load.h b/include/opentracing/dynamic_load.h
index 1d265ef..6d11e54 100644
--- a/include/opentracing/dynamic_load.h
+++ b/include/opentracing/dynamic_load.h
@@ -1,6 +1,7 @@
#ifndef OPENTRACING_DYNAMIC_LOAD_H
#define OPENTRACING_DYNAMIC_LOAD_H
+#include
#include
#include
#include
@@ -35,14 +36,37 @@
// assert(error_category != nullptr);
// std::error_code error{rcode, *error_category};
// }
-extern "C" {
-#ifdef OPENTRACING_BUILD_DYNAMIC_LOADING
-int __attribute((weak))
-OpenTracingMakeTracerFactory(const char* opentracing_version,
- const void** error_category,
- void** tracer_factory);
+
+using OpenTracingMakeTracerFactoryType = int(const char* opentracing_version,
+ const void** error_category,
+ void** tracer_factory);
+
+#ifdef WIN32
+
+#define OPENTRACING_DECLARE_IMPL_FACTORY(X) \
+ extern "C" { \
+ \
+extern __declspec(dllexport) \
+ OpenTracingMakeTracerFactoryType* const OpenTracingMakeTracerFactory; \
+ \
+__declspec(selectany) OpenTracingMakeTracerFactoryType* const \
+ OpenTracingMakeTracerFactory = X; \
+ } // extern "C"
+
+#else
+
+#define OPENTRACING_DECLARE_IMPL_FACTORY(X) \
+ extern "C" { \
+ \
+__attribute((weak)) extern OpenTracingMakeTracerFactoryType* const \
+ OpenTracingMakeTracerFactory; \
+ \
+ OpenTracingMakeTracerFactoryType* const OpenTracingMakeTracerFactory = X; \
+ } // extern "C"
+
#endif
-} // extern "C"
+
+
namespace opentracing {
BEGIN_OPENTRACING_ABI_NAMESPACE
@@ -52,7 +76,7 @@ BEGIN_OPENTRACING_ABI_NAMESPACE
// See
// http://blog.think-async.com/2010/04/system-error-support-in-c0x-part-1.html
// https://ned14.github.io/boost.outcome/md_doc_md_03-tutorial_b.html
-const std::error_category& dynamic_load_error_category();
+OPENTRACING_API const std::error_category& dynamic_load_error_category();
// `dynamic_load_failure_error` occurs when dynamically loading a tracer library
// fails. Possible reasons could be the library doesn't exist or it is missing
@@ -117,7 +141,8 @@ class DynamicTracingLibraryHandle {
// }
//
// See DynamicTracingLibraryHandle, TracerFactory
-expected DynamicallyLoadTracingLibrary(
+OPENTRACING_API expected
+DynamicallyLoadTracingLibrary(
const char* shared_library, std::string& error_message) noexcept;
END_OPENTRACING_ABI_NAMESPACE
} // namespace opentracing
diff --git a/include/opentracing/ext/tags.h b/include/opentracing/ext/tags.h
index 9918c26..cd4c140 100644
--- a/include/opentracing/ext/tags.h
+++ b/include/opentracing/ext/tags.h
@@ -1,6 +1,7 @@
#ifndef OPENTRACING_EXT_TAGS_H
#define OPENTRACING_EXT_TAGS_H
+#include
#include
#include
@@ -19,13 +20,13 @@ namespace ext {
// ---------------------------------------------------------------------------
// span_kind hints at relationship between spans, e.g. client/server
// ---------------------------------------------------------------------------
-extern const opentracing::string_view span_kind;
+OPENTRACING_API extern const opentracing::string_view span_kind;
// Marks a span representing the client-side of an RPC or other remote call
-extern const opentracing::string_view span_kind_rpc_client;
+OPENTRACING_API extern const opentracing::string_view span_kind_rpc_client;
// Marks a span representing the server-side of an RPC or other remote call
-extern const opentracing::string_view span_kind_rpc_server;
+OPENTRACING_API extern const opentracing::string_view span_kind_rpc_server;
// ---------------------------------------------------------------------------
// error indicates whether a Span ended in an error state.
diff --git a/include/opentracing/noop.h b/include/opentracing/noop.h
index 9509c90..5313489 100644
--- a/include/opentracing/noop.h
+++ b/include/opentracing/noop.h
@@ -1,6 +1,7 @@
#ifndef OPENTRACING_NOOP_H
#define OPENTRACING_NOOP_H
+#include
#include
#include
#include
@@ -20,7 +21,7 @@ BEGIN_OPENTRACING_ABI_NAMESPACE
// (see Tracer::Global and Tracer::InitGlobal functions).
//
// WARNING: NoopTracer does not support baggage propagation.
-std::shared_ptr MakeNoopTracer() noexcept;
+OPENTRACING_API std::shared_ptr MakeNoopTracer() noexcept;
END_OPENTRACING_ABI_NAMESPACE
} // namespace opentracing
diff --git a/include/opentracing/propagation.h b/include/opentracing/propagation.h
index 923cb16..bb889c5 100644
--- a/include/opentracing/propagation.h
+++ b/include/opentracing/propagation.h
@@ -1,6 +1,7 @@
#ifndef OPENTRACING_PROPAGATION_H
#define OPENTRACING_PROPAGATION_H
+#include
#include
#include
#include
@@ -62,7 +63,7 @@ enum class SpanReferenceType {
// See
// http://blog.think-async.com/2010/04/system-error-support-in-c0x-part-1.html
// https://ned14.github.io/boost.outcome/md_doc_md_03-tutorial_b.html
-const std::error_category& propagation_error_category();
+OPENTRACING_API const std::error_category& propagation_error_category();
// `invalid_span_context_error` occurs when Tracer::Inject() is asked to operate
// on a SpanContext which it is not prepared to handle (for example, since it
diff --git a/include/opentracing/symbols.h b/include/opentracing/symbols.h
new file mode 100644
index 0000000..d34f473
--- /dev/null
+++ b/include/opentracing/symbols.h
@@ -0,0 +1,34 @@
+#ifndef OPENTRACING_SYMBOLS_H
+#define OPENTRACING_SYMBOLS_H
+
+#include
+
+#ifdef _MSC_VER
+#pragma warning(push)
+#pragma warning(disable : 4251)
+#endif
+
+#ifdef _MSC_VER
+
+#define OPENTRACING_EXPORT __declspec(dllexport)
+
+// Export if this is our own source, otherwise import:
+#ifndef OPENTRACING_STATIC
+#ifdef OPENTRACING_EXPORTS
+#define OPENTRACING_API __declspec(dllexport)
+#else // OPENTRACING_STATIC
+#define OPENTRACING_API __declspec(dllimport)
+#endif // OPENTRACING_EXPORTS
+#endif // OPENTRACING_STATIC
+
+#endif // _MSC_VER
+
+#ifndef OPENTRACING_EXPORT
+#define OPENTRACING_EXPORT
+#endif
+
+#ifndef OPENTRACING_API
+#define OPENTRACING_API
+#endif
+
+#endif // OPENTRACING_SYMBOLS_H
diff --git a/include/opentracing/tracer.h b/include/opentracing/tracer.h
index b085dee..2beadab 100644
--- a/include/opentracing/tracer.h
+++ b/include/opentracing/tracer.h
@@ -1,6 +1,7 @@
#ifndef OPENTRACING_TRACER_H
#define OPENTRACING_TRACER_H
+#include
#include
#include
#include
@@ -57,7 +58,7 @@ class StartSpanOption {
// Tracer is a simple, thin interface for Span creation and SpanContext
// propagation.
-class Tracer {
+class OPENTRACING_API Tracer {
public:
virtual ~Tracer() = default;
diff --git a/include/opentracing/tracer_factory.h b/include/opentracing/tracer_factory.h
index c2d0354..622fa5b 100644
--- a/include/opentracing/tracer_factory.h
+++ b/include/opentracing/tracer_factory.h
@@ -1,6 +1,7 @@
#ifndef OPENTRACING_TRACER_FACTORY_H
#define OPENTRACING_TRACER_FACTORY_H
+#include
#include
#include
@@ -11,7 +12,7 @@ BEGIN_OPENTRACING_ABI_NAMESPACE
// See
// http://blog.think-async.com/2010/04/system-error-support-in-c0x-part-1.html
// https://ned14.github.io/boost.outcome/md_doc_md_03-tutorial_b.html
-const std::error_category& tracer_factory_error_category();
+OPENTRACING_API const std::error_category& tracer_factory_error_category();
// `configuration_parse_error` occurs when the configuration string used to
// construct a tracer does not adhere to the expected format.
@@ -24,7 +25,7 @@ const std::error_code invalid_configuration_error(
2, tracer_factory_error_category());
// TracerFactory constructs tracers from configuration strings.
-class TracerFactory {
+class OPENTRACING_API TracerFactory {
public:
virtual ~TracerFactory() = default;
diff --git a/mocktracer/CMakeLists.txt b/mocktracer/CMakeLists.txt
index 57076cd..5165744 100644
--- a/mocktracer/CMakeLists.txt
+++ b/mocktracer/CMakeLists.txt
@@ -16,15 +16,22 @@ if (BUILD_SHARED_LIBS)
target_include_directories(opentracing_mocktracer INTERFACE "$")
set_target_properties(opentracing_mocktracer PROPERTIES VERSION ${OPENTRACING_VERSION_STRING}
SOVERSION ${OPENTRACING_VERSION_MAJOR})
- target_link_libraries(opentracing_mocktracer opentracing)
+ target_link_libraries(opentracing_mocktracer PUBLIC opentracing)
+ target_compile_definitions(opentracing_mocktracer PRIVATE OPENTRACING_MOCK_TRACER_EXPORTS)
install(TARGETS opentracing_mocktracer EXPORT OpenTracingTargets
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
+
+
endif()
if (BUILD_STATIC_LIBS)
add_library(opentracing_mocktracer-static STATIC ${SRCS})
- set_target_properties(opentracing_mocktracer-static PROPERTIES OUTPUT_NAME opentracing_mocktracer)
+ # Windows generates a lib and dll files for a shared library. using the same name will override the lib file generated by the shared target
+ if (NOT WIN32)
+ set_target_properties(opentracing_mocktracer-static PROPERTIES OUTPUT_NAME opentracing_mocktracer)
+ endif()
+ target_compile_definitions(opentracing_mocktracer-static PRIVATE OPENTRACING_MOCK_TRACER_STATIC)
target_include_directories(opentracing_mocktracer-static INTERFACE "$")
target_link_libraries(opentracing_mocktracer-static opentracing-static)
install(TARGETS opentracing_mocktracer-static EXPORT OpenTracingTargets
diff --git a/mocktracer/include/opentracing/mocktracer/in_memory_recorder.h b/mocktracer/include/opentracing/mocktracer/in_memory_recorder.h
index b379e86..709816d 100644
--- a/mocktracer/include/opentracing/mocktracer/in_memory_recorder.h
+++ b/mocktracer/include/opentracing/mocktracer/in_memory_recorder.h
@@ -1,6 +1,7 @@
#ifndef OPENTRACING_MOCKTRACER_IN_MEMORY_RECORDER_H
#define OPENTRACING_MOCKTRACER_IN_MEMORY_RECORDER_H
+#include
#include
#include
#include
@@ -9,7 +10,7 @@ namespace opentracing {
BEGIN_OPENTRACING_ABI_NAMESPACE
namespace mocktracer {
// InMemoryRecorder stores finished spans and provides accessors to them.
-class InMemoryRecorder : public Recorder {
+class OPENTRACING_MOCK_TRACER_API InMemoryRecorder : public Recorder {
public:
void RecordSpan(SpanData&& span_data) noexcept override;
diff --git a/mocktracer/include/opentracing/mocktracer/json.h b/mocktracer/include/opentracing/mocktracer/json.h
index 99f42a3..d80dde1 100644
--- a/mocktracer/include/opentracing/mocktracer/json.h
+++ b/mocktracer/include/opentracing/mocktracer/json.h
@@ -1,6 +1,7 @@
#ifndef OPENTRACING_MOCKTRACER_JSON_H
#define OPENTRACING_MOCKTRACER_JSON_H
+#include
#include
#include
@@ -8,7 +9,7 @@ namespace opentracing {
BEGIN_OPENTRACING_ABI_NAMESPACE
namespace mocktracer {
// Serialize provided spans to JSON.
-void ToJson(std::ostream& writer, const std::vector& spans);
+OPENTRACING_MOCK_TRACER_API void ToJson(std::ostream& writer, const std::vector& spans);
} // namespace mocktracer
END_OPENTRACING_ABI_NAMESPACE
} // namespace opentracing
diff --git a/mocktracer/include/opentracing/mocktracer/json_recorder.h b/mocktracer/include/opentracing/mocktracer/json_recorder.h
index b452a94..cca55aa 100644
--- a/mocktracer/include/opentracing/mocktracer/json_recorder.h
+++ b/mocktracer/include/opentracing/mocktracer/json_recorder.h
@@ -1,6 +1,7 @@
#ifndef OPENTRACING_MOCKTRACER_JSON_RECORDER_H
#define OPENTRACING_MOCKTRACER_JSON_RECORDER_H
+#include
#include
#include
#include
@@ -14,7 +15,7 @@ namespace mocktracer {
// format.
//
// See also FromJson.
-class JsonRecorder : public Recorder {
+class OPENTRACING_MOCK_TRACER_API JsonRecorder : public Recorder {
public:
explicit JsonRecorder(std::unique_ptr&& out);
diff --git a/mocktracer/include/opentracing/mocktracer/recorder.h b/mocktracer/include/opentracing/mocktracer/recorder.h
index 3104c94..d6b8554 100644
--- a/mocktracer/include/opentracing/mocktracer/recorder.h
+++ b/mocktracer/include/opentracing/mocktracer/recorder.h
@@ -1,6 +1,7 @@
#ifndef OPENTRACING_MOCKTRACER_RECORDER_H
#define OPENTRACING_MOCKTRACER_RECORDER_H
+#include
#include
#include
@@ -70,7 +71,7 @@ inline bool operator!=(const SpanData& lhs, const SpanData& rhs) {
std::ostream& operator<<(std::ostream& out, const SpanData& span_data);
-class Recorder {
+class OPENTRACING_MOCK_TRACER_API Recorder {
public:
virtual ~Recorder() = default;
diff --git a/mocktracer/include/opentracing/mocktracer/symbols.h b/mocktracer/include/opentracing/mocktracer/symbols.h
new file mode 100644
index 0000000..9c63628
--- /dev/null
+++ b/mocktracer/include/opentracing/mocktracer/symbols.h
@@ -0,0 +1,21 @@
+#ifndef OPENTRACING_MOCK_TRACER_SYMBOLS_H
+#define OPENTRACING_MOCK_TRACER_SYMBOLS_H
+
+#include
+
+#ifdef _MSC_VER
+// Export if this is our own source, otherwise import:
+#ifndef OPENTRACING_MOCK_TRACER_STATIC
+#ifdef OPENTRACING_MOCK_TRACER_EXPORTS
+#define OPENTRACING_MOCK_TRACER_API __declspec(dllexport)
+#else
+#define OPENTRACING_MOCK_TRACER_API __declspec(dllimport)
+#endif
+#endif
+#endif // _MSC_VER
+
+#ifndef OPENTRACING_MOCK_TRACER_API
+#define OPENTRACING_MOCK_TRACER_API
+#endif
+
+#endif // OPENTRACING_SYMBOLS_H
diff --git a/mocktracer/include/opentracing/mocktracer/tracer.h b/mocktracer/include/opentracing/mocktracer/tracer.h
index 646375d..63af2cb 100644
--- a/mocktracer/include/opentracing/mocktracer/tracer.h
+++ b/mocktracer/include/opentracing/mocktracer/tracer.h
@@ -1,6 +1,7 @@
#ifndef OPENTRACING_MOCKTRACER_TRACER_H
#define OPENTRACING_MOCKTRACER_TRACER_H
+#include
#include
#include
#include