From 5dbdbb642f5ff3f78e4cdc57f2f85eeabf39afe5 Mon Sep 17 00:00:00 2001 From: Quim Muntal Date: Wed, 19 Dec 2018 09:34:14 +0100 Subject: [PATCH] Fix MinGW builds (#113) * use ole32 when compiling with MINGW in Windows for UUIDs * use winresrc.h instead of winres.h * remove ole32 link dependency * add mingw shell script * add mingw support to travis-cli * fix travis before_script * add cmake cross compile support to cmake * remove tobydox dependency * use mingw from /usr instead of /opt * remove test from travis mingw build * remove tets generation for linux mingw * fix mingw cmake script * add LIB3MF_TESTS at cmake toolchain * reenable tests in mingw cmake --- .travis.yml | 15 +++++++++++++-- CMakeLists.txt | 10 ++++++---- Release/VersionInfo/VersionResource.rc | 2 +- cmake/GenerateMinGW.sh | 15 +++++++++++++++ 4 files changed, 35 insertions(+), 7 deletions(-) create mode 100644 cmake/GenerateMinGW.sh diff --git a/.travis.yml b/.travis.yml index 95c97c42f..eb63e4ef0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,13 +11,24 @@ matrix: compiler: gcc - os: osx osx_image: xcode7.2 + - os: linux + compiler: x86_64-w64-mingw32-g++ + env: BUILDMODE=cmake-mingw32 + addons: + apt: + packages: + - gcc-mingw-w64-base + - binutils-mingw-w64-x86-64 + - gcc-mingw-w64-x86-64 + - gcc-mingw-w64 + - g++-mingw-w64-x86-64 before_script: - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then HOMEBREW_NO_AUTO_UPDATE=1 brew install ossp-uuid ; fi - - sh cmake/GenerateMake.sh + - if [[ "$BUILDMODE" = "cmake-mingw32" ]]; then sh cmake/GenerateMinGW.sh ; else sh cmake/GenerateMake.sh ; fi - cd build script: - cmake --build . - - ctest -V + - if ![[ "$BUILDMODE" = "cmake-mingw32" ]]; then ctest -V ; fi diff --git a/CMakeLists.txt b/CMakeLists.txt index 38fbb5f7c..ab04d083a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,11 +105,13 @@ if (UNIX OR MINGW) if (NOT APPLE) SET_TARGET_PROPERTIES(${PROJECT_NAME}_s PROPERTIES LINK_FLAGS -s) endif() - find_library(LIBUUID_PATH uuid) - if(NOT LIBUUID_PATH) - message(FATAL_ERROR "libuuid not found") + if (NOT WIN32) + find_library(LIBUUID_PATH uuid) + if(NOT LIBUUID_PATH) + message(FATAL_ERROR "libuuid not found") + endif() + target_link_libraries(${PROJECT_NAME}_s ${LIBUUID_PATH}) endif() - target_link_libraries(${PROJECT_NAME}_s ${LIBUUID_PATH}) else() # wd4996 masks the deprecated-warning target_compile_options(${PROJECT_NAME}_s PUBLIC "$<$:/Od;/Ob0;/Gm;/sdl;/W3;/WX;/FC;/wd4996>") diff --git a/Release/VersionInfo/VersionResource.rc b/Release/VersionInfo/VersionResource.rc index 4f0d14904..45714baea 100644 --- a/Release/VersionInfo/VersionResource.rc +++ b/Release/VersionInfo/VersionResource.rc @@ -1,5 +1,5 @@ #include "VersionInfo.h" -#include "winres.h" +#include "winresrc.h" // IDI_ICON1 ICON PRODUCT_ICON diff --git a/cmake/GenerateMinGW.sh b/cmake/GenerateMinGW.sh new file mode 100644 index 000000000..47ce05097 --- /dev/null +++ b/cmake/GenerateMinGW.sh @@ -0,0 +1,15 @@ +#!/bin/sh + +basepath="$(cd "$(dirname "$0")" && pwd)" +builddir="$basepath/../build" +mkdir -p "$builddir" +cd "$builddir" +echo "SET(CMAKE_SYSTEM_NAME Windows)" > toolchain.cmake && +echo "SET(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc)" >> toolchain.cmake && +echo "SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++)" >> toolchain.cmake && +echo "SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)" >> toolchain.cmake && +echo "SET(CMAKE_FIND_ROOT_PATH /usr/mingw64)" >> toolchain.cmake && +echo "SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)" >> toolchain.cmake && +echo "SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)" >> toolchain.cmake && +echo "SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)" >> toolchain.cmake && +cmake .. -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake "$@"