aboutsummaryrefslogtreecommitdiffstats
path: root/cmake/EthExecutableHelper.cmake
blob: 921b37e7742c3409d16014ecd90e2bc8f2a0937f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#
# this function requires the following variables to be specified:
# ETH_VERSION
# PROJECT_NAME
# PROJECT_VERSION
# PROJECT_COPYRIGHT_YEAR
# PROJECT_VENDOR
# PROJECT_DOMAIN_SECOND
# PROJECT_DOMAIN_FIRST
# SRC_LIST
# HEADERS
#
# params:
# ICON
#

macro(eth_add_executable EXECUTABLE)
    set (extra_macro_args ${ARGN})
    set (options)
    set (one_value_args ICON)
    set (multi_value_args UI_RESOURCES WIN_RESOURCES)
    cmake_parse_arguments (ETH_ADD_EXECUTABLE "${options}" "${one_value_args}" "${multi_value_args}" "${extra_macro_args}")

    if (APPLE)

        add_executable(${EXECUTABLE} MACOSX_BUNDLE ${SRC_LIST} ${HEADERS} ${ETH_ADD_EXECUTABLE_UI_RESOURCES})
        set(PROJECT_VERSION "${ETH_VERSION}")
        set(MACOSX_BUNDLE_INFO_STRING "${PROJECT_NAME} ${PROJECT_VERSION}")
        set(MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_NAME} ${PROJECT_VERSION}")
        set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_NAME} ${PROJECT_VERSION}")
        set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION}")
        set(MACOSX_BUNDLE_COPYRIGHT "${PROJECT_COPYRIGHT_YEAR} ${PROJECT_VENDOR}")
        set(MACOSX_BUNDLE_GUI_IDENTIFIER "${PROJECT_DOMAIN_SECOND}.${PROJECT_DOMAIN_FIRST}")
        set(MACOSX_BUNDLE_BUNDLE_NAME ${EXECUTABLE})
        set(MACOSX_BUNDLE_ICON_FILE ${ETH_ADD_EXECUTABLE_ICON})
        set_target_properties(${EXECUTABLE} PROPERTIES MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/EthereumMacOSXBundleInfo.plist.in")
        set_source_files_properties(${EXECUTABLE} PROPERTIES MACOSX_PACKAGE_LOCATION MacOS)
        set_source_files_properties("${CMAKE_CURRENT_SOURCE_DIR}/${MACOSX_BUNDLE_ICON_FILE}.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)

    else ()
        add_executable(${EXECUTABLE} ${ETH_ADD_EXECUTABLE_UI_RESOURCES}  ${ETH_ADD_EXECUTABLE_WIN_RESOURCES} ${SRC_LIST} ${HEADERS})
    endif()

endmacro()

macro(eth_simple_add_executable EXECUTABLE)
    add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS})

    # Apple does not support statically linked binaries on OS X.   That means
    # that we can only statically link against our external libraries, but
    # we cannot statically link against the C++ runtime libraries and other
    # platform libraries (as is possible on Windows and Alpine Linux) to produce
    # an entirely transportable binary.
    #
    # See https://developer.apple.com/library/mac/qa/qa1118/_index.html for more info.
    #
    # GLIBC also appears not to support static linkage too, which probably means that
    # Debian and Ubuntu will only be able to do partially-statically linked
    # executables too, just like OS X.
    #
    # For OS X, at the time of writing, we are left with the following dynamically
    # linked dependencies, of which curl and libz might still be fixable:
    #
    # /usr/lib/libc++.1.dylib
    # /usr/lib/libSystem.B.dylib
    # /usr/lib/libcurl.4.dylib
    # /usr/lib/libz.1.dylib
    #
    if (STATIC_LINKING AND NOT APPLE)
        set(CMAKE_EXE_LINKER_FLAGS "-static ${CMAKE_EXE_LINKER_FLAGS}")
        set_target_properties(${EXECUTABLE} PROPERTIES LINK_SEARCH_START_STATIC 1)
        set_target_properties(${EXECUTABLE} PROPERTIES LINK_SEARCH_END_STATIC 1)
    endif()
endmacro()

