ZMQSourceRunChecks.cmake 6.65 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18


macro(zmq_check_sock_cloexec)
  message(STATUS "Checking whether SOCK_CLOEXEC is supported")
  check_c_source_runs(
    "
#include <sys/types.h>
#include <sys/socket.h>

int main(int argc, char *argv [])
{
    int s = socket(PF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0);
    return(s == -1);
}
"
    ZMQ_HAVE_SOCK_CLOEXEC)
endmacro()

19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
macro(zmq_check_efd_cloexec)
  message(STATUS "Checking whether EFD_CLOEXEC is supported")
  check_c_source_runs(
    "
#include <sys/eventfd.h>

int main(int argc, char *argv [])
{
    int s = eventfd (0, EFD_CLOEXEC);
    return(s == -1);
}
"
    ZMQ_HAVE_EVENTFD_CLOEXEC)
endmacro()

34 35 36 37 38 39 40 41 42 43
macro(zmq_check_o_cloexec)
  message(STATUS "Checking whether O_CLOEXEC is supported")
  check_c_source_runs(
    "
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char *argv [])
{
44
    int s = open (\"/dev/null\", O_CLOEXEC | O_RDONLY);
45
    return s == -1;
46 47 48 49 50
}
"
    ZMQ_HAVE_O_CLOEXEC)
endmacro()

51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
macro(zmq_check_so_bindtodevice)
  message(STATUS "Checking whether SO_BINDTODEVICE is supported")
  check_c_source_runs(
"
#include <sys/socket.h>

int main(int argc, char *argv [])
{
/* Actually making the setsockopt() call requires CAP_NET_RAW */
#ifndef SO_BINDTODEVICE
    return 1;
#else
    return 0;
#endif
}
"
    ZMQ_HAVE_SO_BINDTODEVICE)
endmacro()

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
# TCP keep-alives Checks.

macro(zmq_check_so_keepalive)
  message(STATUS "Checking whether SO_KEEPALIVE is supported")
  check_c_source_runs(
"
#include <sys/types.h>
#include <sys/socket.h>

int main(int argc, char *argv [])
{
    int s, rc, opt = 1;
    return(
       ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) ||
       ((rc = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,(char*) &opt, sizeof(int))) == -1)
    );
}
"
    ZMQ_HAVE_SO_KEEPALIVE)
endmacro()

macro(zmq_check_tcp_keepcnt)
  message(STATUS "Checking whether TCP_KEEPCNT is supported")
  check_c_source_runs(
    "
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

int main(int argc, char *argv [])
{
    int s, rc, opt = 1;
    return(
       ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) ||
       ((rc = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,(char*) &opt, sizeof(int))) == -1) ||
       ((rc = setsockopt(s, IPPROTO_TCP, TCP_KEEPCNT,(char*) &opt, sizeof(int))) == -1)
    );
}
"
    ZMQ_HAVE_TCP_KEEPCNT)
endmacro()

macro(zmq_check_tcp_keepidle)
  message(STATUS "Checking whether TCP_KEEPIDLE is supported")
  check_c_source_runs(
    "
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

int main(int argc, char *argv [])
{
    int s, rc, opt = 1;
    return(
       ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) ||
       ((rc = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,(char*) &opt, sizeof(int))) == -1) ||
       ((rc = setsockopt(s, IPPROTO_TCP, TCP_KEEPIDLE,(char*) &opt, sizeof(int))) == -1)
    );
}
"
    ZMQ_HAVE_TCP_KEEPIDLE)
endmacro()


macro(zmq_check_tcp_keepintvl)
  message(STATUS "Checking whether TCP_KEEPINTVL is supported")
  check_c_source_runs(
    "
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

int main(int argc, char *argv [])
{
    int s, rc, opt = 1;
    return(
       ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) ||
       ((rc = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,(char*) &opt, sizeof(int))) == -1) ||
       ((rc = setsockopt(s, IPPROTO_TCP, TCP_KEEPINTVL,(char*) &opt, sizeof(int))) == -1)
    );
}

"
    ZMQ_HAVE_TCP_KEEPINTVL)
endmacro()


macro(zmq_check_tcp_keepalive)
  message(STATUS "Checking whether TCP_KEEPALIVE is supported")
  check_c_source_runs(
    "
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>

int main(int argc, char *argv [])
{
    int s, rc, opt = 1;
    return(
       ((s = socket(PF_INET, SOCK_STREAM, 0)) == -1) ||
       ((rc = setsockopt(s, SOL_SOCKET, SO_KEEPALIVE,(char*) &opt, sizeof(int))) == -1) ||
       ((rc = setsockopt(s, IPPROTO_TCP, TCP_KEEPALIVE,(char*) &opt, sizeof(int))) == -1)
    );
}
"
    ZMQ_HAVE_TCP_KEEPALIVE)
endmacro()
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207


macro(zmq_check_tcp_tipc)
  message(STATUS "Checking whether TIPC is supported")
  check_c_source_runs(
    "
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/socket.h>
#include <linux/tipc.h>

int main(int argc, char *argv [])
{
    struct sockaddr_tipc topsrv;
    int sd = socket(AF_TIPC, SOCK_SEQPACKET, 0);
    memset(&topsrv, 0, sizeof(topsrv));
    topsrv.family = AF_TIPC;
    topsrv.addrtype = TIPC_ADDR_NAME;
    topsrv.addr.name.name.type = TIPC_TOP_SRV;
    topsrv.addr.name.name.instance = TIPC_TOP_SRV;
    fcntl(sd, F_SETFL, O_NONBLOCK);
}
"
    ZMQ_HAVE_TIPC)
endmacro()
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259


macro(zmq_check_pthread_setname)
  message(STATUS "Checking pthread_setname signature")
  set(SAVE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
  set(CMAKE_REQUIRED_FLAGS "-D_GNU_SOURCE -Werror -pthread")
  check_c_source_runs(
    "
#include <pthread.h>

int main(int argc, char *argv [])
{
    pthread_setname_np (\"foo\");
    return 0;
}
"
    ZMQ_HAVE_PTHREAD_SETNAME_1)
  check_c_source_runs(
    "
#include <pthread.h>

int main(int argc, char *argv [])
{
    pthread_setname_np (pthread_self(), \"foo\");
    return 0;
}
"
    ZMQ_HAVE_PTHREAD_SETNAME_2)
  check_c_source_runs(
    "
#include <pthread.h>

int main(int argc, char *argv [])
{
    pthread_setname_np (pthread_self(), \"foo\", (void *)0);
    return 0;
}
"
    ZMQ_HAVE_PTHREAD_SETNAME_3)
  check_c_source_runs(
    "
#include <pthread.h>

int main(int argc, char *argv [])
{
    pthread_set_name_np (pthread_self(), \"foo\");
    return 0;
}
"
    ZMQ_HAVE_PTHREAD_SET_NAME)
  set(CMAKE_REQUIRED_FLAGS ${SAVE_CMAKE_REQUIRED_FLAGS})
endmacro()
260

261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
macro(zmq_check_pthread_setaffinity)
  message(STATUS "Checking pthread_setaffinity signature")
  set(SAVE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
  set(CMAKE_REQUIRED_FLAGS "-D_GNU_SOURCE -Werror -pthread")
  check_c_source_runs(
    "
#include <pthread.h>

int main(int argc, char *argv [])
{
    cpu_set_t test; 
    pthread_setaffinity_np (pthread_self(), sizeof(cpu_set_t), &test);
    return 0;
}
"
276
    ZMQ_HAVE_PTHREAD_SET_AFFINITY)
277 278 279
  set(CMAKE_REQUIRED_FLAGS ${SAVE_CMAKE_REQUIRED_FLAGS})
endmacro()

280 281 282 283 284 285 286 287 288 289

macro(zmq_check_getrandom)
  message(STATUS "Checking whether getrandom is supported")
  check_c_source_runs(
    "
#include <sys/random.h>

int main (int argc, char *argv [])
{
    char buf[4];
290 291
    int rc = getrandom(buf, 4, 0);
    return rc == -1 ? 1 : 0;
292 293 294 295
}
"
    ZMQ_HAVE_GETRANDOM)
endmacro()
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313

macro(zmq_check_noexcept)
  message(STATUS "Checking whether noexcept is supported")
  check_cxx_source_compiles(
"
struct X 
{
    X(int i) noexcept {}
};

int main(int argc, char *argv [])
{
    X x(5);
    return 0;
}
"
    ZMQ_HAVE_NOEXCEPT)
endmacro()