Skip to content

Commit f8ab4df

Browse files
authored
Make inclusion of jsoncpp source optional (#50)
1 parent ea4ad5b commit f8ab4df

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ include(CTest)
1010

1111
set(WERROR true CACHE BOOL "Enable warnings as errors.")
1212
set(WALL true CACHE BOOL "Enable all warnings.")
13+
set(INCLUDE_JSONCPP true CACHE BOOL "Include jsoncpp source")
1314
set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
1415

1516
if(NOT WIN32)
@@ -34,6 +35,14 @@ if(USE_CPPRESTSDK)
3435
set(CPPREST_LIB "cpprestsdk::cpprest")
3536
endif()
3637

38+
if(NOT INCLUDE_JSONCPP)
39+
find_package(jsoncpp REQUIRED)
40+
# jsoncpp has different target names depending on whether it
41+
# was built as a shared or static library. We make this override-able
42+
# so we can be resilient to the changes between versions.
43+
set(JSONCPP_LIB "jsoncpp_lib" CACHE STRING "jsoncpp target name")
44+
endif()
45+
3746
include_directories (include)
3847

3948
# TODO: We shouldn't use this, it makes the dll/lib export all symbols

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Below are instructions to build on different OS's. You can also use the followin
2121
| -DBUILD_SAMPLES | Build the included sample project | false |
2222
| -DBUILD_TESTING | Builds the test project | true |
2323
| -DUSE_CPPRESTSDK | Includes the CppRestSDK (default http stack) | false |
24+
| -DINCLUDE_JSONCPP | Builds jsoncpp source code as part of the output binary | true |
2425
| -DWERROR | Enables warnings as errors | true |
2526
| -DWALL | Enables all warnings | true |
2627
| -DINJECT_HEADER_AFTER_STDAFX=`<header path>` | Adds the provided header to the library compilation in stdafx.cpp, intended to allow "new" and "delete" to be replaced. | `<none>` |

src/signalrclient/CMakeLists.txt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,11 @@ set (SOURCES
2222
websocket_transport.cpp
2323
../../third_party_code/cpprestsdk/uri.cpp
2424
../../third_party_code/cpprestsdk/uri_builder.cpp
25-
../../third_party_code/jsoncpp/jsoncpp.cpp
2625
)
2726

2827
include_directories(
29-
../../third_party_code/cpprestsdk
30-
../../third_party_code/jsoncpp)
28+
../../third_party_code/cpprestsdk
29+
)
3130

3231
add_library (signalrclient ${SOURCES})
3332

@@ -61,6 +60,13 @@ else()
6160
target_compile_options(signalrclient PRIVATE -Wextra -Wpedantic -Wno-unknown-pragmas)
6261
endif()
6362

63+
if(INCLUDE_JSONCPP)
64+
target_sources(signalrclient PRIVATE ../../third_party_code/jsoncpp/jsoncpp.cpp)
65+
target_include_directories(signalrclient PRIVATE ../../third_party_code/jsoncpp)
66+
else()
67+
target_link_libraries(signalrclient PUBLIC ${JSONCPP_LIB})
68+
endif()
69+
6470
if(NOT USE_CPPRESTSDK)
6571
target_link_libraries(signalrclient)
6672
else()

0 commit comments

Comments
 (0)