@@ -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 )
3637option (ENABLE_IWYU "Enable 'Include What You Use' scanner (CMake 3.3+)" OFF )
3738
3839################ WINDOWS ##################
@@ -122,19 +123,6 @@ IF (ENABLE_BLACKMAGIC)
122123 ENDIF (BLACKMAGIC_FOUND)
123124ENDIF (ENABLE_BLACKMAGIC)
124125
125- ################### ZEROMQ #####################
126- # Find ZeroMQ library (used for socket communication & logging)
127-
128- # Some platforms package the header-only cppzmq C++ bindings separately,
129- # others (Ubuntu) bundle them in with libzmq itself
130- find_package (cppzmq QUIET )
131- find_package (ZMQ REQUIRED)
132-
133- # Include ZeroMQ headers (needed for compile)
134- include_directories (${ZMQ_INCLUDE_DIRS} )
135- if (cppzmq_FOUND)
136- include_directories (${cppzmq_INCLUDE_DIRS} )
137- endif ()
138126
139127################### RESVG #####################
140128# Find resvg library (used for rendering svg files)
@@ -149,18 +137,6 @@ if (RESVG_FOUND)
149137 SET (CMAKE_SWIG_FLAGS "-DUSE_RESVG=1" )
150138endif (RESVG_FOUND)
151139
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-
164140############### PROFILING #################
165141#set(PROFILER "/usr/lib/libprofiler.so.0.3.2")
166142#set(PROFILER "/usr/lib/libtcmalloc.so.4")
@@ -236,12 +212,6 @@ SET ( OPENSHOT_SOURCE_FILES
236212 ${QT_PLAYER_FILES}
237213 ${MOC_FILES} )
238214
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-
245215# ImageMagic related files
246216IF (ImageMagick_FOUND)
247217 SET ( OPENSHOT_SOURCE_FILES ${OPENSHOT_SOURCE_FILES}
@@ -280,6 +250,44 @@ set_target_properties(openshot
280250 INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX} /lib"
281251 )
282252
253+ ################### JSONCPP #####################
254+ # Include jsoncpp headers (needed for JSON parsing)
255+ if (USE_SYSTEM_JSONCPP)
256+ message (STATUS "Looking for system JsonCpp" )
257+ find_package (JsonCpp)
258+ if (JSONCPP_FOUND AND NOT TARGET jsoncpp_lib)
259+ # Create the expected target, for older installs that don't
260+ add_library (jsoncpp_lib INTERFACE )
261+ target_include_directories (jsoncpp_lib INTERFACE
262+ ${JSONCPP_INCLUDE_DIRS} )
263+ target_link_libraries (jsoncpp_lib INTERFACE ${JSONCPP_LIBRARY} )
264+ endif ()
265+ endif ()
266+
267+ if (NOT JSONCPP_FOUND AND NOT DISABLE_BUNDLED_JSONCPP)
268+ message (STATUS "Using embedded JsonCpp (not found or USE_SYSTEM_JSONCPP disabled)" )
269+ if (NOT TARGET jsoncpp_lib)
270+ add_library (jsoncpp_lib INTERFACE )
271+ target_include_directories (jsoncpp_lib INTERFACE
272+ "${PROJECT_SOURCE_DIR} /thirdparty/jsoncpp" )
273+ target_sources (jsoncpp_lib INTERFACE "${PROJECT_SOURCE_DIR} /thirdparty/jsoncpp/jsoncpp.cpp" )
274+ # Because this satisfies the requirement, an installed JsonCpp is optional
275+ set_package_properties(JsonCpp PROPERTIES TYPE OPTIONAL )
276+ endif ()
277+ add_feature_info("JsonCpp (embedded)" TRUE "JsonCpp will be compiled from the bundled sources" )
278+ endif ()
279+
280+ if (JSONCPP_FOUND)
281+ # JsonCpp is actually required, even though we probe for it optionally
282+ # (This tells feature_summary() to bail if it's not found, later)
283+ set_package_properties(JsonCpp PROPERTIES TYPE REQUIRED)
284+ endif ()
285+
286+ # If we found any usable JsonCpp, use it. Otherwise, bail.
287+ if (TARGET jsoncpp_lib)
288+ target_link_libraries (openshot PUBLIC jsoncpp_lib)
289+ endif ()
290+
283291################### FFMPEG #####################
284292# Find FFmpeg libraries (used for video encoding / decoding)
285293FIND_PACKAGE (FFmpeg REQUIRED COMPONENTS avcodec avdevice avformat avutil swscale)
@@ -314,14 +322,26 @@ endif()
314322
315323target_link_libraries (openshot PUBLIC OpenMP::OpenMP_CXX)
316324
325+ ################### ZEROMQ #####################
326+ # Find ZeroMQ library (used for socket communication & logging)
327+ find_package (ZeroMQ REQUIRED) # Creates libzmq target
328+
329+ # Some platforms package the header-only cppzmq C++ bindings separately,
330+ # others (Ubuntu) bundle them in with libzmq itself
331+ find_package (cppzmq QUIET ) # Creates cppzmq target
332+
333+ # Include ZeroMQ headers (needed for compile)
334+ target_link_libraries (openshot PUBLIC libzmq)
335+ if (TARGET cppzmq)
336+ target_link_libraries (openshot PUBLIC cppzmq)
337+ endif ()
338+
317339
318340############### LINK LIBRARY #################
319341SET ( REQUIRED_LIBRARIES
320342 ${LIBOPENSHOT_AUDIO_LIBRARIES}
321343 ${QT_LIBRARIES}
322344 ${PROFILER}
323- ${JSONCPP_LIBRARY}
324- ${ZMQ_LIBRARIES}
325345 )
326346
327347IF (RESVG_FOUND)
@@ -389,9 +409,8 @@ add_subdirectory(bindings)
389409########### PRINT FEATURE SUMMARY ##############
390410feature_summary(WHAT ALL
391411 INCLUDE_QUIET_PACKAGES
392- DESCRIPTION "Build configuration:"
393- VAR featuresText)
394- message ("\n ${featuresText} " )
412+ FATAL_ON_MISSING_REQUIRED_PACKAGES
413+ DESCRIPTION "Displaying feature summary\n\n Build configuration:" )
395414
396415############### INSTALL HEADERS & LIBRARY ################
397416set (LIB_INSTALL_DIR lib${LIB_SUFFIX} ) # determine correct lib folder
0 commit comments