Add option to build CMake against a system jsoncpp

Create a CMAKE_USE_SYSTEM_JSONCPP option.
This commit is contained in:
Brad King 2015-01-20 10:31:13 -05:00
parent 17cfa09eb2
commit 27c6da933e
6 changed files with 40 additions and 7 deletions

View File

@ -65,7 +65,7 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
# Allow the user to enable/disable all system utility library options by # Allow the user to enable/disable all system utility library options by
# defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}. # defining CMAKE_USE_SYSTEM_LIBRARIES or CMAKE_USE_SYSTEM_LIBRARY_${util}.
set(UTILITIES BZIP2 CURL EXPAT FORM LIBARCHIVE LIBLZMA ZLIB) set(UTILITIES BZIP2 CURL EXPAT FORM JSONCPP LIBARCHIVE LIBLZMA ZLIB)
foreach(util ${UTILITIES}) foreach(util ${UTILITIES})
if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util} if(NOT DEFINED CMAKE_USE_SYSTEM_LIBRARY_${util}
AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES) AND DEFINED CMAKE_USE_SYSTEM_LIBRARIES)
@ -104,6 +104,7 @@ macro(CMAKE_HANDLE_SYSTEM_LIBRARIES)
CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma" CMAKE_DEPENDENT_OPTION(CMAKE_USE_SYSTEM_LIBLZMA "Use system-installed liblzma"
"${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON) "${CMAKE_USE_SYSTEM_LIBRARY_LIBLZMA}" "NOT CMAKE_USE_SYSTEM_LIBARCHIVE" ON)
option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}") option(CMAKE_USE_SYSTEM_FORM "Use system-installed libform" "${CMAKE_USE_SYSTEM_LIBRARY_FORM}")
option(CMAKE_USE_SYSTEM_JSONCPP "Use system-installed jsoncpp" "${CMAKE_USE_SYSTEM_LIBRARY_JSONCPP}")
# Mention to the user what system libraries are being used. # Mention to the user what system libraries are being used.
foreach(util ${UTILITIES}) foreach(util ${UTILITIES})
@ -373,8 +374,24 @@ macro (CMAKE_BUILD_UTILITIES)
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# Build jsoncpp library. # Build jsoncpp library.
add_subdirectory(Utilities/cmjsoncpp) if(CMAKE_USE_SYSTEM_JSONCPP)
CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty") if(EXISTS ${CMAKE_ROOT}/Modules/FindJsonCpp.cmake)
find_package(JsonCpp)
elseif(NOT CMAKE_VERSION VERSION_LESS 3.0)
include(${CMake_SOURCE_DIR}/Modules/FindJsonCpp.cmake)
else()
message(FATAL_ERROR "CMAKE_USE_SYSTEM_JSONCPP requires CMake >= 3.0")
endif()
if(NOT JsonCpp_FOUND)
message(FATAL_ERROR
"CMAKE_USE_SYSTEM_JSONCPP is ON but a JsonCpp is not found!")
endif()
set(CMAKE_JSONCPP_LIBRARIES JsonCpp::JsonCpp)
else()
set(CMAKE_JSONCPP_LIBRARIES cmjsoncpp)
add_subdirectory(Utilities/cmjsoncpp)
CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty")
endif()
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# Build XMLRPC library for CMake and CTest. # Build XMLRPC library for CMake and CTest.

View File

@ -503,7 +503,7 @@ target_link_libraries(CMakeLib cmsys
${CMAKE_EXPAT_LIBRARIES} ${CMAKE_ZLIB_LIBRARIES} ${CMAKE_EXPAT_LIBRARIES} ${CMAKE_ZLIB_LIBRARIES}
${CMAKE_TAR_LIBRARIES} ${CMAKE_COMPRESS_LIBRARIES} ${CMAKE_TAR_LIBRARIES} ${CMAKE_COMPRESS_LIBRARIES}
${CMAKE_CURL_LIBRARIES} ${CMAKE_CURL_LIBRARIES}
cmjsoncpp ${CMAKE_JSONCPP_LIBRARIES}
) )
# On Apple we need CoreFoundation # On Apple we need CoreFoundation

View File

@ -20,6 +20,7 @@
#cmakedefine CMAKE_USE_SYSTEM_LIBARCHIVE #cmakedefine CMAKE_USE_SYSTEM_LIBARCHIVE
#cmakedefine CMAKE_USE_SYSTEM_LIBLZMA #cmakedefine CMAKE_USE_SYSTEM_LIBLZMA
#cmakedefine CMAKE_USE_SYSTEM_FORM #cmakedefine CMAKE_USE_SYSTEM_FORM
#cmakedefine CMAKE_USE_SYSTEM_JSONCPP
#cmakedefine CTEST_USE_XMLRPC #cmakedefine CTEST_USE_XMLRPC
#endif #endif

View File

@ -13,6 +13,11 @@
#define cm_jsoncpp_reader_h #define cm_jsoncpp_reader_h
/* Use the jsoncpp library configured for CMake. */ /* Use the jsoncpp library configured for CMake. */
#include <cmjsoncpp/include/json/reader.h> #include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_JSONCPP
# include <json/reader.h>
#else
# include <cmjsoncpp/include/json/reader.h>
#endif
#endif #endif

View File

@ -13,6 +13,11 @@
#define cm_jsoncpp_value_h #define cm_jsoncpp_value_h
/* Use the jsoncpp library configured for CMake. */ /* Use the jsoncpp library configured for CMake. */
#include <cmjsoncpp/include/json/value.h> #include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_JSONCPP
# include <json/value.h>
#else
# include <cmjsoncpp/include/json/value.h>
#endif
#endif #endif

View File

@ -13,6 +13,11 @@
#define cm_jsoncpp_writer_h #define cm_jsoncpp_writer_h
/* Use the jsoncpp library configured for CMake. */ /* Use the jsoncpp library configured for CMake. */
#include <cmjsoncpp/include/json/writer.h> #include "cmThirdParty.h"
#ifdef CMAKE_USE_SYSTEM_JSONCPP
# include <json/writer.h>
#else
# include <cmjsoncpp/include/json/writer.h>
#endif
#endif #endif