jsonrpc.cmake 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. if (NOT TARGET jsoncpp-project)
  2. # Include jsoncpp dependency if not included yet.
  3. message("we don't have jsoncpp.")
  4. include(${CMAKE_CURRENT_LIST_DIR}/jsoncpp.cmake)
  5. endif()
  6. # HTTP client from JSON RPC CPP requires curl library. It can find it itself,
  7. # but we need to know the libcurl location for static linking.
  8. find_package(CURL REQUIRED)
  9. # HTTP server from JSON RPC CPP requires microhttpd library. It can find it itself,
  10. # but we need to know the MHD location for static linking.
  11. find_package(MHD REQUIRED)
  12. set(CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
  13. -DCMAKE_BUILD_TYPE=Release
  14. # Build static lib but suitable to be included in a shared lib.
  15. -DCMAKE_POSITION_INDEPENDENT_CODE=On
  16. -DBUILD_STATIC_LIBS=On
  17. -DBUILD_SHARED_LIBS=Off
  18. -DUNIX_DOMAIN_SOCKET_SERVER=Off
  19. -DUNIX_DOMAIN_SOCKET_CLIENT=Off
  20. -DHTTP_SERVER=On
  21. -DHTTP_CLIENT=On
  22. -DCOMPILE_TESTS=Off
  23. -DCOMPILE_STUBGEN=Off
  24. -DCOMPILE_EXAMPLES=Off
  25. # Point to jsoncpp library.
  26. -DJSONCPP_INCLUDE_DIR=/usr/lib/x86_64-linux-gnu
  27. # Select jsoncpp include prefix: <json/...> or <jsoncpp/json/...>
  28. -DJSONCPP_INCLUDE_PREFIX=json
  29. -DJSONCPP_LIBRARY=/usr/lib/x86_64-linux-gnu/libjsonrpccpp-common.so
  30. -DCURL_INCLUDE_DIR=${CURL_INCLUDE_DIR}
  31. -DCURL_LIBRARY=${CURL_LIBRARY}
  32. -DMHD_INCLUDE_DIR=${MHD_INCLUDE_DIR}
  33. -DMHD_LIBRARY=${MHD_LIBRARY})
  34. #ExternalProject_Add(jsonrpc-project
  35. # PREFIX deps/jsonrpc
  36. # URL https://github.com/cinemast/libjson-rpc-cpp/archive/v0.7.0.tar.gz
  37. # URL_HASH SHA256=669c2259909f11a8c196923a910f9a16a8225ecc14e6c30e2bcb712bab9097eb
  38. # # On Windows it tries to install this dir. Create it to prevent failure.
  39. # PATCH_COMMAND cmake -E make_directory <SOURCE_DIR>/win32-deps/include
  40. # CMAKE_ARGS ${CMAKE_ARGS}
  41. # # Overwtire build and install commands to force Release build on MSVC.
  42. # BUILD_COMMAND cmake --build <BINARY_DIR> --config Release
  43. # INSTALL_COMMAND cmake --build <BINARY_DIR> --config Release --target install
  44. #)
  45. #add_dependencies(jsonrpc-project jsoncpp)
  46. # jsoncpp
  47. # Create jsonrpc imported libraries
  48. #ExternalProject_Get_Property(jsonrpc-project INSTALL_DIR)
  49. #set(JSONRPC_INCLUDE_DIR ${INSTALL_DIR}/include)
  50. #file(MAKE_DIRECTORY ${JSONRPC_INCLUDE_DIR}) # Must exist.
  51. # CMake Error at deps/jsonrpc.cmake:55 (file):
  52. set(JSONRPC_INCLUDE_DIR /usr/lib/x86_64-linux-gnu/ )
  53. # file problem creating directory: /include
  54. # INTERFACE_INCLUDE_DIRECTORIES.
  55. message("JSONRPC INCLUDE DIR:" ${JSONRPC_INCLUDE_DIR})
  56. message("CMAKE_CURRENT_LIST_DIR:" ${CMAKE_CURRENT_LIST_DIR})
  57. message("INTERFACE_INCLUDE_DIRECTORIES:" ${INTERFACE_INCLUDE_DIRECTORIES})
  58. message("CURL_INCLUDE_DIR:" ${CURL_INCLUDE_DIR})
  59. message("MHD_INCLUDE_DIR:" ${MHD_INCLUDE_DIR})
  60. add_library(jsonrpc::common STATIC IMPORTED)
  61. set_property(TARGET jsonrpc::common PROPERTY IMPORTED_LOCATION /usr/lib/x86_64-linux-gnu/jsonrpccpp-common${CMAKE_STATIC_LIBRARY_SUFFIX})
  62. set_property(TARGET jsonrpc::common PROPERTY INTERFACE_LINK_LIBRARIES jsoncpp)
  63. set_property(TARGET jsonrpc::common PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${JSONRPC_INCLUDE_DIR} ${JSONCPP_INCLUDE_DIR})
  64. add_dependencies(jsonrpc::common jsonrpc-project)
  65. add_library(jsonrpc::client STATIC IMPORTED)
  66. #set_property(TARGET jsonrpc::client PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}jsonrpccpp-client${CMAKE_STATIC_LIBRARY_SUFFIX})
  67. set_property(TARGET jsonrpc::client PROPERTY IMPORTED_LOCATION /usr/lib/x86_64-linux-gnu/jsonrpccpp-client${CMAKE_STATIC_LIBRARY_SUFFIX})
  68. set_property(TARGET jsonrpc::client PROPERTY INTERFACE_LINK_LIBRARIES jsonrpc::common ${CURL_LIBRARY})
  69. set_property(TARGET jsonrpc::client PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CURL_INCLUDE_DIR})
  70. add_dependencies(jsonrpc::client jsonrpc-project)
  71. add_library(jsonrpc::server STATIC IMPORTED)
  72. set_property(TARGET jsonrpc::server PROPERTY IMPORTED_LOCATION /usr/lib/x86_64-linux-gnu/jsonrpccpp-server${CMAKE_STATIC_LIBRARY_SUFFIX})
  73. set_property(TARGET jsonrpc::server PROPERTY INTERFACE_LINK_LIBRARIES jsonrpc::common ${MHD_LIBRARY})
  74. set_property(TARGET jsonrpc::server PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${MHD_INCLUDE_DIR})
  75. add_dependencies(jsonrpc::server jsonrpc-project)
  76. unset(INSTALL_DIR)
  77. unset(CMAKE_ARGS)