
########## CHECK FOR HEADER FILES ############

INCLUDE(CheckIncludeFiles)

# Probe for timer header files
CHECK_INCLUDE_FILES("mach/mach_time.h" NNTI_HAVE_MACH_TIME_H)
CHECK_INCLUDE_FILES("mach/mach.h" NNTI_HAVE_MACH_MACH_H)
CHECK_INCLUDE_FILES("mach/clock.h" NNTI_HAVE_MACH_CLOCK_H)
CHECK_INCLUDE_FILES("time.h" NNTI_HAVE_TIME_H)
CHECK_INCLUDE_FILES("sys/time.h" NNTI_HAVE_SYS_TIME_H)

if (TPL_ENABLE_PAPI)
  CHECK_INCLUDE_FILES("papi.h" NNTI_HAVE_PAPI_H)
endif (TPL_ENABLE_PAPI)

########## CHECK FOR FUNCTIONS ############

INCLUDE(CheckLibraryExists)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckCSourceCompiles)
INCLUDE(CheckCXXSourceCompiles)

# clock_gettime
IF (NNTI_HAVE_TIME_H)
  CHECK_LIBRARY_EXISTS(rt clock_gettime "" NNTI_HAVE_CLOCK_GETTIME)
  IF (NNTI_HAVE_CLOCK_GETTIME)
    SET(CMAKE_REQUIRED_LIBRARIES "rt;${CMAKE_REQUIRED_LIBRARIES}")
    SET(NNTI_TIMERS_LIBRARIES rt)
  ENDIF (NNTI_HAVE_CLOCK_GETTIME)
ENDIF(NNTI_HAVE_TIME_H)

# gettimeofday
IF (NNTI_HAVE_SYS_TIME_H)
  CHECK_FUNCTION_EXISTS(gettimeofday NNTI_HAVE_GETTIMEOFDAY)
ENDIF (NNTI_HAVE_SYS_TIME_H)

# papi
IF (NNTI_HAVE_PAPI_H)
  CHECK_FUNCTION_EXISTS(PAPI_get_real_usec NNTI_HAVE_PAPI_GET_REAL_USEC)
  SET(NNTI_HAVE_PAPI ${NNTI_HAVE_PAPI_GET_REAL_USEC})
ENDIF (NNTI_HAVE_PAPI_H)

# mach_absolute_time (on apple)
IF (NNTI_HAVE_MACH_TIME_H)
  CHECK_FUNCTION_EXISTS(mach_absolute_time NNTI_HAVE_MACH_ABSOLUTE_TIME)
ENDIF (NNTI_HAVE_MACH_TIME_H)

# clock_get_time (apple)
IF (NNTI_HAVE_MACH_CLOCK_H)
  CHECK_FUNCTION_EXISTS(clock_get_time NNTI_HAVE_CLOCK_GET_TIME)
ENDIF (NNTI_HAVE_MACH_CLOCK_H)


