aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2011-02-21 19:03:13 -0800
committerJosh Blum <josh@joshknows.com>2011-02-21 19:03:13 -0800
commita8bb5ec900d8f2d3d2f274a921d19b564c668323 (patch)
treea3f87f539a8ff641cd6580c0ea28d38adcd0b057 /host
parenta7f9529f77700309dbaaa6250f6bd775bab7a70d (diff)
downloaduhd-a8bb5ec900d8f2d3d2f274a921d19b564c668323.tar.gz
uhd-a8bb5ec900d8f2d3d2f274a921d19b564c668323.tar.bz2
uhd-a8bb5ec900d8f2d3d2f274a921d19b564c668323.zip
uhd: replace header checks in cmake files with more robust compile checks for features
implemented different ifdefs in the cpp files
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/transport/if_addrs.hpp1
-rw-r--r--host/lib/transport/CMakeLists.txt25
-rw-r--r--host/lib/transport/if_addrs.cpp16
-rw-r--r--host/lib/utils/CMakeLists.txt43
-rw-r--r--host/lib/utils/load_modules.cpp14
-rw-r--r--host/lib/utils/thread_priority.cpp10
6 files changed, 70 insertions, 39 deletions
diff --git a/host/include/uhd/transport/if_addrs.hpp b/host/include/uhd/transport/if_addrs.hpp
index c831750d7..689aff42c 100644
--- a/host/include/uhd/transport/if_addrs.hpp
+++ b/host/include/uhd/transport/if_addrs.hpp
@@ -31,7 +31,6 @@ namespace uhd{ namespace transport{
std::string inet;
std::string mask;
std::string bcast;
- if_addrs_t(void);
};
/*!
diff --git a/host/lib/transport/CMakeLists.txt b/host/lib/transport/CMakeLists.txt
index e58957154..a5bf9c5f1 100644
--- a/host/lib/transport/CMakeLists.txt
+++ b/host/lib/transport/CMakeLists.txt
@@ -48,20 +48,31 @@ ENDIF(ENABLE_USB)
########################################################################
MESSAGE(STATUS "")
MESSAGE(STATUS "Configuring interface address discovery...")
-
+INCLUDE(CheckCXXSourceCompiles)
INCLUDE(CheckIncludeFileCXX)
-CHECK_INCLUDE_FILE_CXX(ifaddrs.h HAVE_IFADDRS_H)
+
+CHECK_CXX_SOURCE_COMPILES("
+ #include <ifaddrs.h>
+ int main(){
+ struct ifaddrs *ifap;
+ getifaddrs(&ifap);
+ return 0;
+ }
+ " HAVE_GETIFADDRS
+)
+
CHECK_INCLUDE_FILE_CXX(winsock2.h HAVE_WINSOCK2_H)
-IF(HAVE_IFADDRS_H)
+IF(HAVE_GETIFADDRS)
MESSAGE(STATUS " Interface address discovery supported through getifaddrs.")
- SET(IF_ADDRS_DEFS HAVE_IFADDRS_H)
+ SET(IF_ADDRS_DEFS HAVE_GETIFADDRS)
ELSEIF(HAVE_WINSOCK2_H)
MESSAGE(STATUS " Interface address discovery supported through SIO_GET_INTERFACE_LIST.")
- SET(IF_ADDRS_DEFS HAVE_WINSOCK2_H)
-ELSE(HAVE_IFADDRS_H)
+ SET(IF_ADDRS_DEFS HAVE_SIO_GET_INTERFACE_LIST)
+ELSE()
MESSAGE(STATUS " Interface address discovery not supported.")
-ENDIF(HAVE_IFADDRS_H)
+ SET(IF_ADDRS_DEFS HAVE_IF_ADDRS_DUMMY)
+ENDIF()
SET_SOURCE_FILES_PROPERTIES(
${CMAKE_CURRENT_SOURCE_DIR}/if_addrs.cpp
diff --git a/host/lib/transport/if_addrs.cpp b/host/lib/transport/if_addrs.cpp
index 17cf8455b..b7c8ad844 100644
--- a/host/lib/transport/if_addrs.cpp
+++ b/host/lib/transport/if_addrs.cpp
@@ -20,14 +20,10 @@
#include <boost/cstdint.hpp>
#include <iostream>
-uhd::transport::if_addrs_t::if_addrs_t(void){
- /* NOP */
-}
-
/***********************************************************************
* Interface address discovery through ifaddrs api
**********************************************************************/
-#if defined(HAVE_IFADDRS_H)
+#ifdef HAVE_GETIFADDRS
#include <ifaddrs.h>
static boost::asio::ip::address_v4 sockaddr_to_ip_addr(sockaddr *addr){
@@ -59,10 +55,12 @@ std::vector<uhd::transport::if_addrs_t> uhd::transport::get_if_addrs(void){
return if_addrs;
}
+#endif /* HAVE_GETIFADDRS */
+
/***********************************************************************
* Interface address discovery through windows api
**********************************************************************/
-#elif defined(HAVE_WINSOCK2_H)
+#ifdef HAVE_SIO_GET_INTERFACE_LIST
#include <winsock2.h>
std::vector<uhd::transport::if_addrs_t> uhd::transport::get_if_addrs(void){
@@ -98,13 +96,15 @@ std::vector<uhd::transport::if_addrs_t> uhd::transport::get_if_addrs(void){
return if_addrs;
}
+#endif /* HAVE_SIO_GET_INTERFACE_LIST */
+
/***********************************************************************
* Interface address discovery not included
**********************************************************************/
-#else /* HAVE_IFADDRS_H */
+#ifdef HAVE_IF_ADDRS_DUMMY
std::vector<uhd::transport::if_addrs_t> uhd::transport::get_if_addrs(void){
return std::vector<if_addrs_t>();
}
-#endif /* HAVE_IFADDRS_H */
+#endif /* HAVE_IF_ADDRS_DUMMY */
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 <pthread.h>
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 <dlfcn.h>
+ int main(){
+ dlopen(0, 0);
+ return 0;
+ }
+ " HAVE_DLOPEN
+)
+UNSET(CMAKE_REQUIRED_LIBRARIES)
+
+CHECK_CXX_SOURCE_COMPILES("
+ #include <windows.h>
+ 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 <dlfcn.h>
-
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 <windows.h>
+#ifdef HAVE_LOAD_LIBRARY
+#include <windows.h>
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 <pthread.h>
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 <windows.h>
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 */