From ae26f969c9c260556aad4ffd006fea96f3452d01 Mon Sep 17 00:00:00 2001 From: gnieboer <gnieboer@corpcomm.net> Date: Sun, 7 Feb 2016 00:03:00 +0300 Subject: MSVC-specific changes for compatibility * Changed gr-dtv cmake so SSE2 would be detected on both MSVC and GCC compilers * Removed addition of /O2 flag on MSVC builds as it conflicts with /RTC1 flag * Added detection of MSVC 14.0 and added additional filenames to library detection to cover what windows builds the dependencies as. * Additional name options were placed at end so as to not conflict with other builds. * Removed use of not() function and replaced with standard C syntax. The check for zero is to handle the edge case where the random numbers return zero and would cause a div/zero error two lines afterwards. * Add dwrite library for win32 builds for qtgui --- cmake/Modules/FindGSL.cmake | 2 +- cmake/Modules/FindQwt.cmake | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'cmake') diff --git a/cmake/Modules/FindGSL.cmake b/cmake/Modules/FindGSL.cmake index b36a1e9c2a..7b8c6cdb64 100644 --- a/cmake/Modules/FindGSL.cmake +++ b/cmake/Modules/FindGSL.cmake @@ -44,7 +44,7 @@ if( WIN32 AND NOT CYGWIN AND NOT MSYS ) # look for gsl cblas library find_library( GSL_CBLAS_LIBRARY - NAMES gslcblas + NAMES gslcblas cblas ) if( GSL_CBLAS_LIBRARY ) set( GSL_CBLAS_FOUND ON ) diff --git a/cmake/Modules/FindQwt.cmake b/cmake/Modules/FindQwt.cmake index 3ce49aa04b..da8bbe9049 100644 --- a/cmake/Modules/FindQwt.cmake +++ b/cmake/Modules/FindQwt.cmake @@ -9,6 +9,7 @@ find_path(QWT_INCLUDE_DIRS NAMES qwt_global.h HINTS ${CMAKE_INSTALL_PREFIX}/include/qwt + ${CMAKE_PREFIX_PATH}/include/qwt PATHS /usr/local/include/qwt-qt4 /usr/local/include/qwt @@ -22,10 +23,11 @@ find_path(QWT_INCLUDE_DIRS ) find_library (QWT_LIBRARIES - NAMES qwt6 qwt6-qt4 qwt qwt-qt4 + NAMES qwt6 qwt6-qt4 qwt qwt-qt4 qwt5 qwtd5 HINTS ${CMAKE_INSTALL_PREFIX}/lib ${CMAKE_INSTALL_PREFIX}/lib64 + ${CMAKE_PREFIX_PATH}/lib PATHS /usr/local/lib /usr/lib -- cgit v1.2.3 From 25142dad0464bed59dc03672931aab637f82d376 Mon Sep 17 00:00:00 2001 From: Paul Cercueil <paul.cercueil@analog.com> Date: Mon, 14 Sep 2015 14:53:35 +0200 Subject: cmake: Windows-specific fixes for compatibility * Properly wrap the prefix variables in quotation marks. This allows to set an empty prefix. * Fix library names when compiling for Windows. This now also works when using mingw-w64. * Fix boost module name when compiling with mingw-w64 * Fix build under mingw-w64 * Fix config.h header to avoid macro redefinition * Remove duplicated Boost::thread entry in dependencies list --- CMakeLists.txt | 4 +- cmake/Modules/GrBoost.cmake | 7 ++- cmake/msvc/config.h | 7 +++ gnuradio-runtime/include/gnuradio/high_res_timer.h | 2 +- gnuradio-runtime/lib/CMakeLists.txt | 8 +-- gnuradio-runtime/lib/flat_flowgraph.cc | 4 +- gnuradio-runtime/lib/realtime_impl.cc | 70 +++++++++++----------- gnuradio-runtime/lib/thread/thread.cc | 10 +++- gnuradio-runtime/lib/thread/thread_body_wrapper.cc | 2 +- gnuradio-runtime/lib/tpb_thread_body.cc | 4 +- gr-blocks/lib/ConfigChecks.cmake | 2 +- 11 files changed, 70 insertions(+), 50 deletions(-) (limited to 'cmake') diff --git a/CMakeLists.txt b/CMakeLists.txt index 9cf7ac796a..622b724b38 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,7 +59,7 @@ ENDIF() # Environment setup ######################################################################## IF(NOT DEFINED BOOST_ROOT) - SET(BOOST_ROOT ${CMAKE_INSTALL_PREFIX}) + SET(BOOST_ROOT "${CMAKE_INSTALL_PREFIX}") ENDIF() ######################################################################## @@ -162,7 +162,7 @@ set(GR_THEMES_DIR ${GR_PKG_DATA_DIR}/themes CACHE PATH "Path to install QTG # Set location of config/prefs files in /etc # Special exception if prefix is /usr so we don't make a /usr/etc. set(GR_CONF_DIR etc CACHE PATH "Path to install config files") -string(COMPARE EQUAL ${CMAKE_INSTALL_PREFIX} "/usr" isusr) +string(COMPARE EQUAL "${CMAKE_INSTALL_PREFIX}" "/usr" isusr) if(isusr) set(SYSCONFDIR "/${GR_CONF_DIR}" CACHE PATH "System configuration directory") else(isusr) diff --git a/cmake/Modules/GrBoost.cmake b/cmake/Modules/GrBoost.cmake index ecf58a9367..6e036a5bdc 100644 --- a/cmake/Modules/GrBoost.cmake +++ b/cmake/Modules/GrBoost.cmake @@ -31,10 +31,15 @@ set(BOOST_REQUIRED_COMPONENTS program_options filesystem system - thread regex ) +if (MINGW) + set(BOOST_REQUIRED_COMPONENTS ${BOOST_REQUIRED_COMPONENTS} thread_win32) +else(MINGW) + set(BOOST_REQUIRED_COMPONENTS ${BOOST_REQUIRED_COMPONENTS} thread) +endif(MINGW) + if(UNIX AND NOT BOOST_ROOT AND EXISTS "/usr/lib64") list(APPEND BOOST_LIBRARYDIR "/usr/lib64") #fedora 64-bit fix endif(UNIX AND NOT BOOST_ROOT AND EXISTS "/usr/lib64") diff --git a/cmake/msvc/config.h b/cmake/msvc/config.h index 43792c7837..50515104db 100644 --- a/cmake/msvc/config.h +++ b/cmake/msvc/config.h @@ -21,19 +21,25 @@ typedef ptrdiff_t ssize_t; //////////////////////////////////////////////////////////////////////// // rint functions //////////////////////////////////////////////////////////////////////// +#define _USE_MATH_DEFINES #include <math.h> +#if _MSC_VER < 1800 static inline long lrint(double x){return (long)(x > 0.0 ? x + 0.5 : x - 0.5);} static inline long lrintf(float x){return (long)(x > 0.0f ? x + 0.5f : x - 0.5f);} static inline long long llrint(double x){return (long long)(x > 0.0 ? x + 0.5 : x - 0.5);} static inline long long llrintf(float x){return (long long)(x > 0.0f ? x + 0.5f : x - 0.5f);} static inline double rint(double x){return (x > 0.0)? floor(x + 0.5) : ceil(x - 0.5);} static inline float rintf(float x){return (x > 0.0f)? floorf(x + 0.5f) : ceilf(x - 0.5f);} +#endif //////////////////////////////////////////////////////////////////////// // math constants //////////////////////////////////////////////////////////////////////// +#ifndef INFINITY #define INFINITY HUGE_VAL +#endif +#ifndef _MATH_DEFINES_DEFINED # define M_E 2.7182818284590452354 /* e */ # define M_LOG2E 1.4426950408889634074 /* log_2 e */ # define M_LOG10E 0.43429448190325182765 /* log_10 e */ @@ -47,6 +53,7 @@ static inline float rintf(float x){return (x > 0.0f)? floorf(x + 0.5f) : ceilf(x # define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ # define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ # define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ +#endif //////////////////////////////////////////////////////////////////////// // random and srandom diff --git a/gnuradio-runtime/include/gnuradio/high_res_timer.h b/gnuradio-runtime/include/gnuradio/high_res_timer.h index ce11cd8ebb..5f6a285a11 100644 --- a/gnuradio-runtime/include/gnuradio/high_res_timer.h +++ b/gnuradio-runtime/include/gnuradio/high_res_timer.h @@ -107,7 +107,7 @@ namespace gr { //////////////////////////////////////////////////////////////////////// #ifdef GNURADIO_HRT_USE_QUERY_PERFORMANCE_COUNTER - #include <Windows.h> + #include <windows.h> inline gr::high_res_timer_type gr::high_res_timer_now(void){ LARGE_INTEGER counts; diff --git a/gnuradio-runtime/lib/CMakeLists.txt b/gnuradio-runtime/lib/CMakeLists.txt index cc51f97855..3da550d37b 100644 --- a/gnuradio-runtime/lib/CMakeLists.txt +++ b/gnuradio-runtime/lib/CMakeLists.txt @@ -31,9 +31,9 @@ message(STATUS "Loading build date ${BUILD_DATE} into constants...") message(STATUS "Loading version ${VERSION} into constants...") #double escape for windows backslash path separators -string(REPLACE "\\" "\\\\" prefix ${prefix}) -string(REPLACE "\\" "\\\\" SYSCONFDIR ${SYSCONFDIR}) -string(REPLACE "\\" "\\\\" GR_PREFSDIR ${GR_PREFSDIR}) +string(REPLACE "\\" "\\\\" prefix "${prefix}") +string(REPLACE "\\" "\\\\" SYSCONFDIR "${SYSCONFDIR}") +string(REPLACE "\\" "\\\\" GR_PREFSDIR "${GR_PREFSDIR}") configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/constants.cc.in @@ -149,7 +149,7 @@ CHECK_INCLUDE_FILE_CXX(windows.h HAVE_WINDOWS_H) IF(HAVE_WINDOWS_H) ADD_DEFINITIONS(-DHAVE_WINDOWS_H -DUSING_WINSOCK -DWIN32_LEAN_AND_MEAN) MESSAGE(STATUS "Adding windows libs to gnuradio runtime libs...") - LIST(APPEND gnuradio_runtime_libs WS2_32.lib WSock32.lib) + LIST(APPEND gnuradio_runtime_libs ws2_32 wsock32) ENDIF(HAVE_WINDOWS_H) #need to link with librt on ubuntu 11.10 for shm_* diff --git a/gnuradio-runtime/lib/flat_flowgraph.cc b/gnuradio-runtime/lib/flat_flowgraph.cc index 81c1184cfa..82680bfc2d 100644 --- a/gnuradio-runtime/lib/flat_flowgraph.cc +++ b/gnuradio-runtime/lib/flat_flowgraph.cc @@ -320,7 +320,7 @@ namespace gr { const int alignment = volk_get_alignment(); for(int i = 0; i < block->detail()->ninputs(); i++) { void *r = (void*)block->detail()->input(i)->read_pointer(); - unsigned long int ri = (unsigned long int)r % alignment; + uintptr_t ri = (uintptr_t)r % alignment; //std::cerr << "reader: " << r << " alignment: " << ri << std::endl; if(ri != 0) { size_t itemsize = block->detail()->input(i)->get_sizeof_item(); @@ -332,7 +332,7 @@ namespace gr { for(int i = 0; i < block->detail()->noutputs(); i++) { void *w = (void*)block->detail()->output(i)->write_pointer(); - unsigned long int wi = (unsigned long int)w % alignment; + uintptr_t wi = (uintptr_t)w % alignment; //std::cerr << "writer: " << w << " alignment: " << wi << std::endl; if(wi != 0) { size_t itemsize = block->detail()->output(i)->get_sizeof_item(); diff --git a/gnuradio-runtime/lib/realtime_impl.cc b/gnuradio-runtime/lib/realtime_impl.cc index 54db9d8d70..83afd9568d 100644 --- a/gnuradio-runtime/lib/realtime_impl.cc +++ b/gnuradio-runtime/lib/realtime_impl.cc @@ -65,7 +65,41 @@ namespace gr { #endif -#if defined(HAVE_PTHREAD_SETSCHEDPARAM) +#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) + +#include <windows.h> + +namespace gr { + namespace impl { + + rt_status_t enable_realtime_scheduling(rt_sched_param p) + { + //set the priority class on the process + int pri_class = (true)? REALTIME_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS; + if(SetPriorityClass(GetCurrentProcess(), pri_class) == 0) + return RT_OTHER_ERROR; + + //scale the priority value to the constants + int priorities[] = { + THREAD_PRIORITY_IDLE, THREAD_PRIORITY_LOWEST, THREAD_PRIORITY_BELOW_NORMAL, THREAD_PRIORITY_NORMAL, + THREAD_PRIORITY_ABOVE_NORMAL, THREAD_PRIORITY_HIGHEST, THREAD_PRIORITY_TIME_CRITICAL + }; + const double priority = double(p.priority)/(rt_priority_max() - rt_priority_min()); + size_t pri_index = size_t((priority+1.0)*6/2.0); // -1 -> 0, +1 -> 6 + pri_index %= sizeof(priorities)/sizeof(*priorities); //range check + + //set the thread priority on the thread + if(SetThreadPriority(GetCurrentThread(), priorities[pri_index]) == 0) + return RT_OTHER_ERROR; + + //printf("SetPriorityClass + SetThreadPriority\n"); + return RT_OK; + } + + } // namespace impl +} // namespace gr + +#elif defined(HAVE_PTHREAD_SETSCHEDPARAM) namespace gr { namespace impl { @@ -141,40 +175,6 @@ namespace gr { } // namespace impl } // namespace gr -#elif defined(_WIN32) || defined(__WIN32__) || defined(WIN32) - -#include <windows.h> - -namespace gr { - namespace impl { - - rt_status_t enable_realtime_scheduling(rt_sched_param p) - { - //set the priority class on the process - int pri_class = (true)? REALTIME_PRIORITY_CLASS : NORMAL_PRIORITY_CLASS; - if(SetPriorityClass(GetCurrentProcess(), pri_class) == 0) - return RT_OTHER_ERROR; - - //scale the priority value to the constants - int priorities[] = { - THREAD_PRIORITY_IDLE, THREAD_PRIORITY_LOWEST, THREAD_PRIORITY_BELOW_NORMAL, THREAD_PRIORITY_NORMAL, - THREAD_PRIORITY_ABOVE_NORMAL, THREAD_PRIORITY_HIGHEST, THREAD_PRIORITY_TIME_CRITICAL - }; - const double priority = double(p.priority)/(rt_priority_max() - rt_priority_min()); - size_t pri_index = size_t((priority+1.0)*6/2.0); // -1 -> 0, +1 -> 6 - pri_index %= sizeof(priorities)/sizeof(*priorities); //range check - - //set the thread priority on the thread - if(SetThreadPriority(GetCurrentThread(), priorities[pri_index]) == 0) - return RT_OTHER_ERROR; - - //printf("SetPriorityClass + SetThreadPriority\n"); - return RT_OK; - } - - } // namespace impl -} // namespace gr - #else namespace gr { diff --git a/gnuradio-runtime/lib/thread/thread.cc b/gnuradio-runtime/lib/thread/thread.cc index 483dfed493..f2606c71ae 100644 --- a/gnuradio-runtime/lib/thread/thread.cc +++ b/gnuradio-runtime/lib/thread/thread.cc @@ -28,7 +28,7 @@ #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) -#include <Windows.h> +#include <windows.h> namespace gr { namespace thread { @@ -111,6 +111,7 @@ namespace gr { // Not implemented on Windows return -1; } +#ifndef __MINGW32__ #pragma pack(push,8) typedef struct tagTHREADNAME_INFO { @@ -152,6 +153,13 @@ namespace gr { _set_thread_name(thread, name.c_str(), dwThreadId); } +#else + void + set_thread_name(gr_thread_t thread, std::string name) + { + /* Not implemented on mingw-w64 */ + } +#endif /* !__MINGW32__ */ } /* namespace thread */ } /* namespace gr */ diff --git a/gnuradio-runtime/lib/thread/thread_body_wrapper.cc b/gnuradio-runtime/lib/thread/thread_body_wrapper.cc index e23b7d15d0..fffa7e4c44 100644 --- a/gnuradio-runtime/lib/thread/thread_body_wrapper.cc +++ b/gnuradio-runtime/lib/thread/thread_body_wrapper.cc @@ -34,7 +34,7 @@ namespace gr { namespace thread { -#if defined(HAVE_PTHREAD_SIGMASK) && defined(HAVE_SIGNAL_H) +#if defined(HAVE_PTHREAD_SIGMASK) && defined(HAVE_SIGNAL_H) && !defined(__MINGW32__) void mask_signals() { diff --git a/gnuradio-runtime/lib/tpb_thread_body.cc b/gnuradio-runtime/lib/tpb_thread_body.cc index e0aacb4153..e3f57eef53 100644 --- a/gnuradio-runtime/lib/tpb_thread_body.cc +++ b/gnuradio-runtime/lib/tpb_thread_body.cc @@ -37,8 +37,8 @@ namespace gr { { //std::cerr << "tpb_thread_body: " << block << std::endl; -#ifdef _MSC_VER - #include <Windows.h> +#if defined(_MSC_VER) || defined(__MINGW32__) + #include <windows.h> thread::set_thread_name(GetCurrentThread(), boost::str(boost::format("%s%d") % block->name() % block->unique_id())); #else thread::set_thread_name(pthread_self(), boost::str(boost::format("%s%d") % block->name() % block->unique_id())); diff --git a/gr-blocks/lib/ConfigChecks.cmake b/gr-blocks/lib/ConfigChecks.cmake index 7f60aed403..1effaa8360 100644 --- a/gr-blocks/lib/ConfigChecks.cmake +++ b/gr-blocks/lib/ConfigChecks.cmake @@ -56,7 +56,7 @@ CHECK_INCLUDE_FILE_CXX(windows.h HAVE_WINDOWS_H) IF(HAVE_WINDOWS_H) ADD_DEFINITIONS(-DHAVE_WINDOWS_H -DUSING_WINSOCK) MESSAGE(STATUS "Adding windows libs to gr blocks libs...") - LIST(APPEND blocks_libs WS2_32.lib WSock32.lib) + LIST(APPEND blocks_libs ws2_32 wsock32) ENDIF(HAVE_WINDOWS_H) ######################################################################## -- cgit v1.2.3