EthExecutableHelper.cmake 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #
  2. # this function requires the following variables to be specified:
  3. # ETH_VERSION
  4. # PROJECT_NAME
  5. # PROJECT_VERSION
  6. # PROJECT_COPYRIGHT_YEAR
  7. # PROJECT_VENDOR
  8. # PROJECT_DOMAIN_SECOND
  9. # PROJECT_DOMAIN_FIRST
  10. # SRC_LIST
  11. # HEADERS
  12. #
  13. # params:
  14. # ICON
  15. #
  16. macro(eth_add_executable EXECUTABLE)
  17. set (extra_macro_args ${ARGN})
  18. set (options)
  19. set (one_value_args ICON)
  20. set (multi_value_args UI_RESOURCES WIN_RESOURCES)
  21. cmake_parse_arguments (ETH_ADD_EXECUTABLE "${options}" "${one_value_args}" "${multi_value_args}" "${extra_macro_args}")
  22. if (APPLE)
  23. add_executable(${EXECUTABLE} MACOSX_BUNDLE ${SRC_LIST} ${HEADERS} ${ETH_ADD_EXECUTABLE_UI_RESOURCES})
  24. set(PROJECT_VERSION "${ETH_VERSION}")
  25. set(MACOSX_BUNDLE_INFO_STRING "${PROJECT_NAME} ${PROJECT_VERSION}")
  26. set(MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_NAME} ${PROJECT_VERSION}")
  27. set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_NAME} ${PROJECT_VERSION}")
  28. set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}")
  29. set(MACOSX_BUNDLE_COPYRIGHT "${PROJECT_COPYRIGHT_YEAR} ${PROJECT_VENDOR}")
  30. set(MACOSX_BUNDLE_GUI_IDENTIFIER "${PROJECT_DOMAIN_SECOND}.${PROJECT_DOMAIN_FIRST}")
  31. set(MACOSX_BUNDLE_BUNDLE_NAME ${EXECUTABLE})
  32. set(MACOSX_BUNDLE_ICON_FILE ${ETH_ADD_EXECUTABLE_ICON})
  33. set_target_properties(${EXECUTABLE} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/EthereumMacOSXBundleInfo.plist.in")
  34. set_source_files_properties(${EXECUTABLE} PROPERTIES MACOSX_PACKAGE_LOCATION MacOS)
  35. set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/${MACOSX_BUNDLE_ICON_FILE}.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
  36. else ()
  37. add_executable(${EXECUTABLE} ${ETH_ADD_EXECUTABLE_UI_RESOURCES} ${ETH_ADD_EXECUTABLE_WIN_RESOURCES} ${SRC_LIST} ${HEADERS})
  38. endif()
  39. endmacro()
  40. macro(eth_simple_add_executable EXECUTABLE)
  41. add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS})
  42. # Apple does not support statically linked binaries on OS X. That means
  43. # that we can only statically link against our external libraries, but
  44. # we cannot statically link against the C++ runtime libraries and other
  45. # platform libraries (as is possible on Windows and Alpine Linux) to produce
  46. # an entirely transportable binary.
  47. #
  48. # See https://developer.apple.com/library/mac/qa/qa1118/_index.html for more info.
  49. #
  50. # GLIBC also appears not to support static linkage too, which probably means that
  51. # Debian and Ubuntu will only be able to do partially-statically linked
  52. # executables too, just like OS X.
  53. #
  54. # For OS X, at the time of writing, we are left with the following dynamically
  55. # linked dependencies, of which curl and libz might still be fixable:
  56. #
  57. # /usr/lib/libc++.1.dylib
  58. # /usr/lib/libSystem.B.dylib
  59. # /usr/lib/libcurl.4.dylib
  60. # /usr/lib/libz.1.dylib
  61. #
  62. if (STATIC_LINKING AND NOT APPLE)
  63. set(CMAKE_EXE_LINKER_FLAGS "-static ${CMAKE_EXE_LINKER_FLAGS}")
  64. set_target_properties(${EXECUTABLE} PROPERTIES LINK_SEARCH_START_STATIC 1)
  65. set_target_properties(${EXECUTABLE} PROPERTIES LINK_SEARCH_END_STATIC 1)
  66. endif()
  67. endmacro()
  68. macro(eth_copy_dll EXECUTABLE DLL)
  69. # dlls must be unsubstitud list variable (without ${}) in format
  70. # optimized;path_to_dll.dll;debug;path_to_dlld.dll
  71. if(DEFINED MSVC)
  72. list(GET ${DLL} 1 DLL_RELEASE)
  73. list(GET ${DLL} 3 DLL_DEBUG)
  74. add_custom_command(TARGET ${EXECUTABLE}
  75. PRE_BUILD
  76. COMMAND ${CMAKE_COMMAND} ARGS
  77. -DDLL_RELEASE="${DLL_RELEASE}"
  78. -DDLL_DEBUG="${DLL_DEBUG}"
  79. -DCONF="$<CONFIGURATION>"
  80. -DDESTINATION="${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
  81. -P "${ETH_SCRIPTS_DIR}/copydlls.cmake"
  82. )
  83. endif()
  84. endmacro()
  85. macro(eth_copy_dlls EXECUTABLE)
  86. foreach(dll ${ARGN})
  87. eth_copy_dll(${EXECUTABLE} ${dll})
  88. endforeach(dll)
  89. endmacro()
  90. macro(eth_install_executable EXECUTABLE)
  91. if (APPLE)
  92. # TODO - Why is this different than the branch Linux below, which has the RUNTIME keyword too?
  93. install(TARGETS ${EXECUTABLE} DESTINATION bin)
  94. elseif (MSVC)
  95. set(COMPONENT ${EXECUTABLE})
  96. install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Debug/"
  97. DESTINATION .
  98. CONFIGURATIONS Debug
  99. COMPONENT ${COMPONENT}
  100. )
  101. install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Release/"
  102. DESTINATION .
  103. CONFIGURATIONS Release
  104. COMPONENT ${COMPONENT}
  105. )
  106. install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo/"
  107. DESTINATION .
  108. CONFIGURATIONS RelWithDebInfo
  109. COMPONENT ${COMPONENT}
  110. )
  111. else()
  112. install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin)
  113. endif ()
  114. endmacro()
  115. macro (eth_name KEY VALUE)
  116. if (NOT (APPLE OR WIN32))
  117. string(TOLOWER ${VALUE} LVALUE )
  118. set(${KEY} ${LVALUE})
  119. else()
  120. set(${KEY} ${VALUE})
  121. endif()
  122. endmacro()
  123. macro(jsonrpcstub_client_create EXECUTABLE SPEC CLIENTNAME CLIENTDIR CLIENTFILENAME)
  124. if (ETH_JSON_RPC_STUB)
  125. add_custom_target(${SPEC}stub)
  126. add_custom_command(
  127. TARGET ${SPEC}stub
  128. POST_BUILD
  129. DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${SPEC}"
  130. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  131. COMMAND ${CMAKE_COMMAND} -DETH_SPEC_PATH="${CMAKE_CURRENT_SOURCE_DIR}/${SPEC}" -DETH_SOURCE_DIR="${CMAKE_SOURCE_DIR}" -DETH_CMAKE_DIR="${ETH_CMAKE_DIR}"
  132. -DETH_CLIENT_DIR="${CLIENTDIR}"
  133. -DETH_CLIENT_NAME=${CLIENTNAME}
  134. -DETH_CLIENT_FILENAME=${CLIENTFILENAME}
  135. -DETH_JSON_RPC_STUB="${ETH_JSON_RPC_STUB}"
  136. -P "${ETH_SCRIPTS_DIR}/jsonrpcstub.cmake"
  137. )
  138. add_dependencies(${EXECUTABLE} ${SPEC}stub)
  139. endif ()
  140. endmacro()
  141. macro(jsonrpcstub_create EXECUTABLE SPEC SERVERNAME SERVERDIR SERVERFILENAME CLIENTNAME CLIENTDIR CLIENTFILENAME)
  142. if (ETH_JSON_RPC_STUB)
  143. add_custom_target(${SPEC}stub)
  144. add_custom_command(
  145. TARGET ${SPEC}stub
  146. POST_BUILD
  147. DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${SPEC}"
  148. WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
  149. COMMAND ${CMAKE_COMMAND} -DETH_SPEC_PATH="${CMAKE_CURRENT_SOURCE_DIR}/${SPEC}" -DETH_SOURCE_DIR="${CMAKE_SOURCE_DIR}" -DETH_CMAKE_DIR="${ETH_CMAKE_DIR}"
  150. -DETH_CLIENT_DIR="${CLIENTDIR}"
  151. -DETH_CLIENT_NAME=${CLIENTNAME}
  152. -DETH_CLIENT_FILENAME=${CLIENTFILENAME}
  153. -DETH_SERVER_DIR="${SERVERDIR}"
  154. -DETH_SERVER_NAME=${SERVERNAME}
  155. -DETH_SERVER_FILENAME=${SERVERFILENAME}
  156. -DETH_JSON_RPC_STUB="${ETH_JSON_RPC_STUB}"
  157. -P "${ETH_SCRIPTS_DIR}/jsonrpcstub.cmake"
  158. )
  159. add_dependencies(${EXECUTABLE} ${SPEC}stub)
  160. endif ()
  161. endmacro()