EthDependencies.cmake 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. # all dependencies that are not directly included in the cpp-ethereum distribution are defined here
  2. # for this to work, download the dependency via the cmake script in extdep or install them manually!
  3. function(eth_show_dependency DEP NAME)
  4. get_property(DISPLAYED GLOBAL PROPERTY ETH_${DEP}_DISPLAYED)
  5. if (NOT DISPLAYED)
  6. set_property(GLOBAL PROPERTY ETH_${DEP}_DISPLAYED TRUE)
  7. message(STATUS "${NAME} headers: ${${DEP}_INCLUDE_DIRS}")
  8. message(STATUS "${NAME} lib : ${${DEP}_LIBRARIES}")
  9. if (NOT("${${DEP}_DLLS}" STREQUAL ""))
  10. message(STATUS "${NAME} dll : ${${DEP}_DLLS}")
  11. endif()
  12. endif()
  13. endfunction()
  14. # The Windows platform has not historically had any standard packaging system for delivering
  15. # versioned releases of libraries. Homebrew and PPA perform that function for macOS and Ubuntu
  16. # respectively, and there are analogous standards for other Linux distros. In the absense of
  17. # such a standard, we have chosen to make a "fake packaging system" for cpp-ethereum, which is
  18. # implemented in https://github.com/ethereum/cpp-dependencies.
  19. #
  20. # NOTE - In the last couple of years, the NuGet packaging system, first created for delivery
  21. # of .NET packages, has added support for C++ packages, and it may be possible for us to migrate
  22. # our "fake package server" to that real package server. That would certainly be preferable
  23. # to rolling our own, but it also puts us at the mercy of intermediate package maintainers who
  24. # may be inactive. There is not a fantastic range of packages available at the time of writing,
  25. # so we might find that such a move turns us into becoming the package maintainer for our
  26. # dependencies. Not a net win :-)
  27. #
  28. # "Windows - Try to use NuGet C++ packages"
  29. # https://github.com/ethereum/webthree-umbrella/issues/509
  30. #
  31. # Perhaps a better alternative is to step away from dependencies onto binary releases entirely,
  32. # and switching to build-from-source for some (or all) of our dependencies, especially if they
  33. # are small. That gives us total control, but at the cost of longer build times. That is the
  34. # approach which Pawel has taken for LLVM in https://github.com/ethereum/evmjit.
  35. # boilerplate macros for some code editors
  36. add_definitions(-DETH_TRUE)
  37. # custom cmake scripts
  38. set(ETH_CMAKE_DIR ${CMAKE_CURRENT_LIST_DIR})
  39. set(ETH_SCRIPTS_DIR ${ETH_CMAKE_DIR}/scripts)
  40. find_program(CTEST_COMMAND ctest)
  41. # Use the dynamic libraries for Boost for Linux and static linkage on Windows and macOS.
  42. # We would like to use static linkage on Linux too, but on Ubuntu at least it appears that
  43. # the prebuilt binaries for Boost won't support this.
  44. #
  45. # We will need to build Boost from source ourselves, with -fPIC enabled, before we are
  46. # able to remove this conditional. That is exactly what has been happening for months for
  47. # the doublethinkco cross-builds (see https://github.com/doublethinkco/cpp-ethereum-cross).
  48. #
  49. # Typical build error we get if trying to do static Boost on Ubunty Trusty (many of them):
  50. #
  51. # Linking CXX shared library libdevcore.so
  52. # /usr/bin/ld.gold: error: /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/
  53. # libboost_thread.a(thread.o): requires dynamic R_X86_64_32 reloc which may overflow at
  54. # runtime; recompile with -fPIC
  55. #
  56. # https://travis-ci.org/bobsummerwill/cpp-ethereum/jobs/145955041
  57. if (UNIX AND NOT APPLE)
  58. set(Boost_USE_STATIC_LIBS OFF)
  59. else()
  60. set(Boost_USE_STATIC_LIBS ON)
  61. endif()
  62. # We have work-in-progress here to support building cpp-ethereum with static-linkage, which
  63. # provides a fantastic end-user experience. You have entirely standalone executables
  64. # which are entirely atomic and "just work". They contain everything you need and talk directly
  65. # to the operating system kernel. Such linkage also allow best-possible dead-code removal and
  66. # global optimizations. That is the model which is used by default for all golang apps.
  67. #
  68. # "Enable static build of binaries"
  69. # https://github.com/ethereum/webthree-umbrella/issues/495
  70. #
  71. # So we just have `geth` and `geth.exe`. This mode lets you have an `eth` which works just
  72. # the same. This approach is a particular benefit on Linux where there is huge fragmentation
  73. # of packaging systems and .so versioning across distros. Building a standalone executable
  74. # for Linux which "just works" on all distros would be a huge win. This mode allows just
  75. # that to happen already on Alpine Linux using the musl standard library, and I hope we can
  76. # extend that support to further distros in the near future.
  77. #
  78. # We also have partial support for static linkage on macOS, though we would only be able to
  79. # statically link the external dependencies above the kernel. Anything which is part of the
  80. # operating system itself can only be used via dylibs. Still, we can improve things a lot.
  81. #
  82. # This is a macOS operating system constraint.
  83. #
  84. # See https://developer.apple.com/library/mac/qa/qa1118/_index.html
  85. #
  86. # "Apple does not support statically linked binaries on Mac OS X. A statically linked binary
  87. # assumes binary compatibility at the kernel system call interface, and we do not make any
  88. # guarantees on that front. Rather, we strive to ensure binary compatibility in each
  89. # dynamically linked system library and framework."
  90. set(STATIC_LINKING FALSE CACHE BOOL "Build static binaries")
  91. if (STATIC_LINKING)
  92. set(Boost_USE_STATIC_RUNTIME ON)
  93. set(OpenSSL_USE_STATIC_LIBS ON)
  94. if (MSVC)
  95. # TODO - Why would we need .a on Windows? Maybe some Cygwin-ism.
  96. # When I work through Windows static linkage, I will remove this,
  97. # if that is possible.
  98. set(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a ${CMAKE_FIND_LIBRARY_SUFFIXES})
  99. elseif (APPLE)
  100. # At the time of writing, we are still only PARTIALLY statically linked
  101. # on OS X, with a mixture of statically linked external libraries where
  102. # those are available, and dynamically linked where that is the only
  103. # option we have. Ultimately, the aim would be for everything except
  104. # the runtime libraries to be statically linked.
  105. #
  106. # Still TODO:
  107. # - json-rpc-cpp
  108. # - leveldb (which pulls in snappy, for the dylib at ;east)
  109. # - miniupnp
  110. # - gmp
  111. #
  112. # Two further libraries (curl and zlib) ship as dylibs with the platform
  113. # but again we could build from source and statically link these too.
  114. set(CMAKE_FIND_LIBRARY_SUFFIXES .a .dylib)
  115. else()
  116. set(CMAKE_FIND_LIBRARY_SUFFIXES .a)
  117. endif()
  118. set(ETH_STATIC ON)
  119. endif()
  120. include_directories(BEFORE "${PROJECT_BINARY_DIR}/include")
  121. function(eth_use TARGET REQUIRED)
  122. if (NOT TARGET ${TARGET})
  123. message(FATAL_ERROR "eth_use called for non existing target ${TARGET}")
  124. endif()
  125. if (TARGET ${PROJECT_NAME}_BuildInfo.h)
  126. add_dependencies(${TARGET} ${PROJECT_NAME}_BuildInfo.h)
  127. endif()
  128. foreach(MODULE ${ARGN})
  129. string(REPLACE "::" ";" MODULE_PARTS "${MODULE}")
  130. list(GET MODULE_PARTS 0 MODULE_MAIN)
  131. list(LENGTH MODULE_PARTS MODULE_LENGTH)
  132. if (MODULE_LENGTH GREATER 1)
  133. list(GET MODULE_PARTS 1 MODULE_SUB)
  134. endif()
  135. # TODO: check if file exists if not, throws FATAL_ERROR with detailed description
  136. get_target_property(TARGET_APPLIED ${TARGET} TARGET_APPLIED_${MODULE_MAIN}_${MODULE_SUB})
  137. if (NOT TARGET_APPLIED)
  138. include(Use${MODULE_MAIN})
  139. set_target_properties(${TARGET} PROPERTIES TARGET_APPLIED_${MODULE_MAIN}_${MODULE_SUB} TRUE)
  140. eth_apply(${TARGET} ${REQUIRED} ${MODULE_SUB})
  141. endif()
  142. endforeach()
  143. endfunction()