| 1 | diff --git a/cmake/FindJsonCPP.cmake b/cmake/FindJsonCPP.cmake
|
| 2 | index 59e971a58..18260fde8 100644
|
| 3 | |
| 4 | |
| 5 | @@ -39,10 +39,11 @@
|
| 6 | # JsonCPP_FOUND - The jsoncpp library has been found
|
| 7 | # JsonCPP_TARGET - The name of the CMake target for the jsoncpp library
|
| 8 |
|
| 9 | +if(TARGET jsoncpp_lib OR TARGET jsoncpp_static OR TARGET PkgConfig::jsoncpp)
|
| 10 |
|
| 11 | -if(TARGET jsoncpp_lib OR TARGET jsoncpp_static)
|
| 12 | -
|
| 13 | - if(TARGET jsoncpp_lib)
|
| 14 | + if(TARGET PkgConfig::jsoncpp)
|
| 15 | + set(JsonCPP_TARGET PkgConfig::jsoncpp)
|
| 16 | + elseif(TARGET jsoncpp_lib)
|
| 17 | set(JsonCPP_TARGET jsoncpp_lib)
|
| 18 | else()
|
| 19 | set(JsonCPP_TARGET jsoncpp_static)
|
| 20 | @@ -57,24 +58,50 @@ if(TARGET jsoncpp_lib OR TARGET jsoncpp_static)
|
| 21 | mark_as_advanced(JsonCPP_TARGET)
|
| 22 |
|
| 23 | else()
|
| 24 | -
|
| 25 | - set(_OPTIONS "CONFIG")
|
| 26 | + find_package(PkgConfig QUIET)
|
| 27 | +
|
| 28 | + set(_OPTIONS1 "CONFIG")
|
| 29 | + set(_OPTIONS2 "IMPORTED_TARGET") # for pkg_check_modules fallback
|
| 30 | +
|
| 31 | if(JsonCPP_FIND_REQUIRED)
|
| 32 | - list(APPEND _OPTIONS "REQUIRED")
|
| 33 | - endif()
|
| 34 | - if(JsonCPP_FIND_QUIETLY)
|
| 35 | - list(APPEND _OPTIONS "QUIET")
|
| 36 | + if(PKG_CONFIG_FOUND)
|
| 37 | + list(APPEND _OPTIONS2 "REQUIRED")
|
| 38 | + else()
|
| 39 | + list(APPEND _OPTIONS1 "REQUIRED")
|
| 40 | + endif()
|
| 41 | endif()
|
| 42 | - if(JsonCPP_FIND_VERSION)
|
| 43 | - list(PREPEND _OPTIONS "${jsoncpp_FIND_VERSION}")
|
| 44 | + if(JsonCPP_FIND_QUIETLY)
|
| 45 | + list(APPEND _OPTIONS1 "QUIET")
|
| 46 | + list(APPEND _OPTIONS2 "QUIET")
|
| 47 | endif()
|
| 48 | - if(JsonCPP_FIND_EXACT)
|
| 49 | - list(APPEND _OPTIONS "EXACT")
|
| 50 | + if(PKG_CONFIG_FOUND)
|
| 51 | + if(JsonCPP_FIND_VERSION)
|
| 52 | + if(JsonCPP_FIND_EXACT)
|
| 53 | + list(APPEND _OPTIONS2 "jsoncpp=${JsonCPP_FIND_VERSION}")
|
| 54 | + else()
|
| 55 | + list(APPEND _OPTIONS2 "jsoncpp>=${JsonCPP_FIND_VERSION}")
|
| 56 | + endif()
|
| 57 | + else()
|
| 58 | + list(APPEND _OPTIONS2 "jsoncpp")
|
| 59 | + endif()
|
| 60 | + else()
|
| 61 | + if(JsonCPP_FIND_VERSION)
|
| 62 | + list(PREPEND _OPTIONS1 "${jsoncpp_FIND_VERSION}")
|
| 63 | + endif()
|
| 64 | + if(JsonCPP_FIND_EXACT)
|
| 65 | + list(APPEND _OPTIONS1 "EXACT")
|
| 66 | + endif()
|
| 67 | endif()
|
| 68 |
|
| 69 | - find_package(jsoncpp ${_OPTIONS})
|
| 70 | + find_package(jsoncpp ${_OPTIONS1})
|
| 71 | +
|
| 72 | + if(NOT JsonCPP_FOUND)
|
| 73 | + pkg_check_modules(jsoncpp ${_OPTIONS2})
|
| 74 | + endif()
|
| 75 |
|
| 76 | - if(TARGET jsoncpp_lib)
|
| 77 | + if(TARGET PkgConfig::jsoncpp)
|
| 78 | + set(JsonCPP_TARGET jsoncpp)
|
| 79 | + elseif(TARGET jsoncpp_lib)
|
| 80 | set(JsonCPP_TARGET jsoncpp_lib)
|
| 81 | else()
|
| 82 | set(JsonCPP_TARGET jsoncpp_static)
|