macro(eth_copy_dll EXECUTABLE DLL)
    # dlls must be unsubstitud list variable (without ${}) in format
    # optimized;path_to_dll.dll;debug;path_to_dlld.dll
    if(DEFINED MSVC)
        list(GET ${DLL} 1 DLL_RELEASE)
        list(GET ${DLL} 3 DLL_DEBUG)
        add_custom_command(TARGET ${EXECUTABLE}
            PRE_BUILD
            COMMAND ${CMAKE_COMMAND} ARGS
            -DDLL_RELEASE="${DLL_RELEASE}"
            -DDLL_DEBUG="${DLL_DEBUG}"
            -DCONF="$<CONFIGURATION>"
            -DDESTINATION="${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}"
            -P "${ETH_SCRIPTS_DIR}/copydlls.cmake"
        )
    endif()
endmacro()

macro(eth_copy_dlls EXECUTABLE)
    foreach(dll ${ARGN})
        eth_copy_dll(${EXECUTABLE} ${dll})
    endforeach(dll)
endmacro()


macro(eth_install_executable EXECUTABLE)

    if (APPLE)

        # TODO - Why is this different than the branch Linux below, which has the RUNTIME keyword too?
        install(TARGETS ${EXECUTABLE} DESTINATION bin)

    elseif (DEFINED MSVC)

        set(COMPONENT ${EXECUTABLE})

        install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Debug/"
            DESTINATION .
            CONFIGURATIONS Debug
            COMPONENT ${COMPONENT}
        )

        install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/Release/"
            DESTINATION .
            CONFIGURATIONS Release
            COMPONENT ${COMPONENT}
        )

        install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/RelWithDebInfo/"
            DESTINATION .
            CONFIGURATIONS RelWithDebInfo
            COMPONENT ${COMPONENT}
        )

    else()
        install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin)
    endif ()

endmacro()

macro (eth_name KEY VALUE)
    if (NOT (APPLE OR WIN32))
        string(TOLOWER ${VALUE} LVALUE )
        set(${KEY} ${LVALUE})
    else()
        set(${KEY} ${VALUE})
    endif()
endmacro()

macro(jsonrpcstub_client_create SPEC CLIENTNAME CLIENTDIR CLIENTFILENAME)
    if (ETH_JSON_RPC_STUB)
        add_custom_target(${SPEC}stub)
        add_custom_command(
        TARGET ${SPEC}stub
        POST_BUILD
        DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${SPEC}"
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
        COMMAND ${CMAKE_COMMAND} -DETH_SPEC_PATH="${CMAKE_CURRENT_SOURCE_DIR}/${SPEC}" -DETH_SOURCE_DIR="${CMAKE_SOURCE_DIR}" -DETH_CMAKE_DIR="${ETH_CMAKE_DIR}"
            -DETH_CLIENT_DIR="${CLIENTDIR}"
            -DETH_CLIENT_NAME=${CLIENTNAME}
            -DETH_CLIENT_FILENAME=${CLIENTFILENAME}
            -DETH_JSON_RPC_STUB="${ETH_JSON_RPC_STUB}"
            -P "${ETH_SCRIPTS_DIR}/jsonrpcstub.cmake"
            )
        add_dependencies(${EXECUTABLE} ${SPEC}stub)
    endif ()
endmacro()

macro(jsonrpcstub_create SPEC SERVERNAME SERVERDIR SERVERFILENAME CLIENTNAME CLIENTDIR CLIENTFILENAME)
    if (ETH_JSON_RPC_STUB)
        add_custom_target(${SPEC}stub)
        add_custom_command(
        TARGET ${SPEC}stub
        POST_BUILD
        DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${SPEC}"
        WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
        COMMAND ${CMAKE_COMMAND} -DETH_SPEC_PATH="${CMAKE_CURRENT_SOURCE_DIR}/${SPEC}" -DETH_SOURCE_DIR="${CMAKE_SOURCE_DIR}" -DETH_CMAKE_DIR="${ETH_CMAKE_DIR}"
            -DETH_CLIENT_DIR="${CLIENTDIR}"
            -DETH_CLIENT_NAME=${CLIENTNAME}
            -DETH_CLIENT_FILENAME=${CLIENTFILENAME}
            -DETH_SERVER_DIR="${SERVERDIR}"
            -DETH_SERVER_NAME=${SERVERNAME}
            -DETH_SERVER_FILENAME=${SERVERFILENAME}
            -DETH_JSON_RPC_STUB="${ETH_JSON_RPC_STUB}"
            -P "${ETH_SCRIPTS_DIR}/jsonrpcstub.cmake"
            )
        add_dependencies(${EXECUTABLE} ${SPEC}stub)
    endif ()
endmacro()