aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorNicholas Corgan <nick.corgan@ettus.com>2014-12-19 14:52:57 -0800
committerMartin Braun <martin.braun@ettus.com>2015-01-13 09:46:41 +0100
commit3f9ef46bc51acc5933721974e191d2a9659f6566 (patch)
tree9dc0b36ab3f9f70ce0a7d0629e1a56aa2b41aed1 /host
parentbe5f9613311d944b8971570bff444c5af094f0f5 (diff)
downloaduhd-3f9ef46bc51acc5933721974e191d2a9659f6566.tar.gz
uhd-3f9ef46bc51acc5933721974e191d2a9659f6566.tar.bz2
uhd-3f9ef46bc51acc5933721974e191d2a9659f6566.zip
Added support for MinGW cross-compile
* Added CMake toolchain file, compatible with different versions * No dependency on MinGW runtime, all statically linked * Misc coding tweaks to allow MinGW to compile
Diffstat (limited to 'host')
-rw-r--r--host/CMakeLists.txt16
-rw-r--r--host/cmake/Toolchains/mingw_cross.cmake69
-rw-r--r--host/include/uhd/config.hpp9
-rw-r--r--host/include/uhd/transport/nirio/nirio_driver_iface.h4
-rw-r--r--host/lib/transport/nirio/nifpga_lvbitx.cpp2
-rw-r--r--host/lib/utils/platform.cpp4
-rw-r--r--host/tests/CMakeLists.txt8
7 files changed, 104 insertions, 8 deletions
diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt
index 856f1ec70..6d87bf95d 100644
--- a/host/CMakeLists.txt
+++ b/host/CMakeLists.txt
@@ -137,6 +137,22 @@ IF(MSVC)
ADD_DEFINITIONS(/MP) #multi-threaded build
ENDIF(MSVC)
+IF(MINGW)
+ #Avoid depending on MinGW runtime DLLs
+ CHECK_CXX_COMPILER_FLAG(-static-libgcc HAVE_STATIC_LIBGCC_FLAG)
+ IF(HAVE_STATIC_LIBGCC_FLAG)
+ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
+ SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
+ SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libgcc")
+ ENDIF()
+ CHECK_CXX_COMPILER_FLAG(-static-libstdc++ HAVE_STATIC_LIBSTDCXX_FLAG)
+ IF(HAVE_STATIC_LIBSTDCXX_FLAG)
+ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++")
+ SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -static-libstdc++")
+ SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -static-libstdc++")
+ ENDIF()
+ENDIF()
+
IF(CYGWIN)
ADD_DEFINITIONS(-D__USE_W32_SOCKETS) #boost asio says we need this
ENDIF(CYGWIN)
diff --git a/host/cmake/Toolchains/mingw_cross.cmake b/host/cmake/Toolchains/mingw_cross.cmake
new file mode 100644
index 000000000..7c5adb002
--- /dev/null
+++ b/host/cmake/Toolchains/mingw_cross.cmake
@@ -0,0 +1,69 @@
+# Use this command:
+#
+# cmake -DCMAKE_TOOLCHAIN_FILE=cmake/Toolchain-mingw.cmake .
+#
+# or for out of source:
+#
+# cmake -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-mingw.cmake ..
+#
+# You will need at least CMake 2.6.0.
+#
+# Adjust the following paths to suit your environment.
+#
+# This file was based on http://www.cmake.org/Wiki/CmakeMingw
+
+# the name of the target operating system
+set(CMAKE_SYSTEM_NAME Windows)
+
+# Assume the target architecture.
+# XXX for some reason the value set here gets cleared before we reach the
+# main CMakeLists.txt; see that file for a workaround.
+# set(CMAKE_SYSTEM_PROCESSOR i686)
+
+# Which compilers to use for C and C++, and location of target
+# environment.
+if(EXISTS /usr/i586-mingw32msvc)
+ # First look in standard location as used by Debian/Ubuntu/etc.
+ set(CMAKE_C_COMPILER i586-mingw32msvc-gcc)
+ set(CMAKE_CXX_COMPILER i586-mingw32msvc-g++)
+ set(CMAKE_RC_COMPILER i586-mingw32msvc-windres)
+ set(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc)
+elseif(EXISTS /usr/i686-w64-mingw32)
+ # First look in standard location as used by Debian/Ubuntu/etc.
+ set(CMAKE_C_COMPILER i686-w64-mingw32-gcc)
+ set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++)
+ set(CMAKE_RC_COMPILER i686-w64-mingw32-windres)
+ set(CMAKE_AR:FILEPATH /usr/bin/i686-w64-mingw32-ar)
+elseif(EXISTS /opt/mingw)
+ # You can get a MinGW environment using the script at <http://mxe.cc>.
+ # It downloads and builds MinGW and most of the dependencies for you.
+ # You can use the toolchain file generated by MXE called `mxe-conf.cmake'
+ # or you can use this file by adjusting the above and following paths.
+ set(CMAKE_C_COMPILER /opt/mingw/usr/bin/i686-pc-mingw32-gcc)
+ set(CMAKE_CXX_COMPILER /opt/mingw/usr/bin/i686-pc-mingw32-g++)
+ set(CMAKE_RC_COMPILER /opt/mingw/usr/bin/i686-pc-mingw32-windres)
+ set(CMAKE_FIND_ROOT_PATH /opt/mingw/usr/i686-pc-mingw32)
+else()
+ # Else fill in local path which the user will likely adjust.
+ # This is the location assumed by <http://www.libsdl.org/extras/win32/cross/>
+ set(CMAKE_C_COMPILER /usr/local/cross-tools/bin/i386-mingw32-gcc)
+ set(CMAKE_CXX_COMPILER /usr/local/cross-tools/bin/i386-mingw32-g++)
+ set(CMAKE_RC_COMPILER /usr/local/cross-tools/bin/i386-mingw32-windres)
+ set(CMAKE_FIND_ROOT_PATH /usr/local/cross-tools)
+endif()
+
+# Adjust the default behaviour of the FIND_XXX() commands:
+# search headers and libraries in the target environment, search
+# programs in the host environment
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+
+# Tell pkg-config not to look at the target environment's .pc files.
+# Setting PKG_CONFIG_LIBDIR sets the default search directory, but we have to
+# set PKG_CONFIG_PATH as well to prevent pkg-config falling back to the host's
+# path.
+set(ENV{PKG_CONFIG_LIBDIR} ${CMAKE_FIND_ROOT_PATH}/lib/pkgconfig)
+set(ENV{PKG_CONFIG_PATH} ${CMAKE_FIND_ROOT_PATH}/lib/pkgconfig)
+
+set(ENV{MINGDIR} ${CMAKE_FIND_ROOT_PATH})
diff --git a/host/include/uhd/config.hpp b/host/include/uhd/config.hpp
index 619bd0787..173845fea 100644
--- a/host/include/uhd/config.hpp
+++ b/host/include/uhd/config.hpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010-2011 Ettus Research LLC
+// Copyright 2010-2011,2014 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -56,6 +56,13 @@ typedef ptrdiff_t ssize_t;
#define UHD_DEPRECATED __declspec(deprecated)
#define UHD_ALIGNED(x) __declspec(align(x))
#define UHD_UNUSED(x) x
+#elif defined(__MINGW32__)
+ #define UHD_EXPORT __declspec(dllexport)
+ #define UHD_IMPORT __declspec(dllimport)
+ #define UHD_INLINE inline
+ #define UHD_DEPRECATED __declspec(deprecated)
+ #define UHD_ALIGNED(x) __declspec(align(x))
+ #define UHD_UNUSED(x) x
#elif defined(__GNUG__) && __GNUG__ >= 4
#define UHD_EXPORT __attribute__((visibility("default")))
#define UHD_IMPORT __attribute__((visibility("default")))
diff --git a/host/include/uhd/transport/nirio/nirio_driver_iface.h b/host/include/uhd/transport/nirio/nirio_driver_iface.h
index 83afd816a..3e0e56a7f 100644
--- a/host/include/uhd/transport/nirio/nirio_driver_iface.h
+++ b/host/include/uhd/transport/nirio/nirio_driver_iface.h
@@ -24,9 +24,9 @@
#include <uhd/transport/nirio/status.h>
#include <uhd/config.hpp>
#if defined(UHD_PLATFORM_WIN32)
- #include <Windows.h>
+ #include <windows.h>
#pragma warning(disable:4201) // nonstandard extension used : nameless struct/union
- #include <WinIoCtl.h>
+ #include <winioctl.h>
#pragma warning(default:4201)
#elif !defined(UHD_PLATFORM_LINUX)
#include <IOKit/IOKitLib.h>
diff --git a/host/lib/transport/nirio/nifpga_lvbitx.cpp b/host/lib/transport/nirio/nifpga_lvbitx.cpp
index b87d87a8d..189037163 100644
--- a/host/lib/transport/nirio/nifpga_lvbitx.cpp
+++ b/host/lib/transport/nirio/nifpga_lvbitx.cpp
@@ -115,7 +115,7 @@ std::string nifpga_lvbitx::_get_fpga_images_dir(const std::string search_paths)
// directories searched for a LVBITX image.
//
char* uhd_images_dir;
-#ifdef UHD_PLATFORM_WIN32
+#if defined(UHD_PLATFORM_WIN32) && !defined(__MINGW32__) // Some versions of MinGW don't expose _dupenv_s
size_t len;
errno_t err = _dupenv_s(&uhd_images_dir, &len, "UHD_IMAGES_DIR");
if(not err and uhd_images_dir != NULL) search_path_vtr.push_back(std::string(uhd_images_dir));
diff --git a/host/lib/utils/platform.cpp b/host/lib/utils/platform.cpp
index e2f92039e..a9cef663b 100644
--- a/host/lib/utils/platform.cpp
+++ b/host/lib/utils/platform.cpp
@@ -1,5 +1,5 @@
//
-// Copyright 2010-2012 Ettus Research LLC
+// Copyright 2010-2012,2014 Ettus Research LLC
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
@@ -19,7 +19,7 @@
#include <uhd/config.hpp>
#include <boost/functional/hash.hpp>
#ifdef UHD_PLATFORM_WIN32
-#include <Windows.h>
+#include <windows.h>
#else
#include <unistd.h>
#endif
diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt
index 829fb8e94..596ab1017 100644
--- a/host/tests/CMakeLists.txt
+++ b/host/tests/CMakeLists.txt
@@ -48,7 +48,11 @@ SET(test_sources
)
#turn each test cpp file into an executable with an int main() function
-ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN)
+IF(MINGW)
+ ADD_DEFINITIONS(-DBOOST_TEST_MAIN)
+ELSE()
+ ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN)
+ENDIF()
SET(UHD_TEST_TARGET_DEPS uhd)
SET(UHD_TEST_LIBRARY_DIRS ${Boost_LIBRARY_DIRS})
@@ -57,7 +61,7 @@ SET(UHD_TEST_LIBRARY_DIRS ${Boost_LIBRARY_DIRS})
FOREACH(test_source ${test_sources})
GET_FILENAME_COMPONENT(test_name ${test_source} NAME_WE)
ADD_EXECUTABLE(${test_name} ${test_source})
- TARGET_LINK_LIBRARIES(${test_name} uhd)
+ TARGET_LINK_LIBRARIES(${test_name} uhd ${Boost_LIBRARIES})
UHD_ADD_TEST(${test_name} ${test_name})
UHD_INSTALL(TARGETS ${test_name} RUNTIME DESTINATION ${PKG_LIB_DIR}/tests COMPONENT tests)
ENDFOREACH(test_source)