-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This version is a bit more robust when it comes to linking against librt for clock_gettime. If we can't find clock_gettime we don't use it, even if the headers advertise it. If we do manage to find clock_gettime, we explicitly define a preprocessor symbol so the code knows it is available.
- Loading branch information
Showing
4 changed files
with
34 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,28 @@ | ||
include (CheckFunctionExists) | ||
|
||
set (CMAKE_REQUIRED_LIBRARIES_orig ${CMAKE_REQUIRED_LIBRARIES}) | ||
check_function_exists (clock_gettime res) | ||
if (NOT res EQUAL 1) | ||
set (CMAKE_REQUIRED_LIBRARIES rt) | ||
check_function_exists (clock_gettime CLOCK_GETTIME_REQUIRES_RT) | ||
endif () | ||
set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_orig}) | ||
set(CLOCK_GETTIME_LIBRARIES "") | ||
set(CMAKE_REQUIRED_LIBRARIES_orig ${CMAKE_REQUIRED_LIBRARIES}) | ||
check_function_exists(clock_gettime CLOCK_GETTIME_FOUND) | ||
if(CLOCK_GETTIME_FOUND) | ||
set(CLOCK_GETTIME_LIBRARIES) | ||
else() | ||
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_orig} rt) | ||
check_function_exists(clock_gettime CLOCK_GETTIME_FOUND) | ||
if(CLOCK_GETTIME_FOUND) | ||
set(CLOCK_GETTIME_LIBRARIES rt) | ||
else() | ||
# mingw puts clock_gettime in pthreads | ||
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_orig} pthread) | ||
check_function_exists(clock_gettime CLOCK_GETTIME_FOUND) | ||
if(CLOCK_GETTIME_FOUND) | ||
set(CLOCK_GETTIME_LIBRARIES pthread) | ||
endif() | ||
endif() | ||
endif() | ||
|
||
set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES_orig}) | ||
unset(CMAKE_REQUIRED_LIBRARIES_orig) | ||
|
||
set(CLOCK_GETTIME_FOULD "${CLOCK_GETTIME_FOUND}" PARENT_SCOPE) | ||
set(CLOCK_GETTIME_LIBRARIES "${CLOCK_GETTIME_LIBRARIES}" PARENT_SCOPE) | ||
mark_as_advanced(CLOCK_GETTIME_FOUND CLOCK_GETTIME_LIBRARIES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters