From 86924e9cca30b3f4d61fa2d2697d742afa6f73b0 Mon Sep 17 00:00:00 2001 From: Nicholas Corgan Date: Wed, 22 Jul 2015 14:46:31 -0700 Subject: cmake: MinGW improvements * Improved toolchan file, accounts for different versions * Don't force static runtime linking (was causing test errors) * Include MinGW runtime in packaging --- host/CMakeLists.txt | 16 ------ host/cmake/Modules/UHDPackage.cmake | 6 +-- host/cmake/Toolchains/mingw_cross.cmake | 92 ++++++++++++++++----------------- host/tests/CMakeLists.txt | 6 +-- 4 files changed, 48 insertions(+), 72 deletions(-) diff --git a/host/CMakeLists.txt b/host/CMakeLists.txt index c41776aae..be280f785 100644 --- a/host/CMakeLists.txt +++ b/host/CMakeLists.txt @@ -167,22 +167,6 @@ IF(MSVC) ADD_DEFINITIONS(/bigobj) #Increases the number of addressable sections in an .obj file. 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/Modules/UHDPackage.cmake b/host/cmake/Modules/UHDPackage.cmake index 298b9d33a..a17af9c61 100644 --- a/host/cmake/Modules/UHDPackage.cmake +++ b/host/cmake/Modules/UHDPackage.cmake @@ -210,10 +210,10 @@ SET(CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS " DeleteRegValue HKLM ${HLKM_ENV} \\\"UHD_PKG_PATH\\\" ") -IF(MSVC) - #Install necessary MSVC runtime DLL's +IF(WIN32) + #Install necessary runtime DLL's INCLUDE(InstallRequiredSystemLibraries) -ENDIF(MSVC) +ENDIF(WIN32) ######################################################################## IF(NOT ${CPACK_GENERATOR} STREQUAL NSIS) diff --git a/host/cmake/Toolchains/mingw_cross.cmake b/host/cmake/Toolchains/mingw_cross.cmake index 7c5adb002..f1406ec46 100644 --- a/host/cmake/Toolchains/mingw_cross.cmake +++ b/host/cmake/Toolchains/mingw_cross.cmake @@ -1,56 +1,52 @@ -# Use this command: # -# cmake -DCMAKE_TOOLCHAIN_FILE=cmake/Toolchain-mingw.cmake . +# Allow the user to specify a MinGW prefix, but fill in +# most likely default if none given. # -# 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) +SET(CMAKE_SYSTEM_NAME Windows) + +IF(NOT DEFINED MINGW_PREFIX) + SET(POSSIBLE_PREFIXES + i586-mingw32msvc + i686-pc-mingw32 + x86_64-pc-mingw32 + i686-w64-mingw32 + x86_64-w64-mingw32 + ) + + SET(MINGW_FOUND 0) + FOREACH(prefix ${POSSIBLE_PREFIXES}) + IF(EXISTS /usr/${prefix}) + SET(MINGW_PREFIX ${prefix}) + SET(MINGW_FOUND 1) + BREAK() + ENDIF(EXISTS /usr/${prefix}) + ENDFOREACH(prefix ${POSSIBLE_PREFIXES}) + + IF(NOT MINGW_FOUND) + MESSAGE(FATAL_ERROR "No MinGW type specified, but none detected in the usual locations.") + ENDIF(NOT MINGW_FOUND) +ENDIF(NOT DEFINED MINGW_PREFIX) + +SET(MINGW_PREFIX ${MINGW_PREFIX} CACHE STRING "MinGW prefix") + +SET(CMAKE_C_COMPILER ${MINGW_PREFIX}-gcc) +SET(CMAKE_CXX_COMPILER ${MINGW_PREFIX}-g++) +SET(CMAKE_RC_COMPILER ${MINGW_PREFIX}-windres) + +IF(NOT DEFINED CMAKE_FIND_ROOT_PATH) + SET(CMAKE_FIND_ROOT_PATH /usr/${MINGW_PREFIX}) +ENDIF(NOT DEFINED CMAKE_FIND_ROOT_PATH) -# 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) +SET(CMAKE_INCLUDE_PATH + ${CMAKE_FIND_ROOT_PATH}/local/include + ${CMAKE_FIND_ROOT_PATH}/include +) -# 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 . - # 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 - 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() +SET(CMAKE_LIBRARY_PATH + ${CMAKE_FIND_ROOT_PATH}/local/lib + ${CMAKE_FIND_ROOT_PATH}/lib +) # Adjust the default behaviour of the FIND_XXX() commands: # search headers and libraries in the target environment, search diff --git a/host/tests/CMakeLists.txt b/host/tests/CMakeLists.txt index 596ab1017..1fb1a1951 100644 --- a/host/tests/CMakeLists.txt +++ b/host/tests/CMakeLists.txt @@ -48,11 +48,7 @@ SET(test_sources ) #turn each test cpp file into an executable with an int main() function -IF(MINGW) - ADD_DEFINITIONS(-DBOOST_TEST_MAIN) -ELSE() - ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN) -ENDIF() +ADD_DEFINITIONS(-DBOOST_TEST_DYN_LINK -DBOOST_TEST_MAIN) SET(UHD_TEST_TARGET_DEPS uhd) SET(UHD_TEST_LIBRARY_DIRS ${Boost_LIBRARY_DIRS}) -- cgit v1.2.3