From a8bb5ec900d8f2d3d2f274a921d19b564c668323 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 21 Feb 2011 19:03:13 -0800 Subject: uhd: replace header checks in cmake files with more robust compile checks for features implemented different ifdefs in the cpp files --- host/lib/utils/CMakeLists.txt | 43 +++++++++++++++++++++++++++----------- host/lib/utils/load_modules.cpp | 14 ++++++------- host/lib/utils/thread_priority.cpp | 10 +++++---- 3 files changed, 44 insertions(+), 23 deletions(-) (limited to 'host/lib/utils') diff --git a/host/lib/utils/CMakeLists.txt b/host/lib/utils/CMakeLists.txt index 743528189..a4d3b2db2 100644 --- a/host/lib/utils/CMakeLists.txt +++ b/host/lib/utils/CMakeLists.txt @@ -24,8 +24,8 @@ ######################################################################## MESSAGE(STATUS "") MESSAGE(STATUS "Configuring priority scheduling...") - INCLUDE(CheckCXXSourceCompiles) + CHECK_CXX_SOURCE_COMPILES(" #include int main(){ @@ -52,9 +52,10 @@ IF(HAVE_PTHREAD_SETSCHEDPARAM) ELSEIF(HAVE_WIN_SETTHREADPRIORITY) MESSAGE(STATUS " Priority scheduling supported through windows SetThreadPriority.") SET(THREAD_PRIO_DEFS HAVE_WIN_SETTHREADPRIORITY) -ELSE(HAVE_PTHREAD_SETSCHEDPARAM) +ELSE() MESSAGE(STATUS " Priority scheduling not supported.") -ENDIF(HAVE_PTHREAD_SETSCHEDPARAM) + SET(THREAD_PRIO_DEFS HAVE_THREAD_PRIO_DUMMY) +ENDIF() SET_SOURCE_FILES_PROPERTIES( ${CMAKE_CURRENT_SOURCE_DIR}/thread_priority.cpp @@ -66,21 +67,39 @@ SET_SOURCE_FILES_PROPERTIES( ######################################################################## MESSAGE(STATUS "") MESSAGE(STATUS "Configuring module loading...") +INCLUDE(CheckCXXSourceCompiles) -INCLUDE(CheckIncludeFileCXX) -CHECK_INCLUDE_FILE_CXX(dlfcn.h HAVE_DLFCN_H) -CHECK_INCLUDE_FILE_CXX(windows.h HAVE_WINDOWS_H) +SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS}) +CHECK_CXX_SOURCE_COMPILES(" + #include + int main(){ + dlopen(0, 0); + return 0; + } + " HAVE_DLOPEN +) +UNSET(CMAKE_REQUIRED_LIBRARIES) + +CHECK_CXX_SOURCE_COMPILES(" + #include + int main(){ + LoadLibrary(0); + return 0; + } + " HAVE_LOAD_LIBRARY +) -IF(HAVE_DLFCN_H) +IF(HAVE_DLOPEN) MESSAGE(STATUS " Module loading supported through dlopen.") - SET(LOAD_MODULES_DEFS HAVE_DLFCN_H) + SET(LOAD_MODULES_DEFS HAVE_DLOPEN) LIBUHD_APPEND_LIBS(${CMAKE_DL_LIBS}) -ELSEIF(HAVE_WINDOWS_H) +ELSEIF(HAVE_LOAD_LIBRARY) MESSAGE(STATUS " Module loading supported through LoadLibrary.") - SET(LOAD_MODULES_DEFS HAVE_WINDOWS_H) -ELSE(HAVE_DLFCN_H) + SET(LOAD_MODULES_DEFS HAVE_LOAD_LIBRARY) +ELSE() MESSAGE(STATUS " Module loading not supported.") -ENDIF(HAVE_DLFCN_H) + SET(LOAD_MODULES_DEFS HAVE_LOAD_MODULES_DUMMY) +ENDIF() SET_SOURCE_FILES_PROPERTIES( ${CMAKE_CURRENT_SOURCE_DIR}/load_modules.cpp diff --git a/host/lib/utils/load_modules.cpp b/host/lib/utils/load_modules.cpp index 623d31eb6..fa9b22438 100644 --- a/host/lib/utils/load_modules.cpp +++ b/host/lib/utils/load_modules.cpp @@ -29,9 +29,8 @@ namespace fs = boost::filesystem; /*********************************************************************** * Module Load Function **********************************************************************/ -#if defined(HAVE_DLFCN_H) +#ifdef HAVE_DLOPEN #include - static void load_module(const std::string &file_name){ if (dlopen(file_name.c_str(), RTLD_LAZY) == NULL){ throw std::runtime_error(str( @@ -39,10 +38,11 @@ static void load_module(const std::string &file_name){ )); } } +#endif /* HAVE_DLOPEN */ -#elif defined(HAVE_WINDOWS_H) -#include +#ifdef HAVE_LOAD_LIBRARY +#include static void load_module(const std::string &file_name){ if (LoadLibrary(file_name.c_str()) == NULL){ throw std::runtime_error(str( @@ -50,16 +50,16 @@ static void load_module(const std::string &file_name){ )); } } +#endif /* HAVE_LOAD_LIBRARY */ -#else +#ifdef HAVE_LOAD_MODULES_DUMMY static void load_module(const std::string &file_name){ throw std::runtime_error(str( boost::format("Module loading not supported: Cannot load \"%s\"") % file_name )); } - -#endif +#endif /* HAVE_LOAD_MODULES_DUMMY */ /*********************************************************************** * Load Modules diff --git a/host/lib/utils/thread_priority.cpp b/host/lib/utils/thread_priority.cpp index 40b74f655..18f372ec0 100644 --- a/host/lib/utils/thread_priority.cpp +++ b/host/lib/utils/thread_priority.cpp @@ -44,7 +44,7 @@ static void check_priority_range(float priority){ /*********************************************************************** * Pthread API to set priority **********************************************************************/ -#if defined(HAVE_PTHREAD_SETSCHEDPARAM) +#ifdef HAVE_PTHREAD_SETSCHEDPARAM #include void uhd::set_thread_priority(float priority, bool realtime){ @@ -67,11 +67,12 @@ static void check_priority_range(float priority){ int ret = pthread_setschedparam(pthread_self(), policy, &sp); if (ret != 0) throw std::runtime_error("error in pthread_setschedparam"); } +#endif /* HAVE_PTHREAD_SETSCHEDPARAM */ /*********************************************************************** * Windows API to set priority **********************************************************************/ -#elif defined(HAVE_WIN_SETTHREADPRIORITY) +#ifdef HAVE_WIN_SETTHREADPRIORITY #include void uhd::set_thread_priority(float priority, bool realtime){ @@ -93,13 +94,14 @@ static void check_priority_range(float priority){ if (SetThreadPriority(GetCurrentThread(), priorities[pri_index]) == 0) throw std::runtime_error("error in SetThreadPriority"); } +#endif /* HAVE_WIN_SETTHREADPRIORITY */ /*********************************************************************** * Unimplemented API to set priority **********************************************************************/ -#else +#ifdef HAVE_LOAD_MODULES_DUMMY void uhd::set_thread_priority(float, bool){ throw std::runtime_error("set thread priority not implemented"); } -#endif /* HAVE_PTHREAD_SETSCHEDPARAM */ +#endif /* HAVE_LOAD_MODULES_DUMMY */ -- cgit v1.2.3