summaryrefslogtreecommitdiff
blob: 9b0d3284dc483e28a1b4fe7fad56e7cbcb1235e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
From c8d1cd6465d8d64a23a111edb5fba67565660fe8 Mon Sep 17 00:00:00 2001
From: James Le Cuirot <chewi@gentoo.org>
Date: Sun, 27 Feb 2022 22:51:18 +0000
Subject: [PATCH 2/3] Allow building against the system JsonCpp library

`USE_INTERNAL_JSONCPP` defaults to true and ignores `USE_INTERNAL_LIBS`
because users are unlikely to have it installed.

More recent versions of JsonCpp require C++11, but Odamex targets C++98
for compatibility with older platforms. The standard is therefore only
changed to C++11 when `USE_INTERNAL_JSONCPP` is false, and only for the
server where JsonCpp is used. Note that C++11 still works when building
against an older JsonCpp version.

Tested against JsonCpp 1.9.5 on Gentoo Linux.

Closes: https://github.com/odamex/odamex/issues/261
(cherry picked from commit 5162c6297c7177af907e5e0502eac9d59ffcc22b)
---
 CMakeLists.txt           |  1 +
 libraries/CMakeLists.txt |  2 +-
 server/CMakeLists.txt    | 15 ++++++++++++++-
 3 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index c43c9f111..9353d0c6b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,6 +42,7 @@ option(USE_INTERNAL_DEUTEX "Use internal DeuTex" ${USE_INTERNAL_LIBS})
 cmake_dependent_option( USE_INTERNAL_ZLIB "Use internal zlib" ${USE_INTERNAL_LIBS} BUILD_CLIENT 0 )
 cmake_dependent_option( USE_INTERNAL_PNG "Use internal libpng" ${USE_INTERNAL_LIBS} BUILD_CLIENT 0 )
 cmake_dependent_option( USE_INTERNAL_CURL "Use internal libcurl" ${USE_INTERNAL_LIBS} BUILD_CLIENT 0 )
+cmake_dependent_option( USE_INTERNAL_JSONCPP "Use internal JsonCpp" 1 BUILD_SERVER 0 )
 cmake_dependent_option( USE_INTERNAL_WXWIDGETS "Use internal wxWidgets" ${USE_INTERNAL_LIBS} BUILD_LAUNCHER 0 )
 cmake_dependent_option( ENABLE_PORTMIDI "Enable portmidi support" 1 BUILD_CLIENT 0 )
 cmake_dependent_option( USE_MINIUPNP "Build with UPnP support" 1 BUILD_SERVER 0 )
diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt
index ae7db4c86..493d8f12b 100644
--- a/libraries/CMakeLists.txt
+++ b/libraries/CMakeLists.txt
@@ -295,7 +295,7 @@ endif()
 
 ### JsonCpp ###
 
-if(BUILD_SERVER)
+if(BUILD_SERVER AND USE_INTERNAL_JSONCPP)
   message(STATUS "Compiling JsonCpp...")
 
   # Figure out the correct library path to attach to our imported target
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
index 32297080f..a9bf8c44d 100644
--- a/server/CMakeLists.txt
+++ b/server/CMakeLists.txt
@@ -45,7 +45,12 @@ endif()
 add_executable(odasrv
   ${COMMON_SOURCES} ${SERVER_SOURCES} ${SERVER_WIN32_SOURCES})
 odamex_target_settings(odasrv)
-set_property(TARGET odasrv PROPERTY CXX_STANDARD 98)
+
+if(USE_INTERNAL_JSONCPP)
+  set_property(TARGET odasrv PROPERTY CXX_STANDARD 98)
+else()
+  set_property(TARGET odasrv PROPERTY CXX_STANDARD 11)
+endif()
 
 target_include_directories(odasrv PRIVATE src)
 if(WIN32)
@@ -53,6 +58,14 @@ if(WIN32)
 endif()
 target_link_libraries(odasrv ZLIB::ZLIB jsoncpp odamex-common odaproto)
 
+if(USE_INTERNAL_JSONCPP)
+  target_link_libraries(odasrv jsoncpp)
+else()
+  find_package(PkgConfig REQUIRED)
+  pkg_check_modules(JSONCPP jsoncpp REQUIRED IMPORTED_TARGET)
+  target_link_libraries(odasrv PkgConfig::JSONCPP)
+endif()
+
 if(USE_MINIUPNP)
   if(USE_INTERNAL_MINIUPNP)
     target_link_libraries(odasrv upnpc-static)
-- 
2.34.1