From d78357da50999b51f51cc795ecb707277dcfc0fa Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Sun, 1 Sep 2019 22:49:54 +0200 Subject: [PATCH] CMake: Make MinGW support work --- expat/CMakeLists.txt | 19 ++++++++++++++-- expat/Changes | 2 ++ expat/Makefile.am | 1 + expat/cmake/mingw-toolchain.cmake | 36 +++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 expat/cmake/mingw-toolchain.cmake diff --git a/expat/CMakeLists.txt b/expat/CMakeLists.txt index b3ca160b..2d80d836 100644 --- a/expat/CMakeLists.txt +++ b/expat/CMakeLists.txt @@ -328,15 +328,30 @@ if(EXPAT_BUILD_TESTS) tests/structdata.c ) + if(NOT MSVC) + if(MINGW) + set(host whatever-mingw32) # for nothing but run.sh + endif() + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/run.sh.in run.sh @ONLY) + endif() + + function(expat_add_test _name _file) + if(MSVC) + add_test(NAME ${_name} COMMAND ${_file}) + else() + add_test(NAME ${_name} COMMAND bash run.sh ${_file}) + endif() + endfunction() + add_executable(runtests tests/runtests.c ${test_SRCS}) set_property(TARGET runtests PROPERTY RUNTIME_OUTPUT_DIRECTORY tests) target_link_libraries(runtests expat) - add_test(runtests tests/runtests) + expat_add_test(runtests $) add_executable(runtestspp tests/runtestspp.cpp ${test_SRCS}) set_property(TARGET runtestspp PROPERTY RUNTIME_OUTPUT_DIRECTORY tests) target_link_libraries(runtestspp expat) - add_test(runtestspp tests/runtestspp) + expat_add_test(runtestspp $) endif(EXPAT_BUILD_TESTS) if(EXPAT_BUILD_FUZZERS) diff --git a/expat/Changes b/expat/Changes index cabf3aa0..4244c2bc 100644 --- a/expat/Changes +++ b/expat/Changes @@ -56,6 +56,8 @@ Release x.x.x xxx xxx xx xxxx CMake: Now produces a summary of applied configuration CMake: Require C++ compiler only when tests are enabled #265 CMake: Fix linking with MinGW + #330 CMake: Add full support for MinGW; to enable, use + -DCMAKE_TOOLCHAIN_FILE=[expat]/cmake/mingw-toolchain.cmake #316 CMake: Windows: Make binary postfix match MSVC Old: expat[d].lib New: expat[w][d][MD|MT].lib diff --git a/expat/Makefile.am b/expat/Makefile.am index c3825e84..b32d9bad 100644 --- a/expat/Makefile.am +++ b/expat/Makefile.am @@ -55,6 +55,7 @@ pkgconfigdir = $(libdir)/pkgconfig _EXTRA_DIST_CMAKE = \ cmake/expat-config.cmake.in \ + cmake/mingw-toolchain.cmake \ \ CMakeLists.txt \ CMake.README \ diff --git a/expat/cmake/mingw-toolchain.cmake b/expat/cmake/mingw-toolchain.cmake new file mode 100644 index 00000000..31a238b0 --- /dev/null +++ b/expat/cmake/mingw-toolchain.cmake @@ -0,0 +1,36 @@ +# __ __ _ +# ___\ \/ /_ __ __ _| |_ +# / _ \\ /| '_ \ / _` | __| +# | __// \| |_) | (_| | |_ +# \___/_/\_\ .__/ \__,_|\__| +# |_| XML parser +# +# Copyright (c) 2019 Expat development team +# Licensed under the MIT license: +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to permit +# persons to whom the Software is furnished to do so, subject to the +# following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN +# NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR +# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE +# USE OR OTHER DEALINGS IN THE SOFTWARE. + +set(CMAKE_SYSTEM_NAME Windows) + +set(CMAKE_C_COMPILER i686-w64-mingw32-gcc) +set(CMAKE_CXX_COMPILER i686-w64-mingw32-g++) + +set(WIN32 ON) +set(MINGW ON)