Skip to content

Commit d526b6b

Browse files
authored
Merge pull request #520 from 1480c1/nhjson
json: add support for using an external nlohmann_json
2 parents 9169430 + 3eef83d commit d526b6b

File tree

8 files changed

+37
-11
lines changed

8 files changed

+37
-11
lines changed

CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ set( VVENC_ENABLE_BUILD_TYPE_POSTFIX OFF CACHE BOOL "Enable or disable
173173

174174
set( VVENC_ENABLE_LINK_TIME_OPT ON CACHE BOOL "Enable link time optimization for release and profile builds" )
175175

176-
set( VVENC_ENABLE_THIRDPARTY_JSON ON CACHE BOOL "Enable use of thirdparty json library" )
176+
set( VVENC_ENABLE_THIRDPARTY_JSON ON CACHE STRING "Enable use of thirdparty json library, pass in SYSTEM to rely on an external nlohmann_json" )
177+
178+
set_property( CACHE VVENC_ENABLE_THIRDPARTY_JSON PROPERTY STRINGS OFF SYSTEM ON )
177179

178180
set( VVENC_INSTALL_FULLFEATURE_APP OFF CACHE BOOL "Install the full-feature app: vvencFFapp" )
179181

@@ -368,10 +370,20 @@ if( CCACHE_FOUND )
368370
set_property( GLOBAL PROPERTY RULE_LAUNCH_LINK ccache )
369371
endif()
370372

371-
373+
# handle thirdparty json
372374
if( VVENC_ENABLE_THIRDPARTY_JSON )
375+
string( TOUPPER "${VVENC_ENABLE_THIRDPARTY_JSON}" VVENC_ENABLE_THIRDPARTY_JSON )
376+
message( STATUS "VVENC_ENABLE_THIRDPARTY_JSON: ${VVENC_ENABLE_THIRDPARTY_JSON}" )
373377
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVVENC_ENABLE_THIRDPARTY_JSON" )
374378
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVVENC_ENABLE_THIRDPARTY_JSON" )
379+
if ( VVENC_ENABLE_THIRDPARTY_JSON STREQUAL "SYSTEM" )
380+
find_package( nlohmann_json REQUIRED ) # Provides nlohmann_json::nlohmann_json
381+
elseif( NOT TARGET nlohmann_json::nlohmann_json ) # Implies either ON, TRUE, or 1
382+
add_library( nlohmann_json::nlohmann_json INTERFACE IMPORTED )
383+
set_target_properties( nlohmann_json::nlohmann_json PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${PROJECT_SOURCE_DIR}/thirdparty/nlohmann_json/single_include )
384+
endif()
385+
else()
386+
message( STATUS "VVENC_ENABLE_THIRDPARTY_JSON is disabled" )
375387
endif()
376388

377389
# handle rpath correctly

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ ifneq ($(disable-lto),)
5050
CONFIG_OPTIONS += -DVVENC_ENABLE_LINK_TIME_OPT=OFF
5151
endif
5252

53-
ifneq ($(disable-json),)
54-
CONFIG_OPTIONS += -DVVENC_ENABLE_THIRDPARTY_JSON=OFF
53+
ifneq ($(enable-json),)
54+
CONFIG_OPTIONS += -DVVENC_ENABLE_THIRDPARTY_JSON=${enable-json}
5555
endif
5656

5757
ifneq ($(enable-build-type-postfix),)

source/App/vvencFFapp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ target_compile_options( ${EXE_NAME} PRIVATE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CX
3838

3939
target_include_directories( ${EXE_NAME} PRIVATE ../../Lib )
4040
target_link_libraries( ${EXE_NAME} Threads::Threads vvenc )
41+
if( TARGET nlohmann_json::nlohmann_json )
42+
target_link_libraries( ${EXE_NAME} nlohmann_json::nlohmann_json )
43+
endif()
4144

4245
# example: place header files in different folders
4346
source_group( "Header Files" FILES ${INC_FILES} )

source/App/vvencapp/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ target_compile_options( ${EXE_NAME} PRIVATE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CX
3535

3636
target_include_directories( ${EXE_NAME} PRIVATE ../../Lib )
3737
target_link_libraries( ${EXE_NAME} Threads::Threads vvenc )
38+
if( TARGET nlohmann_json::nlohmann_json )
39+
target_link_libraries( ${EXE_NAME} nlohmann_json::nlohmann_json )
40+
endif()
3841

3942
# example: place header files in different folders
4043
source_group( "Header Files" FILES ${INC_FILES} )

source/Lib/EncoderLib/RateCtrl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ POSSIBILITY OF SUCH DAMAGE.
4545
\brief Rate control manager class
4646
*/
4747
#ifdef VVENC_ENABLE_THIRDPARTY_JSON
48-
#include "nlohmann/json.hpp"
48+
#include <nlohmann/json.hpp>
4949
#endif
5050

5151
#include "vvenc/version.h"

source/Lib/apputils/LogoRenderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ POSSIBILITY OF SUCH DAMAGE.
5858
#include "FileIOHelper.h"
5959

6060
#ifdef VVENC_ENABLE_THIRDPARTY_JSON
61-
#include "../../../thirdparty/nlohmann_json/single_include/nlohmann/json.hpp"
61+
#include <nlohmann/json.hpp>
6262
using nlohmann::json;
6363
#endif
6464

source/Lib/vvenc/CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ if( VVENC_ENABLE_X86_SIMD )
134134
INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL OFF )
135135

136136
set_target_properties( ${LIB_NAME}_x86_simd PROPERTIES FOLDER lib )
137+
138+
if( TARGET nlohmann_json::nlohmann_json )
139+
target_link_libraries( ${LIB_NAME}_x86_simd PRIVATE nlohmann_json::nlohmann_json )
140+
endif()
137141
endif()
138142

139143
if( VVENC_ENABLE_ARM_SIMD )
@@ -170,6 +174,10 @@ if( VVENC_ENABLE_ARM_SIMD )
170174
INTERPROCEDURAL_OPTIMIZATION_MINSIZEREL OFF )
171175

172176
set_target_properties( ${LIB_NAME}_arm_simd PROPERTIES FOLDER lib )
177+
178+
if( TARGET nlohmann_json::nlohmann_json )
179+
target_link_libraries( ${LIB_NAME}_arm_simd PRIVATE nlohmann_json::nlohmann_json )
180+
endif()
173181
endif()
174182

175183
# set resource file for MSVC compilers
@@ -187,11 +195,8 @@ if( CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0 )
187195
target_compile_options( ${LIB_NAME} PRIVATE $<$<CXX_COMPILER_ID:GNU>: -Wno-array-bounds> )
188196
endif()
189197

190-
191-
if( VVENC_ENABLE_THIRDPARTY_JSON )
192-
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DVVENC_ENABLE_THIRDPARTY_JSON" )
193-
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DVVENC_ENABLE_THIRDPARTY_JSON" )
194-
target_include_directories( ${LIB_NAME} PRIVATE ../../../thirdparty/nlohmann_json/single_include )
198+
if( TARGET nlohmann_json::nlohmann_json )
199+
target_link_libraries( ${LIB_NAME} PRIVATE nlohmann_json::nlohmann_json )
195200
endif()
196201

197202
if( TARGET INTEL_ITT)

test/vvenc_unit_test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ target_compile_options( ${EXE_NAME} PRIVATE $<$<OR:$<CXX_COMPILER_ID:Clang>,$<CX
2828

2929
target_include_directories( ${EXE_NAME} PRIVATE ${VVENC_LIB_DIR} )
3030
target_link_libraries( ${EXE_NAME} Threads::Threads vvenc )
31+
if( TARGET nlohmann_json::nlohmann_json )
32+
target_link_libraries( ${EXE_NAME} nlohmann_json::nlohmann_json )
33+
endif()
3134
# example: place header files in different folders
3235
source_group( "Header Files" FILES ${INC_FILES} )
3336
source_group( "Resource Files" FILES ${RESOURCE_FILE} )

0 commit comments

Comments
 (0)