|
| 1 | +#[=======================================================================[ |
| 2 | +FindClockGettime |
| 3 | +---------------- |
| 4 | +
|
| 5 | +Finds the clock_gettime() POSIX function on the system. |
| 6 | +
|
| 7 | +Imported Targets |
| 8 | +^^^^^^^^^^^^^^^^ |
| 9 | +
|
| 10 | +This module provides the following Imported Targets: |
| 11 | +
|
| 12 | +POSIX::clock_gettime |
| 13 | + Target encapsulating the clock_gettime() usage requirements, available |
| 14 | + only if clock_gettime() is found. |
| 15 | +
|
| 16 | +#]=======================================================================] |
| 17 | + |
| 18 | +include(CheckSymbolExists) |
| 19 | +include(CMakePushCheckState) |
| 20 | + |
| 21 | +cmake_push_check_state(RESET) |
| 22 | + |
| 23 | +set(CMAKE_REQUIRED_DEFINITIONS -D_POSIX_C_SOURCE=199309L) |
| 24 | +check_symbol_exists(clock_gettime "time.h" CLOCK_GETTIME_IS_BUILT_IN) |
| 25 | +set(${CMAKE_FIND_PACKAGE_NAME}_FOUND ${CLOCK_GETTIME_IS_BUILT_IN}) |
| 26 | + |
| 27 | +if(NOT ${CMAKE_FIND_PACKAGE_NAME}_FOUND) |
| 28 | + set(CMAKE_REQUIRED_LIBRARIES rt) |
| 29 | + check_symbol_exists(clock_gettime "time.h" CLOCK_GETTIME_NEEDS_LINK_TO_LIBRT) |
| 30 | + set(${CMAKE_FIND_PACKAGE_NAME}_FOUND ${CLOCK_GETTIME_NEEDS_LINK_TO_LIBRT}) |
| 31 | +endif() |
| 32 | + |
| 33 | +if(${CMAKE_FIND_PACKAGE_NAME}_FOUND) |
| 34 | + if(NOT TARGET POSIX::clock_gettime) |
| 35 | + add_library(POSIX::clock_gettime INTERFACE IMPORTED) |
| 36 | + set_target_properties(POSIX::clock_gettime PROPERTIES |
| 37 | + INTERFACE_COMPILE_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}" |
| 38 | + INTERFACE_LINK_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}" |
| 39 | + ) |
| 40 | + endif() |
| 41 | +else() |
| 42 | + if(${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) |
| 43 | + message(FATAL_ERROR "clock_gettime() not available.") |
| 44 | + endif() |
| 45 | +endif() |
| 46 | + |
| 47 | +cmake_pop_check_state() |
0 commit comments