Skip to content
Snippets Groups Projects
Commit f7dfe9c9 authored by Ben Boeckel's avatar Ben Boeckel
Browse files

FindJsonCpp: add imported targets

parent bbf5fdb8
No related branches found
No related tags found
No related merge requests found
# Find the JsonCpp include files and library.
#
# JsonCpp is a C++ library that can read/write JSON (JavaScript Object Notation)
# documents. See http://jsoncpp.sourceforge.net/ for more details.
#
# This module defines:
# JsonCpp_INCLUDE_DIRS - where to find json/json.h
# JsonCpp_LIBRARIES - the libraries to link against to use JsonCpp
# JsonCpp_FOUND - if false the library was not found.
find_path(JsonCpp_INCLUDE_DIR "json/json.h"
PATH_SUFFIXES "jsoncpp"
DOC "Specify the JsonCpp include directory here")
DOC "jsoncpp include directory")
mark_as_advanced(JsonCpp_INCLUDE_DIR)
find_library(JsonCpp_LIBRARY
NAMES jsoncpp
PATHS
DOC "Specify the JsonCpp library here")
set(JsonCpp_INCLUDE_DIRS ${JsonCpp_INCLUDE_DIR})
set(JsonCpp_LIBRARIES "${JsonCpp_LIBRARY}")
set(_JsonCpp_version_args)
if (EXISTS "${JsonCpp_INCLUDE_DIR}/json/version.h")
file(STRINGS "${JsonCpp_INCLUDE_DIR}/json/version.h" _JsonCpp_version_contents REGEX "JSONCPP_VERSION_[A-Z]+")
foreach (_JsonCpp_version_part MAJOR MINOR PATCH)
string(REGEX REPLACE ".*# *define +JSONCPP_VERSION_${_JsonCpp_version_part} +([0-9]+).*" "\\1" JsonCpp_VERSION_${_JsonCpp_version_part} "${_JsonCpp_version_contents}")
endforeach ()
set(JsonCpp_VERSION_STRING "${JsonCpp_VERSION_MAJOR}.${JsonCpp_VERSION_MINOR}.${JsonCpp_VERSION_PATCH}")
DOC "jsoncpp library")
mark_as_advanced(JsonCpp_LIBRARY)
set(_JsonCpp_version_args VERSION_VAR JsonCpp_VERSION_STRING)
if (JsonCpp_INCLUDE_DIR AND EXISTS "${JsonCpp_INCLUDE_DIR}/json/version.h")
file(STRINGS "${JsonCpp_INCLUDE_DIR}/json/version.h" _JsonCpp_version_lines
REGEX "JSONCPP_VERSION_[A-Z]+")
string(REGEX REPLACE ".*# *define +JSONCPP_VERSION_MAJOR +([0-9]+).*" "\\1" _JsonCpp_version_major "${_JsonCpp_version_lines}")
string(REGEX REPLACE ".*# *define +JSONCPP_VERSION_MINOR +([0-9]+).*" "\\1" _JsonCpp_version_minor "${_JsonCpp_version_lines}")
string(REGEX REPLACE ".*# *define +JSONCPP_VERSION_PATCH +([0-9]+).*" "\\1" _JsonCpp_version_patch "${_JsonCpp_version_lines}")
set(JsonCpp_VERSION "${_JsonCpp_version_major}.${_JsonCpp_version_minor}.${_JsonCpp_version_patch}")
unset(_JsonCpp_version_major)
unset(_JsonCpp_version_minor)
unset(_JsonCpp_version_patch)
unset(_JsonCpp_version_lines)
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(JsonCpp
REQUIRED_VARS JsonCpp_LIBRARIES JsonCpp_INCLUDE_DIRS
${_JsonCpp_version_args})
REQUIRED_VARS JsonCpp_LIBRARY JsonCpp_INCLUDE_DIR
VERSION_VAR JsonCpp_VERSION)
mark_as_advanced(JsonCpp_INCLUDE_DIR JsonCpp_LIBRARY)
if (JsonCpp_FOUND)
set(JsonCpp_INCLUDE_DIRS "${JsonCpp_INCLUDE_DIR}")
set(JsonCpp_LIBRARIES "${JsonCpp_LIBRARY}")
if (NOT TARGET JsonCpp::JsonCpp)
include(vtkDetectLibraryType)
vtk_detect_library_type(jsoncpp_library_type
PATH "${JsonCpp_LIBRARY}")
add_library(JsonCpp::JsonCpp "${jsoncpp_library_type}" IMPORTED)
unset(jsoncpp_library_type)
set_target_properties(JsonCpp::JsonCpp PROPERTIES
IMPORTED_LOCATION "${JsonCpp_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${JsonCpp_INCLUDE_DIR}")
endif ()
endif ()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment