[CMake] How to detect socklen_t?

Thomas Klausner tk at giga.or.at
Mon Feb 26 13:28:06 EST 2007


Hi!

What's the proper way to check for the existence of socklen_t?
I tried using
	CHECK_SYMBOL_EXISTS(socklen_t "sys/types.h;sys/socket.h" HAVE_SOCKLEN_T)
but the compilers on at least Linux and Irix don't like
	cmakeRequireSymbol(0,&socklen_t);

CHECK_TYPE_SIZE looks like a possible candidate too, but I
don't know how to tell it to include sys/types.h and sys/socket.h.

Currently I'm using a TRY_COMPILE statement like this:
	MESSAGE("-- Looking for socklen_t")
	TRY_COMPILE(HAVE_SOCKLEN_T
	  ${CMAKE_CURRENT_BINARY_DIR}
	  ${CMAKE_CURRENT_SOURCE_DIR}/socklen_t.c
	  OUTPUT_VARIABLE SLT)
	IF(HAVE_SOCKLEN_T)
	  MESSAGE("-- Looking for socklen_t - found")
	ELSE(HAVE_SOCKLEN_T)
	  MESSAGE("-- Looking for socklen_t - not found:\n${SLT}")
	ENDIF(HAVE_SOCKLEN_T)
but I still think there must be a better way -- is there?

Cheers,
 Thomas
-------------- next part --------------
#include <sys/types.h>
#include <sys/socket.h>

int main()
{
    socklen_t *foo;

    foo = 0;
    return 0;
}


More information about the CMake mailing list