configure.cmake 43.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# Copyright (C) 2009 Sun Microsystems,Inc
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

INCLUDE (CheckCSourceCompiles)
INCLUDE (CheckCXXSourceCompiles)
INCLUDE (CheckStructHasMember)
INCLUDE (CheckLibraryExists)
INCLUDE (CheckFunctionExists)
INCLUDE (CheckCCompilerFlag)
INCLUDE (CheckCSourceRuns)
24
INCLUDE (CheckSymbolExists)
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


# Sometimes it is handy to know if PIC option
# is set, to avoid recompilation of the same source 
# for shared libs. We also allow it as an option for
# fast compile.
IF(UNIX)
  IF(APPLE)  
    # OSX  executable are always PIC
    SET(WITH_PIC ON)
  ELSE()
    OPTION(WITH_PIC "Generate PIC objects" OFF)
    IF(WITH_PIC)
      SET(CMAKE_C_FLAGS 
        "${CMAKE_C_FLAGS} ${CMAKE_SHARED_LIBRARY_C_FLAGS}")
      SET(CMAKE_CXX_FLAGS 
        "${CMAKE_CXX_FLAGS} ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}")
    ENDIF()
  ENDIF()
ENDIF()


#
# Tests for OS
IF (CMAKE_SYSTEM_NAME MATCHES "Linux")
  SET(TARGET_OS_LINUX 1)
  SET(HAVE_NPTL 1)
52
  SET(_GNU_SOURCE 1)
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
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
  SET(TARGET_OS_SOLARIS 1)
ENDIF()


# OS display name (version_compile_os etc).
# Used by the test suite to ignore bugs on some platforms, 
# typically on Windows.
IF(WIN32)
 IF(CMAKE_SIZEOF_VOID_P MATCHES 8)
   SET(SYSTEM_TYPE "Win64")
 ELSE()
   SET(SYSTEM_TYPE "Win32")
 ENDIF()
ELSE()
  IF(PLATFORM)
    SET(SYSTEM_TYPE ${PLATFORM})
  ELSE()
    SET(SYSTEM_TYPE ${CMAKE_SYSTEM_NAME})
  ENDIF()
ENDIF()


# Intel compiler is almost Visual C++
# (same compile flags etc). Set MSVC flag
IF(WIN32 AND CMAKE_C_COMPILER MATCHES "icl")
 SET(MSVC TRUE)
ENDIF()

IF(CMAKE_COMPILER_IS_GNUCXX)
  SET(CMAKE_CXX_FLAGS 
    "${CMAKE_CXX_FLAGS} -fno-implicit-templates -fno-exceptions -fno-rtti")
  IF(CMAKE_CXX_FLAGS)
    STRING(REGEX MATCH "fno-implicit-templates" NO_IMPLICIT_TEMPLATES
      ${CMAKE_CXX_FLAGS})
    IF (NO_IMPLICIT_TEMPLATES)
      SET(HAVE_EXPLICIT_TEMPLATE_INSTANTIATION TRUE)
    ENDIF()
  ENDIF()
  IF(MINGW AND CMAKE_SIZEOF_VOIDP EQUAL 4)
   # mininal architecture flags, i486 enables GCC atomics
   ADD_DEFINITIONS(-march=i486)
  ENDIF()
96 97 98 99 100 101
  IF(APPLE AND CMAKE_OSX_DEPLOYMENT_TARGET)
    # Workaround linker problems  on OSX 10.4
    IF(CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "10.5")
      ADD_DEFINITIONS(-fno-common)
    ENDIF()
  ENDIF()
102
ENDIF()
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


# Large files
SET(_LARGEFILE_SOURCE  1)
IF(CMAKE_SYSTEM_NAME STREQUAL "HP-UX")
  SET(_LARGEFILE64_SOURCE 1)
  SET(_FILE_OFFSET_BITS 64)
ENDIF()
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "SunOS" )
  SET(_FILE_OFFSET_BITS 64)
ENDIF()
IF(CMAKE_SYSTEM_NAME MATCHES "AIX" OR CMAKE_SYSTEM_NAME MATCHES "OS400")
  SET(_LARGE_FILES 1)
ENDIF()



  
IF(MSVC)
# Enable debug info also in Release build, and create PDB to be able to analyze 
# crashes
  SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
  SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /Zi")
  SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /debug")
ENDIF()

IF(CMAKE_GENERATOR MATCHES "Visual Studio 7")
    # VS2003 has a bug that prevents linking mysqld with module definition file 
    # (/DEF option for linker). Linker would incorrectly complain about multiply
    # defined symbols. Workaround is to disable dynamic plugins, so /DEF is not
    # used.
    MESSAGE(
   "Warning: Building MySQL with Visual Studio 2003.NET is no more supported.")
    MESSAGE("Please use a newer version of Visual Studio.")
    SET(WITHOUT_DYNAMIC_PLUGINS TRUE)
	
    # VS2003 needs the /Op compiler option to disable floating point 
    # optimizations
141 142 143
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Op")
    SET(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /Op")
ENDIF()
144 145 146 147 148 149 150


IF(CMAKE_SYSTEM_NAME STREQUAL "HP-UX" )
  IF(CMAKE_SIZEOF_VOID_P EQUAL 4)
    # HPUX linker crashes building plugins
    SET(WITHOUT_DYNAMIC_PLUGINS TRUE)
  ENDIF()
151
  # If Itanium make shared library suffix .so
152 153 154 155 156 157 158 159
  # OS understands both .sl and .so. CMake would
  # use .sl, however MySQL prefers .so
  IF(NOT CMAKE_SYSTEM_PROCESSOR MATCHES "9000")
    SET(CMAKE_SHARED_LIBRARY_SUFFIX ".so" CACHE INTERNAL "" FORCE)
    SET(CMAKE_SHARED_MODULE_SUFFIX ".so" CACHE INTERNAL "" FORCE)
  ENDIF()
ENDIF()

160 161 162
# Ensure we have clean build for shared libraries
# without extra dependencies and without unresolved symbols
# (on system that support it)
163 164 165 166 167 168 169 170 171 172
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  FOREACH(LANG C CXX)
  STRING(REPLACE "-rdynamic" "" 
    CMAKE_SHARED_LIBRARY_LINK_${LANG}_FLAGS
    ${CMAKE_SHARED_LIBRARY_LINK_${LANG}_FLAGS}  
  )
  ENDFOREACH()
  SET(LINK_FLAG_NO_UNDEFINED "--Wl,--no-undefined")
ENDIF()

173 174 175 176 177
#Some OS specific hacks
IF(CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
  ADD_DEFINITIONS(-DNET_RETRY_COUNT=1000000)
ELSEIF(CMAKE_SYSTEM MATCHES "HP-UX" AND CMAKE_SYSTEM MATCHES "11")
  ADD_DEFINITIONS(-DHPUX11)
178 179 180 181
ENDIF()

IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
  ADD_DEFINITIONS(-DHAVE_RWLOCK_T)
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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
ENDIF()

# Disable warnings in Visual Studio 8 and above
IF(MSVC AND NOT CMAKE_GENERATOR MATCHES "Visual Studio 7")
  #TODO: update the code and remove the disabled warnings
  ADD_DEFINITIONS(/wd4800 /wd4805)
  ADD_DEFINITIONS(/wd4996)
ENDIF()


# Settings for Visual Studio 7 and above.  
IF(MSVC)
    # replace /MDd with /MTd
    STRING(REPLACE "/MD"  "/MT"  CMAKE_C_FLAGS_RELEASE          ${CMAKE_C_FLAGS_RELEASE})
    STRING(REPLACE "/MD"  "/MT"  CMAKE_C_FLAGS_RELWITHDEBINFO   ${CMAKE_C_FLAGS_RELWITHDEBINFO})
    STRING(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG            ${CMAKE_C_FLAGS_DEBUG})
    STRING(REPLACE "/MDd" "/MTd" CMAKE_C_FLAGS_DEBUG_INIT       ${CMAKE_C_FLAGS_DEBUG_INIT})

    STRING(REPLACE "/MD"  "/MT"  CMAKE_CXX_FLAGS_RELEASE        ${CMAKE_CXX_FLAGS_RELEASE})
    STRING(REPLACE "/MD"  "/MT"  CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO})
    STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG          ${CMAKE_CXX_FLAGS_DEBUG})
    STRING(REPLACE "/MDd" "/MTd" CMAKE_CXX_FLAGS_DEBUG_INIT     ${CMAKE_CXX_FLAGS_DEBUG_INIT})

    # generate map files, set stack size (see bug#20815)
    SET(thread_stack_size 1048576)
    SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /STACK:${thread_stack_size}")
    ADD_DEFINITIONS(-DPTHREAD_STACK_MIN=${thread_stack_size})

    # remove support for Exception handling
    STRING(REPLACE "/GX"   "" CMAKE_CXX_FLAGS            ${CMAKE_CXX_FLAGS})
    STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS            ${CMAKE_CXX_FLAGS})
    STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS_INIT       ${CMAKE_CXX_FLAGS_INIT})
    STRING(REPLACE "/EHsc" "" CMAKE_CXX_FLAGS_DEBUG_INIT ${CMAKE_CXX_FLAGS_DEBUG_INIT})
    
    # Mark 32 bit executables large address aware so they can 
    # use > 2GB address space
    IF(CMAKE_SIZEOF_VOID_P MATCHES 4)
      SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /LARGEADDRESSAWARE")
    ENDIF(CMAKE_SIZEOF_VOID_P MATCHES 4)
