From 7c58c1d59e05d369386eae81e3b95e8cc0a2b53f Mon Sep 17 00:00:00 2001 From: David Neto Date: Mon, 29 Feb 2016 01:01:04 -0500 Subject: [PATCH] Support Linux-to-Windows cross comiple via MinGW For MinGW compile, statically link the C++ runtime Change-Id: Ic58d1e47a814a265fd91edd7082e938ffc87f0c9 --- CMakeLists.txt | 21 +++++++++++++++++---- source/print.cpp | 2 +- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 184301a..977495d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,7 +45,10 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "") endif() option(SPIRV_WERROR "Enable error on warning" ON) -if(UNIX) +if((${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") OR (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")) + set(COMPILER_IS_LIKE_GNU TRUE) +endif() +if(${COMPILER_IS_LIKE_GNU}) set(SPIRV_WARNINGS -Wall -Wextra -Wno-missing-field-initializers) option(SPIRV_WARN_EVERYTHING "Enable -Weverything" ${SPIRV_WARN_EVERYTHING}) @@ -64,7 +67,7 @@ if(UNIX) if(${SPIRV_WERROR}) set(SPIRV_WARNINGS ${SPIRV_WARNINGS} -Werror) endif() -elseif(WIN32) +elseif(MSVC) set(SPIRV_WARNINGS -D_CRT_SECURE_NO_WARNINGS /wd4800) if(${SPIRV_WERROR}) @@ -79,7 +82,8 @@ endif() function(spvtools_default_compile_options TARGET) target_compile_options(${TARGET} PRIVATE ${SPIRV_WARNINGS}) - if (UNIX) + + if (${COMPILER_IS_LIKE_GNU}) target_compile_options(${TARGET} PRIVATE -std=c++11 -fno-exceptions -fno-rtti) target_compile_options(${TARGET} PRIVATE @@ -101,6 +105,15 @@ function(spvtools_default_compile_options TARGET) -Wno-missing-field-initializers) endif() endif() + + # For MinGW cross compile, statically link to the C++ runtime. + # But it still depends on MSVCRT.dll. + if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") + if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU") + set_target_properties(${TARGET} PROPERTIES LINK_FLAGS + -static -static-libgcc -static-libstdc++) + endif() + endif() endfunction() if(NOT COMMAND find_host_package) @@ -279,7 +292,7 @@ if (NOT ${SPIRV_SKIP_EXECUTABLES}) add_executable(UnitSPIRV ${TEST_SOURCES}) spvtools_default_compile_options(UnitSPIRV) - if(UNIX) + if(${COMPILER_IS_LIKE_GNU}) target_compile_options(UnitSPIRV PRIVATE -Wno-undef) endif() if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") diff --git a/source/print.cpp b/source/print.cpp index d157d1d..a354aa9 100644 --- a/source/print.cpp +++ b/source/print.cpp @@ -43,7 +43,7 @@ clr::blue::operator const char*() { return "\e[34m"; } } // namespace libspirv #elif defined(SPIRV_WINDOWS) -#include +#include namespace libspirv {