Skip to content

Commit 43bc0eb

Browse files
authored
Merge pull request #341 from ferdnyc/system-jsoncpp
Build: prefer system-installed JsonCpp by default, with bundled fallback
2 parents afc8974 + 2560409 commit 43bc0eb

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed

src/CMakeLists.txt

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ include(FeatureSummary)
3232

3333
################ OPTIONS ##################
3434
# Optional build settings for libopenshot
35-
OPTION(USE_SYSTEM_JSONCPP "Use system installed JsonCpp" OFF)
35+
option(USE_SYSTEM_JSONCPP "Use system installed JsonCpp, if found" ON)
36+
option(DISABLE_BUNDLED_JSONCPP "Don't fall back to bundled JsonCpp" OFF)
3637
option(ENABLE_IWYU "Enable 'Include What You Use' scanner (CMake 3.3+)" OFF)
3738

3839
################ WINDOWS ##################
@@ -149,18 +150,6 @@ if (RESVG_FOUND)
149150
SET(CMAKE_SWIG_FLAGS "-DUSE_RESVG=1")
150151
endif(RESVG_FOUND)
151152

152-
################### JSONCPP #####################
153-
# Include jsoncpp headers (needed for JSON parsing)
154-
if (USE_SYSTEM_JSONCPP)
155-
message(STATUS "Discovering system JsonCPP (USE_SYSTEM_JSONCPP enabled)")
156-
find_package(JsonCpp REQUIRED)
157-
include_directories(${JSONCPP_INCLUDE_DIRS})
158-
message(STATUS "Discovering system JsonCPP - done")
159-
else()
160-
message(STATUS "Using embedded JsonCpp (USE_SYSTEM_JSONCPP not enabled)")
161-
include_directories("../thirdparty/jsoncpp")
162-
endif(USE_SYSTEM_JSONCPP)
163-
164153
############### PROFILING #################
165154
#set(PROFILER "/usr/lib/libprofiler.so.0.3.2")
166155
#set(PROFILER "/usr/lib/libtcmalloc.so.4")
@@ -236,12 +225,6 @@ SET ( OPENSHOT_SOURCE_FILES
236225
${QT_PLAYER_FILES}
237226
${MOC_FILES})
238227

239-
IF (NOT USE_SYSTEM_JSONCPP)
240-
# Third Party JSON Parser
241-
SET ( OPENSHOT_SOURCE_FILES ${OPENSHOT_SOURCE_FILES}
242-
../thirdparty/jsoncpp/jsoncpp.cpp )
243-
ENDIF (NOT USE_SYSTEM_JSONCPP)
244-
245228
# ImageMagic related files
246229
IF (ImageMagick_FOUND)
247230
SET ( OPENSHOT_SOURCE_FILES ${OPENSHOT_SOURCE_FILES}
@@ -280,6 +263,43 @@ set_target_properties(openshot
280263
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib"
281264
)
282265

266+
################### JSONCPP #####################
267+
# Include jsoncpp headers (needed for JSON parsing)
268+
if (USE_SYSTEM_JSONCPP)
269+
message(STATUS "Looking for system JsonCpp")
270+
find_package(JsonCpp)
271+
if (JSONCPP_FOUND AND NOT TARGET jsoncpp_lib)
272+
# Create the expected target, for older installs that don't
273+
add_library(jsoncpp_lib INTERFACE)
274+
target_include_directories(jsoncpp_lib INTERFACE
275+
${JSONCPP_INCLUDE_DIRS})
276+
target_link_libraries(jsoncpp_lib INTERFACE ${JSONCPP_LIBRARY})
277+
endif ()
278+
endif ()
279+
280+
if (NOT JSONCPP_FOUND AND NOT DISABLE_BUNDLED_JSONCPP)
281+
message(STATUS "Using embedded JsonCpp (not found or USE_SYSTEM_JSONCPP disabled)")
282+
if (NOT TARGET jsoncpp_lib)
283+
add_library(jsoncpp_lib INTERFACE)
284+
target_include_directories(jsoncpp_lib INTERFACE
285+
"${PROJECT_SOURCE_DIR}/thirdparty/jsoncpp")
286+
target_sources(jsoncpp_lib INTERFACE "${PROJECT_SOURCE_DIR}/thirdparty/jsoncpp/jsoncpp.cpp")
287+
# Because this satisfies the requirement, an installed JsonCpp is optional
288+
set_package_properties(JsonCpp PROPERTIES TYPE OPTIONAL)
289+
endif ()
290+
add_feature_info("JsonCpp (embedded)" TRUE "JsonCpp will be compiled from the bundled sources")
291+
endif ()
292+
293+
if (JSONCPP_FOUND)
294+
# JsonCpp is actually required, even though we probe for it optionally
295+
# (This tells feature_summary() to bail if it's not found, later)
296+
set_package_properties(JsonCpp PROPERTIES TYPE REQUIRED)
297+
endif ()
298+
299+
# If we found any usable JsonCpp, use it. Otherwise, bail.
300+
if (TARGET jsoncpp_lib)
301+
target_link_libraries(openshot PUBLIC jsoncpp_lib)
302+
endif ()
283303

284304
################### FFMPEG #####################
285305
# Find FFmpeg libraries (used for video encoding / decoding)
@@ -291,6 +311,7 @@ foreach(ff_comp avcodec avdevice avformat avfilter avutil postproc swscale swres
291311
endif()
292312
endforeach()
293313

314+
294315
################### OPENMP #####################
295316
# Check for OpenMP (used for multi-core processing)
296317

@@ -315,7 +336,6 @@ SET ( REQUIRED_LIBRARIES
315336
${LIBOPENSHOT_AUDIO_LIBRARIES}
316337
${QT_LIBRARIES}
317338
${PROFILER}
318-
${JSONCPP_LIBRARY}
319339
${ZMQ_LIBRARIES}
320340
)
321341

@@ -384,9 +404,8 @@ add_subdirectory(bindings)
384404
########### PRINT FEATURE SUMMARY ##############
385405
feature_summary(WHAT ALL
386406
INCLUDE_QUIET_PACKAGES
387-
DESCRIPTION "Build configuration:"
388-
VAR featuresText)
389-
message("\n${featuresText}")
407+
FATAL_ON_MISSING_REQUIRED_PACKAGES
408+
DESCRIPTION "Displaying feature summary\n\nBuild configuration:")
390409

391410
############### INSTALL HEADERS & LIBRARY ################
392411
set(LIB_INSTALL_DIR lib${LIB_SUFFIX}) # determine correct lib folder

tests/CMakeLists.txt

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,6 @@ if (RESVG_FOUND)
137137
include_directories(${RESVG_INCLUDE_DIRS})
138138
endif(RESVG_FOUND)
139139

140-
################### JSONCPP #####################
141-
# Include jsoncpp headers (needed for JSON parsing)
142-
if (USE_SYSTEM_JSONCPP)
143-
find_package(JsonCpp REQUIRED)
144-
include_directories(${JSONCPP_INCLUDE_DIRS})
145-
else()
146-
include_directories("../thirdparty/jsoncpp")
147-
endif(USE_SYSTEM_JSONCPP)
148140

149141
############### SET TEST SOURCE FILES #################
150142
SET ( OPENSHOT_TEST_FILES

0 commit comments

Comments
 (0)