ENDIF(MSVC)

IF(WIN32)
  ADD_DEFINITIONS("-D_WINDOWS -D__WIN__ -D_CRT_SECURE_NO_DEPRECATE")
  ADD_DEFINITIONS("-D_WIN32_WINNT=0x0501")
  # Speed up build process excluding unused header files
  ADD_DEFINITIONS("-DWIN32_LEAN_AND_MEAN")
  IF (MSVC_VERSION GREATER 1400)
    # Speed up multiprocessor build
Vladislav Vaintroub's avatar
Vladislav Vaintroub committed
230 231
    SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /MP")
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
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 260 261 262 263
  ENDIF()

  # default to x86 platform.  We'll check for X64 in a bit
  SET (PLATFORM X86)
  IF(MSVC AND CMAKE_SIZEOF_VOID_P MATCHES 8)
    # _WIN64 is defined by the compiler itself. 
    # Yet, we define it here again   to work around a bug with  Intellisense 
    # described here: http://tinyurl.com/2cb428. 
    # Syntax highlighting is important for proper debugger functionality.
    ADD_DEFINITIONS("-D_WIN64")
    SET (PLATFORM X64)
  ENDIF()
ENDIF()



# Figure out what engines to build and how (statically or dynamically),
# add preprocessor defines for storage engines.
IF(WITHOUT_DYNAMIC_PLUGINS)
  MESSAGE("Dynamic plugins are disabled.")
ENDIF(WITHOUT_DYNAMIC_PLUGINS)


# Perform machine tests on posix platforms only
IF(WIN32)
 SET(SYSTEM_LIBS ws2_32)
 SET(CMAKE_REQUIRED_INCLUDES "winsock2.h;ws2tcpip.h")
 SET(CMAKE_REQUIRED_DEFINITONS "-D_WIN32_WINNT=0x0501")
 SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ws2_32)
 LINK_LIBRARIES(ws2_32)
ENDIF()

264 265 266 267
# Searches function in libraries
# if function is found, sets output parameter result to the name of the library
# if function is found in libc, result will be empty 
FUNCTION(MY_SEARCH_LIBS func libs result)
268
  CHECK_FUNCTION_EXISTS(${func} HAVE_${func}_IN_LIBC)
269 270 271
  IF(HAVE_${func}_IN_LIBC)
    SET(${result} "" PARENT_SCOPE)
    RETURN()
272
  ENDIF()
273 274 275 276
  FOREACH(lib  ${libs})
    CHECK_LIBRARY_EXISTS(${lib} ${func} "" HAVE_${func}_IN_${lib}) 
    IF(HAVE_${func}_IN_${lib})
      SET(${result} ${lib} PARENT_SCOPE)
277
      RETURN()
278 279 280
    ENDIF()
  ENDFOREACH()
ENDFUNCTION()
281 282

IF(UNIX)
283 284 285
  MY_SEARCH_LIBS(floor m LIBM)
  IF(NOT LIBM)
    MY_SEARCH_LIBS(__infinity m LIBM)
286
  ENDIF()
287
  
288 289 290 291 292
  IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
   # On  Solaris, use of intrinsics will screw the lib search logic
   # Force using -lm, so rint etc are found.
   SET(LIBM m)
  ENDIF()
293

Vladislav Vaintroub's avatar
merge  
Vladislav Vaintroub committed
294
  MY_SEARCH_LIBS(gethostbyname_r  "nsl_r;nsl" LIBNSL)
295
  MY_SEARCH_LIBS(bind "bind;socket" LIBBIND)
296 297 298
  MY_SEARCH_LIBS(crypt crypt LIBCRYPT)
  MY_SEARCH_LIBS(setsockopt socket LIBSOCKET)
  MY_SEARCH_LIBS(dlopen dl LIBDL)
299
  MY_SEARCH_LIBS(sched_yield rt LIBRT)
300 301 302
  IF(NOT LIBRT)
    MY_SEARCH_LIBS(clock_gettime rt LIBRT)
  ENDIF()
303 304
  FIND_PACKAGE(Threads)

305 306 307 308 309 310 311
  IF(CMAKE_SYSTEM_NAME MATCHES "SunOS")
    # CMake defined -lthread as thread flag 
    # This crashes in dlopen when trying to load plugins 
    # Workaround with -lpthread
    SET(CMAKE_THREADS_LIBS_INIT -lpthread)
  ENDIF()

312
  SET(CMAKE_REQUIRED_LIBRARIES 
Vladislav Vaintroub's avatar
merge  
Vladislav Vaintroub committed
313
    ${LIBM} ${LIBNSL} ${LIBBIND} ${LIBCRYPT} ${LIBSOCKET} ${LIBDL} ${CMAKE_THREAD_LIBS_INIT} ${LIBRT})
314

315
  LIST(REMOVE_DUPLICATES CMAKE_REQUIRED_LIBRARIES)
316 317
  LINK_LIBRARIES(${CMAKE_THREAD_LIBS_INIT})
  
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334
  OPTION(WITH_LIBWRAP "Compile with tcp wrappers support" OFF)
  IF(WITH_LIBWRAP)
    SET(SAVE_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
    SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} wrap)
    CHECK_C_SOURCE_COMPILES(
    "
    #include <tcpd.h>
    int allow_severity = 0;
    int deny_severity  = 0;
    int main()
    {
      hosts_access(0);
    }"
    HAVE_LIBWRAP)
    SET(CMAKE_REQUIRED_LIBRARIES ${SAVE_CMAKE_REQUIRED_LIBRARIES})
    IF(HAVE_LIBWRAP)
      SET(MYSYS_LIBWRAP_SOURCE  ${CMAKE_SOURCE_DIR}/mysys/my_libwrap.c)
335
      SET(LIBWRAP "wrap")
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
    ENDIF()
  ENDIF()
ENDIF()

# Workaround for CMake bug#9051
IF(CMAKE_OSX_SYSROOT)
 SET(ENV{CMAKE_OSX_SYSROOT} ${CMAKE_OSX_SYSROOT})
ENDIF()
IF(CMAKE_OSX_SYSROOT)
 SET(ENV{MACOSX_DEPLOYMENT_TARGET} ${OSX_DEPLOYMENT_TARGET})
ENDIF()

# This macro is used only on Windows at the moment
# Some standard functions exist there under different
# names (e.g popen is _popen or strok_r is _strtok_s)
# If a replacement function exists, HAVE_FUNCTION is
# defined to 1. CMake variable <function_name> will also
# be defined to the replacement name.
# So for example, CHECK_FUNCTION_REPLACEMENT(popen _popen)
# will define HAVE_POPEN to 1 and set variable named popen
# to _popen. If the header template, one needs to have
# cmakedefine popen @popen@ which will expand to 
# define popen _popen after CONFIGURE_FILE

MACRO(CHECK_FUNCTION_REPLACEMENT function replacement)
  STRING(TOUPPER ${function} function_upper)
  CHECK_FUNCTION_EXISTS(${function} HAVE_${function_upper})
  IF(NOT HAVE_${function_upper})
    CHECK_FUNCTION_EXISTS(${replacement}  HAVE_${replacement})
    IF(HAVE_${replacement})
      SET(HAVE_${function_upper} 1 )
      SET(${function} ${replacement})
    ENDIF()
  ENDIF()
ENDMACRO()

MACRO(CHECK_SYMBOL_REPLACEMENT symbol replacement header)
  STRING(TOUPPER ${symbol} symbol_upper)
  CHECK_SYMBOL_EXISTS(${symbol} ${header} HAVE_${symbol_upper})
  IF(NOT HAVE_${symbol_upper})
    CHECK_SYMBOL_EXISTS(${replacement} ${header} HAVE_${replacement})
    IF(HAVE_${replacement})
      SET(HAVE_${symbol_upper} 1)
      SET(${symbol} ${replacement})
    ENDIF()
  ENDIF()
ENDMACRO()


MACRO(CHECK_INCLUDE_FILES_UNIX INCLUDES VAR)
IF(UNIX)
  CHECK_INCLUDE_FILES ("${INCLUDES}" ${VAR})
ENDIF()
ENDMACRO()

MACRO(CHECK_C_SOURCE_COMPILES_UNIX SRC VAR)
IF(UNIX)
  CHECK_C_SOURCE_COMPILES("${SRC}" ${VAR})
ENDIF()
ENDMACRO()

MACRO(CHECK_CXX_SOURCE_COMPILES_UNIX SRC VAR)
IF(UNIX)
  CHECK_CXX_SOURCE_COMPILES("${SRC}" ${VAR})
ENDIF()
ENDMACRO()

MACRO(CHECK_FUNCTION_EXISTS_UNIX FUNC VAR)
IF(UNIX)
  CHECK_FUNCTION_EXISTS("${FUNC}" ${VAR})
ENDIF()
ENDMACRO()

MACRO (CHECK_SYMBOL_EXISTS_UNIX SYM HEADER VAR)
IF(UNIX)
  CHECK_SYMBOL_EXISTS("${SYM}" "${HEADER}" ${VAR})
ENDIF()
ENDMACRO()

#
# Tests for header files
#
INCLUDE (CheckIncludeFiles)

CHECK_INCLUDE_FILES ("stdlib.h;stdarg.h;string.h;float.h" STDC_HEADERS)
CHECK_INCLUDE_FILES (sys/types.h HAVE_SYS_TYPES_H)
CHECK_INCLUDE_FILES_UNIX (alloca.h HAVE_ALLOCA_H)
CHECK_INCLUDE_FILES_UNIX (aio.h HAVE_AIO_H)
CHECK_INCLUDE_FILES_UNIX (arpa/inet.h HAVE_ARPA_INET_H)
CHECK_INCLUDE_FILES_UNIX (crypt.h HAVE_CRYPT_H)
CHECK_INCLUDE_FILES (dirent.h HAVE_DIRENT_H)
CHECK_INCLUDE_FILES_UNIX (dlfcn.h HAVE_DLFCN_H)
CHECK_INCLUDE_FILES_UNIX (execinfo.h HAVE_EXECINFO_H)
CHECK_INCLUDE_FILES (fcntl.h HAVE_FCNTL_H)
CHECK_INCLUDE_FILES (fenv.h HAVE_FENV_H)
CHECK_INCLUDE_FILES (float.h HAVE_FLOAT_H)
CHECK_INCLUDE_FILES_UNIX (floatingpoint.h HAVE_FLOATINGPOINT_H)
CHECK_INCLUDE_FILES_UNIX (fpu_control.h HAVE_FPU_CONTROL_H)
CHECK_INCLUDE_FILES_UNIX (grp.h HAVE_GRP_H)
CHECK_INCLUDE_FILES_UNIX (ieeefp.h HAVE_IEEEFP_H)
CHECK_INCLUDE_FILES (inttypes.h HAVE_INTTYPES_H)
CHECK_INCLUDE_FILES_UNIX (langinfo.h HAVE_LANGINFO_H)
CHECK_INCLUDE_FILES (limits.h HAVE_LIMITS_H)
CHECK_INCLUDE_FILES (locale.h HAVE_LOCALE_H)
CHECK_INCLUDE_FILES (malloc.h HAVE_MALLOC_H)
CHECK_INCLUDE_FILES (memory.h HAVE_MEMORY_H)
CHECK_INCLUDE_FILES_UNIX (netinet/in.h HAVE_NETINET_IN_H)
CHECK_INCLUDE_FILES_UNIX (paths.h HAVE_PATHS_H)
CHECK_INCLUDE_FILES_UNIX (port.h HAVE_PORT_H)
CHECK_INCLUDE_FILES_UNIX (pwd.h HAVE_PWD_H)
CHECK_INCLUDE_FILES_UNIX (sched.h HAVE_SCHED_H)
CHECK_INCLUDE_FILES_UNIX (select.h HAVE_SELECT_H)
CHECK_INCLUDE_FILES_UNIX (semaphore.h HAVE_SEMAPHORE_H)
CHECK_INCLUDE_FILES_UNIX (sys/dir.h HAVE_SYS_DIR_H)
CHECK_INCLUDE_FILES_UNIX (sys/pte.h HAVE_SYS_PTE_H)
CHECK_INCLUDE_FILES_UNIX (sys/ptem.h HAVE_SYS_PTEM_H)
CHECK_INCLUDE_FILES (stddef.h HAVE_STDDEF_H)
CHECK_INCLUDE_FILES (stdint.h HAVE_STDINT_H)
CHECK_INCLUDE_FILES (stdlib.h HAVE_STDLIB_H)
CHECK_INCLUDE_FILES (strings.h HAVE_STRINGS_H)
CHECK_INCLUDE_FILES (string.h HAVE_STRING_H)
CHECK_INCLUDE_FILES_UNIX (synch.h HAVE_SYNCH_H)
CHECK_INCLUDE_FILES_UNIX (sysent.h HAVE_SYSENT_H)
CHECK_INCLUDE_FILES_UNIX (sys/cdefs.h HAVE_SYS_CDEFS_H)
CHECK_INCLUDE_FILES_UNIX (sys/file.h HAVE_SYS_FILE_H)
CHECK_INCLUDE_FILES_UNIX (sys/fpu.h HAVE_SYS_FPU_H)
CHECK_INCLUDE_FILES_UNIX (sys/ioctl.h HAVE_SYS_IOCTL_H)
CHECK_INCLUDE_FILES_UNIX (sys/ipc.h HAVE_SYS_IPC_H)
CHECK_INCLUDE_FILES_UNIX (sys/malloc.h HAVE_SYS_MALLOC_H)
CHECK_INCLUDE_FILES_UNIX (sys/mman.h HAVE_SYS_MMAN_H)
CHECK_INCLUDE_FILES_UNIX (sys/prctl.h HAVE_SYS_PRCTL_H)
CHECK_INCLUDE_FILES_UNIX (sys/resource.h HAVE_SYS_RESOURCE_H)
CHECK_INCLUDE_FILES_UNIX (sys/select.h HAVE_SYS_SELECT_H)
CHECK_INCLUDE_FILES_UNIX (sys/shm.h HAVE_SYS_SHM_H)
CHECK_INCLUDE_FILES_UNIX (sys/socket.h HAVE_SYS_SOCKET_H)
CHECK_INCLUDE_FILES (sys/stat.h HAVE_SYS_STAT_H)
CHECK_INCLUDE_FILES_UNIX (sys/stream.h HAVE_SYS_STREAM_H)
CHECK_INCLUDE_FILES_UNIX (sys/termcap.h HAVE_SYS_TERMCAP_H)
CHECK_INCLUDE_FILES ("time.h;sys/timeb.h" HAVE_SYS_TIMEB_H)
CHECK_INCLUDE_FILES_UNIX ("curses.h;term.h" HAVE_TERM_H)
CHECK_INCLUDE_FILES_UNIX (termios.h HAVE_TERMIOS_H)
CHECK_INCLUDE_FILES_UNIX (termio.h HAVE_TERMIO_H)
CHECK_INCLUDE_FILES_UNIX (termcap.h HAVE_TERMCAP_H)
CHECK_INCLUDE_FILES_UNIX (unistd.h HAVE_UNISTD_H)
CHECK_INCLUDE_FILES (utime.h HAVE_UTIME_H)
CHECK_INCLUDE_FILES (varargs.h HAVE_VARARGS_H)
CHECK_INCLUDE_FILES (sys/time.h HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILES (sys/utime.h HAVE_SYS_UTIME_H)
CHECK_INCLUDE_FILES_UNIX (sys/wait.h HAVE_SYS_WAIT_H)
CHECK_INCLUDE_FILES_UNIX (sys/param.h HAVE_SYS_PARAM_H)
CHECK_INCLUDE_FILES_UNIX (sys/vadvise.h HAVE_SYS_VADVISE_H)
CHECK_INCLUDE_FILES_UNIX (fnmatch.h HAVE_FNMATCH_H)
CHECK_INCLUDE_FILES (stdarg.h  HAVE_STDARG_H)
489
CHECK_INCLUDE_FILES_UNIX("stdlib.h;sys/un.h" HAVE_SYS_UN_H)
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504

# Figure out threading library
#
FIND_PACKAGE (Threads)

#
# Tests for functions
#
#CHECK_FUNCTION_EXISTS (aiowait HAVE_AIOWAIT)
CHECK_FUNCTION_EXISTS_UNIX (aio_read HAVE_AIO_READ)
CHECK_FUNCTION_EXISTS_UNIX (alarm HAVE_ALARM)
SET(HAVE_ALLOCA 1)
CHECK_FUNCTION_EXISTS_UNIX (backtrace HAVE_BACKTRACE)
CHECK_FUNCTION_EXISTS_UNIX (backtrace_symbols HAVE_BACKTRACE_SYMBOLS)
CHECK_FUNCTION_EXISTS_UNIX (backtrace_symbols_fd HAVE_BACKTRACE_SYMBOLS_FD)
Vladislav Vaintroub's avatar
merge  
Vladislav Vaintroub committed
505
CHECK_FUNCTION_EXISTS_UNIX (printstack HAVE_PRINTSTACK)
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
CHECK_FUNCTION_EXISTS_UNIX (bcmp HAVE_BCMP)
CHECK_FUNCTION_EXISTS_UNIX (bfill HAVE_BFILL)
CHECK_FUNCTION_EXISTS_UNIX (bmove HAVE_BMOVE)
CHECK_FUNCTION_EXISTS (bsearch HAVE_BSEARCH)
CHECK_FUNCTION_EXISTS (index HAVE_INDEX)
CHECK_FUNCTION_EXISTS_UNIX (bzero HAVE_BZERO)
CHECK_FUNCTION_EXISTS_UNIX (clock_gettime HAVE_CLOCK_GETTIME)
CHECK_FUNCTION_EXISTS_UNIX (cuserid HAVE_CUSERID)
CHECK_FUNCTION_EXISTS_UNIX (directio HAVE_DIRECTIO)
CHECK_FUNCTION_EXISTS_UNIX (_doprnt HAVE_DOPRNT)
CHECK_FUNCTION_EXISTS_UNIX (flockfile HAVE_FLOCKFILE)
CHECK_FUNCTION_EXISTS_UNIX (ftruncate HAVE_FTRUNCATE)
CHECK_FUNCTION_EXISTS_UNIX (getline HAVE_GETLINE)
CHECK_FUNCTION_EXISTS_UNIX (compress HAVE_COMPRESS)
CHECK_FUNCTION_EXISTS_UNIX (crypt HAVE_CRYPT)
CHECK_FUNCTION_EXISTS_UNIX (dlerror HAVE_DLERROR)
CHECK_FUNCTION_EXISTS_UNIX (dlopen HAVE_DLOPEN)
IF (CMAKE_COMPILER_IS_GNUCC)
 IF (CMAKE_EXE_LINKER_FLAGS MATCHES " -static " 
     OR CMAKE_EXE_LINKER_FLAGS MATCHES " -static$")
   SET(HAVE_DLOPEN FALSE CACHE "Disable dlopen due to -static flag" FORCE)
   SET(WITHOUT_DYNAMIC_PLUGINS TRUE)
 ENDIF()
ENDIF()
CHECK_FUNCTION_EXISTS_UNIX (fchmod HAVE_FCHMOD)
CHECK_FUNCTION_EXISTS_UNIX (fcntl HAVE_FCNTL)
CHECK_FUNCTION_EXISTS_UNIX (fconvert HAVE_FCONVERT)
533
CHECK_SYMBOL_EXISTS_UNIX(fdatasync "unistd.h" HAVE_FDATASYNC)
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
CHECK_FUNCTION_EXISTS_UNIX (fesetround HAVE_FESETROUND)
CHECK_FUNCTION_EXISTS_UNIX (fpsetmask HAVE_FPSETMASK)
CHECK_FUNCTION_EXISTS_UNIX (fseeko HAVE_FSEEKO)
CHECK_FUNCTION_EXISTS_UNIX (fsync HAVE_FSYNC)
CHECK_FUNCTION_EXISTS (getcwd HAVE_GETCWD)
CHECK_FUNCTION_EXISTS_UNIX (gethostbyaddr_r HAVE_GETHOSTBYADDR_R)
CHECK_FUNCTION_EXISTS_UNIX (gethostbyname_r HAVE_GETHOSTBYNAME_R)
CHECK_FUNCTION_EXISTS_UNIX (gethrtime HAVE_GETHRTIME)
CHECK_FUNCTION_EXISTS (getnameinfo HAVE_GETNAMEINFO)
CHECK_FUNCTION_EXISTS_UNIX (getpass HAVE_GETPASS)
CHECK_FUNCTION_EXISTS_UNIX (getpassphrase HAVE_GETPASSPHRASE)
CHECK_FUNCTION_EXISTS_UNIX (getpwnam HAVE_GETPWNAM)
CHECK_FUNCTION_EXISTS_UNIX (getpwuid HAVE_GETPWUID)
CHECK_FUNCTION_EXISTS_UNIX (getrlimit HAVE_GETRLIMIT)
CHECK_FUNCTION_EXISTS_UNIX (getrusage HAVE_GETRUSAGE)
CHECK_FUNCTION_EXISTS_UNIX (getwd HAVE_GETWD)
CHECK_FUNCTION_EXISTS_UNIX (gmtime_r HAVE_GMTIME_R)
CHECK_FUNCTION_EXISTS_UNIX (initgroups HAVE_INITGROUPS)
CHECK_FUNCTION_EXISTS_UNIX (issetugid HAVE_ISSETUGID)
CHECK_FUNCTION_EXISTS (ldiv HAVE_LDIV)
CHECK_FUNCTION_EXISTS_UNIX (localtime_r HAVE_LOCALTIME_R)
CHECK_FUNCTION_EXISTS (longjmp HAVE_LONGJMP)
CHECK_FUNCTION_EXISTS (lstat HAVE_LSTAT)
CHECK_FUNCTION_EXISTS_UNIX (madvise HAVE_MADVISE)
CHECK_FUNCTION_EXISTS_UNIX (mallinfo HAVE_MALLINFO)
CHECK_FUNCTION_EXISTS (memcpy HAVE_MEMCPY)
CHECK_FUNCTION_EXISTS (memmove HAVE_MEMMOVE)
CHECK_FUNCTION_EXISTS (mkstemp HAVE_MKSTEMP)
CHECK_FUNCTION_EXISTS_UNIX (mlock HAVE_MLOCK)
CHECK_FUNCTION_EXISTS_UNIX (mlockall HAVE_MLOCKALL)
CHECK_FUNCTION_EXISTS_UNIX (mmap HAVE_MMAP)
CHECK_FUNCTION_EXISTS_UNIX (mmap64 HAVE_MMAP64)
CHECK_FUNCTION_EXISTS (perror HAVE_PERROR)
CHECK_FUNCTION_EXISTS_UNIX (poll HAVE_POLL)
CHECK_FUNCTION_EXISTS_UNIX (port_create HAVE_PORT_CREATE)
CHECK_FUNCTION_EXISTS_UNIX (posix_fallocate HAVE_POSIX_FALLOCATE)
CHECK_FUNCTION_EXISTS_UNIX (pread HAVE_PREAD)
CHECK_FUNCTION_EXISTS_UNIX (pthread_attr_create HAVE_PTHREAD_ATTR_CREATE)
CHECK_FUNCTION_EXISTS_UNIX (pthread_attr_getstacksize HAVE_PTHREAD_ATTR_GETSTACKSIZE)
CHECK_FUNCTION_EXISTS_UNIX (pthread_attr_setscope HAVE_PTHREAD_ATTR_SETSCOPE)
CHECK_FUNCTION_EXISTS_UNIX (pthread_attr_setstacksize HAVE_PTHREAD_ATTR_SETSTACKSIZE)
CHECK_FUNCTION_EXISTS_UNIX (pthread_condattr_create HAVE_PTHREAD_CONDATTR_CREATE)
CHECK_FUNCTION_EXISTS_UNIX (pthread_condattr_setclock HAVE_PTHREAD_CONDATTR_SETCLOCK)
CHECK_FUNCTION_EXISTS_UNIX (pthread_init HAVE_PTHREAD_INIT)
CHECK_FUNCTION_EXISTS_UNIX (pthread_key_delete HAVE_PTHREAD_KEY_DELETE)
CHECK_FUNCTION_EXISTS_UNIX (pthread_rwlock_rdlock HAVE_PTHREAD_RWLOCK_RDLOCK)
CHECK_FUNCTION_EXISTS_UNIX (pthread_sigmask HAVE_PTHREAD_SIGMASK)
CHECK_FUNCTION_EXISTS_UNIX (pthread_threadmask HAVE_PTHREAD_THREADMASK)
CHECK_FUNCTION_EXISTS_UNIX (pthread_yield_np HAVE_PTHREAD_YIELD_NP)
CHECK_FUNCTION_EXISTS (putenv HAVE_PUTENV)
CHECK_FUNCTION_EXISTS_UNIX (readdir_r HAVE_READDIR_R)
CHECK_FUNCTION_EXISTS_UNIX (readlink HAVE_READLINK)
CHECK_FUNCTION_EXISTS_UNIX (re_comp HAVE_RE_COMP)
CHECK_FUNCTION_EXISTS_UNIX (regcomp HAVE_REGCOMP)
CHECK_FUNCTION_EXISTS_UNIX (realpath HAVE_REALPATH)
CHECK_FUNCTION_EXISTS (rename HAVE_RENAME)
CHECK_FUNCTION_EXISTS_UNIX (rwlock_init HAVE_RWLOCK_INIT)
CHECK_FUNCTION_EXISTS_UNIX (sched_yield HAVE_SCHED_YIELD)
CHECK_FUNCTION_EXISTS_UNIX (setenv HAVE_SETENV)
CHECK_FUNCTION_EXISTS (setlocale HAVE_SETLOCALE)
CHECK_FUNCTION_EXISTS_UNIX (setfd HAVE_SETFD)
CHECK_FUNCTION_EXISTS_UNIX (sigaction HAVE_SIGACTION)
CHECK_FUNCTION_EXISTS_UNIX (sigthreadmask HAVE_SIGTHREADMASK)
CHECK_FUNCTION_EXISTS_UNIX (sigwait HAVE_SIGWAIT)
CHECK_FUNCTION_EXISTS_UNIX (sigaddset HAVE_SIGADDSET)
CHECK_FUNCTION_EXISTS_UNIX (sigemptyset HAVE_SIGEMPTYSET)
CHECK_FUNCTION_EXISTS_UNIX (sighold HAVE_SIGHOLD) 
CHECK_FUNCTION_EXISTS_UNIX (sigset HAVE_SIGSET)
CHECK_FUNCTION_EXISTS_UNIX (sleep HAVE_SLEEP)
CHECK_FUNCTION_EXISTS (snprintf HAVE_SNPRINTF)
CHECK_FUNCTION_EXISTS_UNIX (stpcpy HAVE_STPCPY)
CHECK_FUNCTION_EXISTS (strcoll HAVE_STRCOLL)
CHECK_FUNCTION_EXISTS (strerror HAVE_STRERROR)
CHECK_FUNCTION_EXISTS_UNIX (strlcpy HAVE_STRLCPY)
CHECK_FUNCTION_EXISTS (strnlen HAVE_STRNLEN)
CHECK_FUNCTION_EXISTS_UNIX (strlcat HAVE_STRLCAT)
CHECK_FUNCTION_EXISTS_UNIX (strsignal HAVE_STRSIGNAL)
CHECK_FUNCTION_EXISTS_UNIX (fgetln HAVE_FGETLN)
CHECK_FUNCTION_EXISTS (strpbrk HAVE_STRPBRK)
CHECK_FUNCTION_EXISTS (strsep HAVE_STRSEP)
CHECK_FUNCTION_EXISTS (strstr HAVE_STRSTR)
CHECK_FUNCTION_EXISTS_UNIX (strtok_r HAVE_STRTOK_R)
CHECK_FUNCTION_EXISTS (strtol HAVE_STRTOL)
CHECK_FUNCTION_EXISTS (strtoll HAVE_STRTOLL)
CHECK_FUNCTION_EXISTS (strtoul HAVE_STRTOUL)
CHECK_FUNCTION_EXISTS (strtoull HAVE_STRTOULL)
CHECK_FUNCTION_EXISTS (strcasecmp HAVE_STRCASECMP)
CHECK_FUNCTION_EXISTS (strncasecmp HAVE_STRNCASECMP)
CHECK_FUNCTION_EXISTS (strdup HAVE_STRDUP)
CHECK_FUNCTION_EXISTS_UNIX (shmat HAVE_SHMAT) 
CHECK_FUNCTION_EXISTS_UNIX (shmctl HAVE_SHMCTL)
CHECK_FUNCTION_EXISTS_UNIX (shmdt HAVE_SHMDT)
CHECK_FUNCTION_EXISTS_UNIX (shmget HAVE_SHMGET)
CHECK_FUNCTION_EXISTS (tell HAVE_TELL)
CHECK_FUNCTION_EXISTS (tempnam HAVE_TEMPNAM)
CHECK_FUNCTION_EXISTS_UNIX (thr_setconcurrency HAVE_THR_SETCONCURRENCY)
CHECK_FUNCTION_EXISTS_UNIX (thr_yield HAVE_THR_YIELD)
CHECK_FUNCTION_EXISTS_UNIX (vasprintf HAVE_VASPRINTF)
CHECK_FUNCTION_EXISTS (vsnprintf HAVE_VSNPRINTF)
CHECK_FUNCTION_EXISTS_UNIX (vprintf HAVE_VPRINTF)
CHECK_FUNCTION_EXISTS_UNIX (valloc HAVE_VALLOC)
CHECK_FUNCTION_EXISTS_UNIX (memalign HAVE_MEMALIGN)
CHECK_FUNCTION_EXISTS_UNIX (chown HAVE_CHOWN)
CHECK_FUNCTION_EXISTS_UNIX (nl_langinfo HAVE_NL_LANGINFO)

Vladislav Vaintroub's avatar
merge  
Vladislav Vaintroub committed
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664
#--------------------------------------------------------------------
# Support for WL#2373 (Use cycle counter for timing)
#--------------------------------------------------------------------

CHECK_INCLUDE_FILES_UNIX(time.h HAVE_TIME_H)
CHECK_INCLUDE_FILES_UNIX(sys/time.h HAVE_SYS_TIME_H)
CHECK_INCLUDE_FILES_UNIX(sys/times.h HAVE_SYS_TIMES_H)
CHECK_INCLUDE_FILES_UNIX(asm/msr.h HAVE_ASM_MSR_H)
#msr.h has rdtscll()

CHECK_INCLUDE_FILES_UNIX(ia64intrin.h HAVE_IA64INTRIN_H)

CHECK_FUNCTION_EXISTS_UNIX(times HAVE_TIMES)
CHECK_FUNCTION_EXISTS_UNIX(gettimeofday HAVE_GETTIMEOFDAY)
CHECK_FUNCTION_EXISTS_UNIX(read_real_time HAVE_READ_REAL_TIME)
# This should work on AIX.

CHECK_FUNCTION_EXISTS_UNIX(ftime HAVE_FTIME)
# This is still a normal call for milliseconds.

CHECK_FUNCTION_EXISTS_UNIX(time HAVE_TIME)
# We can use time() on Macintosh if there is no ftime().

CHECK_FUNCTION_EXISTS_UNIX(rdtscll HAVE_RDTSCLL)
# I doubt that we'll ever reach the check for this.

665 666 667 668

#
# Tests for symbols
#
669

670 671
CHECK_SYMBOL_EXISTS_UNIX(sys_errlist "stdio.h" HAVE_SYS_ERRLIST)
CHECK_SYMBOL_EXISTS_UNIX(madvise "sys/mman.h" HAVE_DECL_MADVISE)
Vladislav Vaintroub's avatar
Vladislav Vaintroub committed
672 673
CHECK_SYMBOL_EXISTS(tzname "time.h" HAVE_TZNAME)
CHECK_SYMBOL_EXISTS_UNIX(lrand48 "stdlib.h" HAVE_LRAND48)
674 675 676 677 678 679 680 681 682 683 684 685
CHECK_SYMBOL_EXISTS_UNIX(getpagesize "unistd.h" HAVE_GETPAGESIZE)
CHECK_SYMBOL_EXISTS_UNIX(TIOCGWINSZ "sys/ioctl.h" GWINSZ_IN_SYS_IOCTL)
CHECK_SYMBOL_EXISTS_UNIX(FIONREAD "sys/ioctl.h" FIONREAD_IN_SYS_IOCTL)
CHECK_SYMBOL_EXISTS_UNIX(TIOCSTAT "sys/ioctl.h" TIOCSTAT_IN_SYS_IOCTL)
CHECK_SYMBOL_EXISTS(gettimeofday "sys/time.h" HAVE_GETTIMEOFDAY)

CHECK_SYMBOL_EXISTS(finite  "math.h" HAVE_FINITE_IN_MATH_H)
IF(HAVE_FINITE_IN_MATH_H)
  SET(HAVE_FINITE TRUE CACHE INTERNAL "")
ELSE()
  CHECK_SYMBOL_EXISTS(finite  "ieeefp.h" HAVE_FINITE)
ENDIF()
686 687 688
CHECK_SYMBOL_EXISTS(log2  math.h HAVE_LOG2)
CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
CHECK_SYMBOL_EXISTS(rint  math.h HAVE_RINT)
689

690 691 692 693 694 695 696 697
# isinf() prototype not found on Solaris
CHECK_CXX_SOURCE_COMPILES(
"#include  <math.h>
int main() { 
  isinf(0.0); 
  return 0;
}" HAVE_ISINF)

698 699 700 701 702 703 704


#
# Test for endianess
#
INCLUDE(TestBigEndian)
IF(APPLE)
705
  # Cannot  run endian test on universal PPC/Intel binaries 
706
  # would return inconsistent result.
707
  # config.h.cmake includes a special #ifdef for Darwin
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
ELSE()
  TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
ENDIF()

#
# Tests for type sizes (and presence)
#
INCLUDE (CheckTypeSize)
set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
        -D_LARGEFILE_SOURCE -D_LARGE_FILES -D_FILE_OFFSET_BITS=64
        -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS)
SET(CMAKE_EXTRA_INCLUDE_FILES signal.h)
CHECK_TYPE_SIZE(sigset_t SIZEOF_SIGSET_T)
IF(SIZEOF_SIGSET_T)
  SET(HAVE_SIGSET_T 1) 
ENDIF()
IF(NOT SIZEOF_SIGSET_T)
 SET(sigset_t int)
ENDIF()
CHECK_TYPE_SIZE(mode_t SIZEOF_MODE_T)
IF(NOT SIZEOF_MODE_T)
 SET(mode_t int)
ENDIF()


IF(HAVE_STDINT_H)
  SET(CMAKE_EXTRA_INCLUDE_FILES stdint.h)
ENDIF(HAVE_STDINT_H)
736 737 738 739 740 741

IF(NOT APPLE)
  CHECK_TYPE_SIZE("char *" SIZEOF_CHARP)
  CHECK_TYPE_SIZE(long SIZEOF_LONG)
  CHECK_TYPE_SIZE(size_t SIZEOF_SIZE_T)
ENDIF()
742 743 744 745
CHECK_TYPE_SIZE(char SIZEOF_CHAR)
CHECK_TYPE_SIZE(short SIZEOF_SHORT)
CHECK_TYPE_SIZE(int SIZEOF_INT)
CHECK_TYPE_SIZE("long long" SIZEOF_LONG_LONG)
746
SET(CMAKE_EXTRA_INCLUDE_FILES stdio.h sys/types.h)
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
CHECK_TYPE_SIZE(off_t SIZEOF_OFF_T)
CHECK_TYPE_SIZE(uchar SIZEOF_UCHAR)
CHECK_TYPE_SIZE(uint SIZEOF_UINT)
CHECK_TYPE_SIZE(ulong SIZEOF_ULONG)
CHECK_TYPE_SIZE(int8 SIZEOF_INT8)
CHECK_TYPE_SIZE(uint8 SIZEOF_UINT8)
CHECK_TYPE_SIZE(int16 SIZEOF_INT16)
CHECK_TYPE_SIZE(uint16 SIZEOF_UINT16)
CHECK_TYPE_SIZE(int32 SIZEOF_INT32)
CHECK_TYPE_SIZE(uint32 SIZEOF_UINT32)
CHECK_TYPE_SIZE(u_int32_t SIZEOF_U_INT32_T)
CHECK_TYPE_SIZE(int64 SIZEOF_INT64)
CHECK_TYPE_SIZE(uint64 SIZEOF_UINT64)
SET (CMAKE_EXTRA_INCLUDE_FILES sys/types.h)
CHECK_TYPE_SIZE(bool  SIZEOF_BOOL)
SET(CMAKE_EXTRA_INCLUDE_FILES)
IF(HAVE_SYS_SOCKET_H)
  SET(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
ENDIF(HAVE_SYS_SOCKET_H)
CHECK_TYPE_SIZE(socklen_t SIZEOF_SOCKLEN_T)
SET(CMAKE_EXTRA_INCLUDE_FILES)

IF(HAVE_IEEEFP_H)
  SET(CMAKE_EXTRA_INCLUDE_FILES ieeefp.h)
  CHECK_TYPE_SIZE(fp_except SIZEOF_FP_EXCEPT)
  IF(SIZEOF_FP_EXCEPT)
    SET(HAVE_FP_EXCEPT TRUE)
  ENDIF() 
ENDIF()


#
# Code tests
#

CHECK_C_SOURCE_COMPILES("
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#endif
int main()
{
  getaddrinfo( 0, 0, 0, 0);
  return 0;
}"
HAVE_GETADDRINFO)

CHECK_C_SOURCE_COMPILES("
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#endif
int main()
{
  select(0,0,0,0,0);
  return 0;
}"
HAVE_SELECT)

#
# Check if timespec has ts_sec and ts_nsec fields
#

CHECK_C_SOURCE_COMPILES_UNIX("
#include <pthread.h>

int main(int ac, char **av)
{
  struct timespec abstime;
  abstime.ts_sec = time(NULL)+1;
  abstime.ts_nsec = 0;
}
" HAVE_TIMESPEC_TS_SEC)


#
# Check return type of qsort()
#
CHECK_C_SOURCE_COMPILES("
#include <stdlib.h>
#ifdef __cplusplus
extern \"C\"
#endif
void qsort(void *base, size_t nel, size_t width,
  int (*compar) (const void *, const void *));
int main(int ac, char **av) {}
" QSORT_TYPE_IS_VOID)
IF(QSORT_TYPE_IS_VOID)
  SET(RETQSORTTYPE "void")
ELSE(QSORT_TYPE_IS_VOID)
  SET(RETQSORTTYPE "int")
ENDIF(QSORT_TYPE_IS_VOID)

IF(WIN32)
SET(SOCKET_SIZE_TYPE int)
ELSE()
CHECK_CXX_SOURCE_COMPILES("
#include <sys/socket.h>
int main(int argc, char **argv)
{
  getsockname(0,0,(socklen_t *) 0);
  return 0; 
}"
HAVE_SOCKET_SIZE_T_AS_socklen_t)

IF(HAVE_SOCKET_SIZE_T_AS_socklen_t)
  SET(SOCKET_SIZE_TYPE socklen_t)
ELSE()
  CHECK_CXX_SOURCE_COMPILES("
  #include <sys/socket.h>
  int main(int argc, char **argv)
  {
    getsockname(0,0,(int *) 0);
    return 0; 
  }"
  HAVE_SOCKET_SIZE_T_AS_int)
  IF(HAVE_SOCKET_SIZE_T_AS_int)
    SET(SOCKET_SIZE_TYPE int)
  ELSE()
    CHECK_CXX_SOURCE_COMPILES("
    #include <sys/socket.h>
    int main(int argc, char **argv)
    {
      getsockname(0,0,(size_t *) 0);
      return 0; 
    }"
    HAVE_SOCKET_SIZE_T_AS_size_t)
    IF(HAVE_SOCKET_SIZE_T_AS_size_t)
      SET(SOCKET_SIZE_TYPE size_t)
    ELSE()
      SET(SOCKET_SIZE_TYPE int)
    ENDIF()
  ENDIF()
ENDIF()
ENDIF()

CHECK_CXX_SOURCE_COMPILES_UNIX("
#include <pthread.h>
int main()
{
  pthread_yield();
  return 0;
}
" HAVE_PTHREAD_YIELD_ZERO_ARG)

IF(NOT STACK_DIRECTION)
  IF(CMAKE_CROSSCOMPILING)
   MESSAGE(FATAL_ERROR 
   "STACK_DIRECTION is not defined.  Please specify -DSTACK_DIRECTION=1 "
   "or -DSTACK_DIRECTION=-1 when calling cmake.")
  ELSE()
    TRY_RUN(STACKDIR_RUN_RESULT STACKDIR_COMPILE_RESULT    
     ${CMAKE_BINARY_DIR} 
     ${CMAKE_SOURCE_DIR}/cmake/stack_direction.c
     )
     # Test program returns 0 (down) or 1 (up).
     # Convert to -1 or 1
     IF(STACKDIR_RUN_RESULT EQUAL 0)
       SET(STACK_DIRECTION -1 CACHE INTERNAL "Stack grows direction")
     ELSE()
       SET(STACK_DIRECTION 1 CACHE INTERNAL "Stack grows direction")
     ENDIF()
917
     MESSAGE(STATUS "Checking stack direction : ${STACK_DIRECTION}")
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942
   ENDIF()
ENDIF()

#
# Check return type of signal handlers
#
CHECK_C_SOURCE_COMPILES("
#include <signal.h>
#ifdef signal
# undef signal
#endif
#ifdef __cplusplus
extern \"C\" void (*signal (int, void (*)(int)))(int);
#else
void (*signal ()) ();
#endif
int main(int ac, char **av) {}
" SIGNAL_RETURN_TYPE_IS_VOID)
IF(SIGNAL_RETURN_TYPE_IS_VOID)
  SET(RETSIGTYPE void)
ELSE(SIGNAL_RETURN_TYPE_IS_VOID)
  SET(RETSIGTYPE int)
ENDIF(SIGNAL_RETURN_TYPE_IS_VOID)


943 944
CHECK_INCLUDE_FILES_UNIX("time.h;sys/time.h" TIME_WITH_SYS_TIME)
CHECK_SYMBOL_EXISTS_UNIX(O_NONBLOCK "unistd.h;fcntl.h" HAVE_FCNTL_NONBLOCK)
945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094
IF(NOT HAVE_FCNTL_NONBLOCK)
 SET(NO_FCNTL_NONBLOCK 1)
ENDIF()

#
# Test for how the C compiler does inline, if at all
#
CHECK_C_SOURCE_COMPILES("
static inline int foo(){return 0;}
int main(int argc, char *argv[]){return 0;}"
                            C_HAS_inline)
IF(NOT C_HAS_inline)
  CHECK_C_SOURCE_COMPILES("
  static __inline int foo(){return 0;}
  int main(int argc, char *argv[]){return 0;}"
                            C_HAS___inline)
  SET(C_INLINE __inline)
ENDIF()

IF(NOT CMAKE_CROSSCOMPILING AND NOT MSVC)
  STRING(TOLOWER ${CMAKE_SYSTEM_PROCESSOR}  processor)
  IF(processor MATCHES "86" OR processor MATCHES "amd64" OR processor MATCHES "x64")
  #Check for x86 PAUSE instruction
  # We have to actually try running the test program, because of a bug
  # in Solaris on x86_64, where it wrongly reports that PAUSE is not
  # supported when trying to run an application.  See
  # http://bugs.opensolaris.org/bugdatabase/printableBug.do?bug_id=6478684
  CHECK_C_SOURCE_RUNS("
  int main()
  { 
    __asm__ __volatile__ (\"pause\"); 
    return 0;
  }"  HAVE_PAUSE_INSTRUCTION)
  ENDIF()
  IF (NOT HAVE_PAUSE_INSTRUCTION)
    CHECK_C_SOURCE_COMPILES("
    int main()
    {
     __asm__ __volatile__ (\"rep; nop\");
     return 0;
    }
   " HAVE_FAKE_PAUSE_INSTRUCTION)
  ENDIF()
ENDIF()
  
CHECK_SYMBOL_EXISTS_UNIX(tcgetattr "termios.h" HAVE_TCGETATTR 1)
CHECK_INCLUDE_FILES_UNIX(sys/ioctl.h HAVE_SYS_IOCTL 1)

#
# Check type of signal routines (posix, 4.2bsd, 4.1bsd or v7)
#
CHECK_C_SOURCE_COMPILES_UNIX("
  #include <signal.h>
  int main(int ac, char **av)
  {
    sigset_t ss;
    struct sigaction sa;
    sigemptyset(&ss); sigsuspend(&ss);
    sigaction(SIGINT, &sa, (struct sigaction *) 0);
    sigprocmask(SIG_BLOCK, &ss, (sigset_t *) 0);
  }"
  HAVE_POSIX_SIGNALS)

IF(NOT HAVE_POSIX_SIGNALS)
 CHECK_C_SOURCE_COMPILES_UNIX("
  #include <signal.h>
  int main(int ac, char **av)
  {
    int mask = sigmask(SIGINT);
    sigsetmask(mask); sigblock(mask); sigpause(mask);
  }"
  HAVE_BSD_SIGNALS)
  IF (NOT HAVE_BSD_SIGNALS)
    CHECK_C_SOURCE_COMPILES_UNIX("
    #include <signal.h>
    void foo() { }
    int main(int ac, char **av)
    {
      int mask = sigmask(SIGINT);
      sigset(SIGINT, foo); sigrelse(SIGINT);
      sighold(SIGINT); sigpause(SIGINT);
    }"
   HAVE_SVR3_SIGNALS)  
   IF (NOT HAVE_SVR3_SIGNALS)
    SET(HAVE_V7_SIGNALS 1)
   ENDIF(NOT HAVE_SVR3_SIGNALS)
 ENDIF(NOT HAVE_BSD_SIGNALS)
ENDIF(NOT HAVE_POSIX_SIGNALS)

# Assume regular sprintf
SET(SPRINTFS_RETURNS_INT 1)

IF(CMAKE_COMPILER_IS_GNUXX)
CHECK_CXX_SOURCE_COMPILES("
 #include <cxxabi.h>
 int main(int argc, char **argv) 
  {
    char *foo= 0; int bar= 0;
    foo= abi::__cxa_demangle(foo, foo, 0, &bar);
    return 0;
  }"
  HAVE_ABI_CXA_DEMANGLE)
IF(HAVE_ABI_CXA_DEMANGLE)
 SET(HAVE_CXXABI_H 1)
ENDIF()
ENDIF()

CHECK_C_SOURCE_COMPILES_UNIX("
  int main(int argc, char **argv) 
  {
    extern char *__bss_start;
    return __bss_start ? 1 : 0;
  }"
HAVE_BSS_START)

CHECK_C_SOURCE_COMPILES_UNIX("
    int main()
    {
      extern void __attribute__((weak)) foo(void);
      return 0;
    }"
    HAVE_WEAK_SYMBOL
)


CHECK_CXX_SOURCE_COMPILES("
    #include <new>
    int main()
    {
      char *c = new char;
      return 0;
    }"
    HAVE_CXX_NEW
)

CHECK_CXX_SOURCE_COMPILES_UNIX("
    #undef inline
    #if !defined(SCO) && !defined(__osf__) && !defined(_REENTRANT)
    #define _REENTRANT
    #endif
    #include <pthread.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <netdb.h>
    int main()
    {

       struct hostent *foo =
1095 1096
       gethostbyaddr_r((const char *) 0,
          0, 0, (struct hostent *) 0, (char *) NULL,  0, (int *)0);
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
       return 0;
    }
  "
  HAVE_SOLARIS_STYLE_GETHOST)

CHECK_CXX_SOURCE_COMPILES_UNIX("
    #undef inline
    #if !defined(SCO) && !defined(__osf__) && !defined(_REENTRANT)
    #define _REENTRANT
    #endif
    #include <pthread.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <netdb.h>
    int main()
    {
       int ret = gethostbyname_r((const char *) 0,
	(struct hostent*) 0, (char*) 0, 0, (struct hostent **) 0, (int *) 0);
      return 0;
    }"
    HAVE_GETHOSTBYNAME_R_GLIBC2_STYLE)

CHECK_CXX_SOURCE_COMPILES_UNIX("
    #undef inline
    #if !defined(SCO) && !defined(__osf__) && !defined(_REENTRANT)
    #define _REENTRANT
    #endif
    #include <pthread.h>
    #include <sys/types.h>
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    #include <netdb.h>
    int main()
    {
      int ret = gethostbyname_r((const char *) 0, (struct hostent*) 0, (struct hostent_data*) 0);
      return 0;
    }"
    HAVE_GETHOSTBYNAME_R_RETURN_INT)

IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
 CHECK_SYMBOL_EXISTS(SHM_HUGETLB sys/shm.h  HAVE_DECL_SHM_HUGETLB)
 IF(HAVE_DECL_SHM_HUGETLB)
   SET(HAVE_LARGE_PAGES 1)
   SET(HUGETLB_USE_PROC_MEMINFO 1)
   SET(HAVE_LARGE_PAGE_OPTION 1)
  ENDIF()
ENDIF()

IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
 CHECK_SYMBOL_EXISTS(MHA_MAPSIZE_VA sys/mman.h  HAVE_DECL_MHA_MAPSIZE_VA)
 IF(HAVE_DECL_MHA_MAPSIZE_VA)
   SET(HAVE_SOLARIS_LARGE_PAGES 1)
   SET(HAVE_LARGE_PAGE_OPTION 1)
  ENDIF()
ENDIF()

Vladislav Vaintroub's avatar
merge  
Vladislav Vaintroub committed
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199
# Use of ALARMs to wakeup on timeout on sockets
#
# This feature makes use of a mutex and is a scalability hog we
# try to avoid using. However we need support for SO_SNDTIMEO and
# SO_RCVTIMEO socket options for this to work. So we will check
# if this feature is supported by a simple TRY_RUN macro. However
# on some OS's there is support for setting those variables but
# they are silently ignored. For those OS's we will not attempt
# to use SO_SNDTIMEO and SO_RCVTIMEO even if it is said to work.
# See Bug#29093 for the problem with SO_SND/RCVTIMEO on HP/UX.
# To use alarm is simple, simply avoid setting anything.

IF(WIN32)
  SET(HAVE_SOCKET_TIMEOUT 1)
ELSEIF(CMAKE_SYSTEM MATCHES "HP")
  SET(HAVE_SOCKET_TIMEOUT 0)
ELSEIF(CMAKE_CROSSCOMPILING)
  SET(HAVE_SOCKET_TIMEOUT 0)
ELSE()
SET(CMAKE_REQUIRED_LIBRARIES ${LIBNSL} ${LIBSOCKET}) 
CHECK_C_SOURCE_RUNS(
"
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/time.h>
 
 int main()
 {    
   int fd = socket(AF_INET, SOCK_STREAM, 0);
   struct timeval tv;
   int ret= 0;
   tv.tv_sec= 2;
   tv.tv_usec= 0;
   ret|= setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv));
   ret|= setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
   return !!ret;
 }
" HAVE_SOCKET_TIMEOUT)
ENDIF()

SET(NO_ALARM "${HAVE_SOCKET_TIMEOUT}" CACHE BOOL 
   "No need to use alarm to implement socket timeout")
MARK_AS_ADVANCED(NO_ALARM)

1200 1201 1202 1203 1204 1205 1206 1207 1208
IF(CMAKE_SYSTEM_NAME STREQUAL "AIX" OR CMAKE_SYSTEM_NAME STREQUAL "OS400")
  # xlC oddity - it complains about same inline function defined multiple times
  # in different compilation units
  INCLUDE(CheckCXXCompilerFlag)
  CHECK_CXX_COMPILER_FLAG("-qstaticinline" HAVE_QSTATICINLINE)
  IF(HAVE_QSTATICINLINE)
    SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -qstaticinline")
  ENDIF()

1209 1210
  # The following is required to export all symbols 
  # (also with leading underscore)
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226
  STRING(REPLACE  "-bexpall" "-bexpfull" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS
          ${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS})
  STRING(REPLACE  "-bexpall" "-bexpfull" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS
          ${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS})
ENDIF()

IF(CMAKE_COMPILER_IS_GNUCXX)
IF(WITH_ATOMIC_OPS STREQUAL "up")
  SET(MY_ATOMIC_MODE_DUMMY 1 CACHE BOOL "Assume single-CPU mode, no concurrency")
ELSEIF(WITH_ATOMIC_OPS STREQUAL "rwlocks")
  SET(MY_ATOMIC_MODE_RWLOCK 1 CACHE BOOL "Use pthread rwlocks for atomic ops")
ELSEIF(WITH_ATOMIC_OPS STREQUAL "smp")
ELSEIF(NOT WITH_ATOMIC_OPS)
  CHECK_CXX_SOURCE_COMPILES("
  int main()
  {
Vladislav Vaintroub's avatar
merge  
Vladislav Vaintroub committed
1227 1228
    int foo= -10; int bar= 10;
    long long int foo64= -10; long long int bar64= 10;
1229 1230 1231 1232
    if (!__sync_fetch_and_add(&foo, bar) || foo)
      return -1;
    bar= __sync_lock_test_and_set(&foo, bar);
    if (bar || foo != 10)
Vladislav Vaintroub's avatar
merge  
Vladislav Vaintroub committed
1233
      return -1;
1234 1235 1236
    bar= __sync_val_compare_and_swap(&bar, foo, 15);
    if (bar)
      return -1;
Vladislav Vaintroub's avatar
merge  
Vladislav Vaintroub committed
1237 1238 1239 1240 1241 1242 1243 1244
    if (!__sync_fetch_and_add(&foo64, bar64) || foo64)
      return -1;
    bar64= __sync_lock_test_and_set(&foo64, bar64);
    if (bar64 || foo64 != 10)
      return -1;
    bar64= __sync_val_compare_and_swap(&bar64, foo, 15);
    if (bar64)
      return -1;
1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
    return 0;
  }"
  HAVE_GCC_ATOMIC_BUILTINS)
ELSE()
  MESSAGE(FATAL_ERROR "${WITH_ATOMIC_OPS} is not a valid value for WITH_ATOMIC_OPS!")
ENDIF()
ENDIF()

SET(WITH_ATOMIC_LOCKS "${WITH_ATOMIC_LOCKS}" CACHE STRING
"Implement atomic operations using pthread rwlocks or atomic CPU
instructions for multi-processor or uniprocessor
configuration. By default gcc built-in sync functions are used,
if available and 'smp' configuration otherwise.")
MARK_AS_ADVANCED(WITH_ATOMIC_LOCKS MY_ATOMIC_MODE_RWLOCK MY_ATOMIC_MODE_DUMMY)

IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
 CHECK_C_SOURCE_RUNS(
 "
 #include  <atomic.h>
  int main()
  {
Vladislav Vaintroub's avatar
merge  
Vladislav Vaintroub committed
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286
    int foo = -10; int bar = 10;
    int64_t foo64 = -10; int64_t bar64 = 10;
    if (atomic_add_int_nv((uint_t *)&foo, bar) || foo)
      return -1;
    bar = atomic_swap_uint((uint_t *)&foo, (uint_t)bar);
    if (bar || foo != 10)
     return -1;
    bar = atomic_cas_uint((uint_t *)&bar, (uint_t)foo, 15);
    if (bar)
      return -1;
    if (atomic_add_64_nv((volatile uint64_t *)&foo64, bar64) || foo64)
      return -1;
    bar64 = atomic_swap_64((volatile uint64_t *)&foo64, (uint64_t)bar64);
    if (bar64 || foo64 != 10)
      return -1;
    bar64 = atomic_cas_64((volatile uint64_t *)&bar64, (uint_t)foo64, 15);
    if (bar64)
      return -1;
    atomic_or_64((volatile uint64_t *)&bar64, 0);
    return 0;
  }
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384
"  HAVE_SOLARIS_ATOMIC)
ENDIF()

#--------------------------------------------------------------------
# Check for IPv6 support
#--------------------------------------------------------------------
CHECK_INCLUDE_FILE(netinet/in6.h HAVE_NETINET_IN6_H)

IF(UNIX)
  SET(CMAKE_EXTRA_INCLUDE_FILES sys/types.h netinet/in.h sys/socket.h)
  IF(HAVE_NETINET_IN6_H)
    SET(CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES} netinet/in6.h)
  ENDIF()
ELSEIF(WIN32)
  SET(CMAKE_EXTRA_INCLUDE_FILES ${CMAKE_EXTRA_INCLUDE_FILES} winsock2.h ws2ipdef.h)
ENDIF()

CHECK_TYPE_SIZE("struct sockaddr_in6" SIZEOF_SOCKADDR_IN6)
CHECK_TYPE_SIZE("struct in6_addr" SIZEOF_IN6_ADDR)
IF(SIZEOF_SOCKADDR_IN6)
  SET(HAVE_STRUCT_SOCKADDR_IN6 1)
ENDIF()
IF(SIZEOF_IN6_ADDR)
  SET(HAVE_STRUCT_IN6_ADDR 1)
ENDIF()

IF(HAVE_STRUCT_SOCKADDR_IN6 OR HAVE_STRUCT_IN6_ADDR)
  SET(HAVE_IPV6 TRUE CACHE INTERNAL "")
ENDIF()


# Check for sockaddr_storage.ss_family
# It is called differently under OS400 and older AIX

CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage"
 ss_family "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_SOCKADDR_STORAGE_SS_FAMILY)
IF(NOT HAVE_SOCKADDR_STORAGE_SS_FAMILY)
  CHECK_STRUCT_HAS_MEMBER("struct sockaddr_storage"
  __ss_family "${CMAKE_EXTRA_INCLUDE_FILES}" HAVE_SOCKADDR_STORAGE___SS_FAMILY)
  IF(HAVE_SOCKADDR_STORAGE___SS_FAMILY)
    SET(ss_family __ss_family)
  ENDIF()
ENDIF()
SET(CMAKE_EXTRA_INCLUDE_FILES) 

CHECK_STRUCT_HAS_MEMBER("struct dirent" d_ino "dirent.h"  STRUCT_DIRENT_HAS_D_INO)
CHECK_STRUCT_HAS_MEMBER("struct dirent" d_namlen "dirent.h"  STRUCT_DIRENT_HAS_D_NAMLEN)
SET(SPRINTF_RETURNS_INT 1)

IF(WIN32)
  SET(SIGNAL_WITH_VIO_CLOSE 1)
  CHECK_SYMBOL_REPLACEMENT(S_IROTH _S_IREAD sys/stat.h)
  CHECK_SYMBOL_REPLACEMENT(S_IFIFO _S_IFIFO sys/stat.h)
  CHECK_SYMBOL_REPLACEMENT(SIGQUIT SIGTERM signal.h)
  CHECK_SYMBOL_REPLACEMENT(SIGPIPE SIGINT signal.h)
  CHECK_SYMBOL_REPLACEMENT(isnan _isnan float.h)
  CHECK_SYMBOL_REPLACEMENT(finite _finite float.h)
  CHECK_FUNCTION_REPLACEMENT(popen _popen)
  CHECK_FUNCTION_REPLACEMENT(pclose _pclose)
  CHECK_FUNCTION_REPLACEMENT(access _access)
  CHECK_FUNCTION_REPLACEMENT(strcasecmp _stricmp)
  CHECK_FUNCTION_REPLACEMENT(strncasecmp _strnicmp)
  CHECK_FUNCTION_REPLACEMENT(snprintf _snprintf)
  CHECK_FUNCTION_REPLACEMENT(strtok_r strtok_s)
  CHECK_FUNCTION_REPLACEMENT(strtoll _strtoi64)
  CHECK_FUNCTION_REPLACEMENT(strtoull _strtoui64)
  CHECK_TYPE_SIZE(ssize_t SIZE_OF_SSIZE_T)
  IF(NOT SIZE_OF_SSIZE_T)
    SET(ssize_t SSIZE_T)
  ENDIF()


  # IPv6 definition (appeared in Vista SDK first)
  CHECK_C_SOURCE_COMPILES("
  #include <winsock2.h>
  int main()
  {
    return IPPROTO_IPV6;
  }"
  HAVE_IPPROTO_IPV6)
  
  CHECK_C_SOURCE_COMPILES("
  #include <winsock2.h>
  #include <ws2ipdef.h>
  int main()
  {
    return IPV6_V6ONLY;
  }"
  HAVE_IPV6_V6ONLY)

  IF(NOT HAVE_IPPROTO_IPV6)
    SET(HAVE_IPPROTO_IPV6 41)
  ENDIF()
  IF(NOT HAVE_IPV6_V6ONLY)
    SET(IPV6_V6ONLY 27)
  ENDIF()

ENDIF(WIN32)