authorgravatar for bodie@synapsegarden.netBodie Solomon <bodie@synapsegarden.net> 2020-03-31 10:13:31-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-03-31 14:23:34-04:00
log9bb76f8ce0b36211e0ff1f502ec46aa5a0142cd0
treee88f6204cda7fd9d9a9a1b0ae1a608999005f0f8
parentd34a3c66b36e3afc8ea7f275b449033fa7a1b4bc

Use correct compiler flags in MSVC bootstrap builds of Zig

https://github.com/ziglang/zig/issues/4877 The CMake build of Zig from C++ uses hand-set compiler flags which are not compatible with the Microsoft C/C++ Optimizing Compiler (cl.exe) used by Visual Studio. This commit attempts to conform them to match the Clang/GCC options under MSVC builds. Note that CL does not have a concept of C99 or "-O3", and may imply other optimizations in "/O2" than are implied by Clang/GCC "-O3". Visual Studio 2019 documentation for cl.exe's optimization options: https://docs.microsoft.com/en-us/cpp/build/reference/o-options-optimize-code?view=vs-2019 Visual Studio 2019 doc for cl.exe's C++ standard options: https://docs.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=vs-2019

1 files changed, 12 insertions(+), 3 deletions(-)

CMakeLists.txt+12-3
...@@ -224,7 +224,7 @@ set(EMBEDDED_SOFTFLOAT_SOURCES...@@ -224,7 +224,7 @@ set(EMBEDDED_SOFTFLOAT_SOURCES
224add_library(embedded_softfloat STATIC ${EMBEDDED_SOFTFLOAT_SOURCES})224add_library(embedded_softfloat STATIC ${EMBEDDED_SOFTFLOAT_SOURCES})
225if(MSVC)225if(MSVC)
226 set_target_properties(embedded_softfloat PROPERTIES226 set_target_properties(embedded_softfloat PROPERTIES
227 COMPILE_FLAGS "-std=c99 /w"227 COMPILE_FLAGS "/w /O2"
228 )228 )
229else()229else()
230 set_target_properties(embedded_softfloat PROPERTIES230 set_target_properties(embedded_softfloat PROPERTIES
...@@ -315,7 +315,12 @@ include_directories(...@@ -315,7 +315,12 @@ include_directories(
315)315)
316316
317# These have to go before the -Wno- flags317# These have to go before the -Wno- flags
318set(EXE_CFLAGS "-std=c++14")318if(MSVC)
319 set(EXE_CFLAGS "/std:c++14")
320else(MSVC)
321 set(EXE_CFLAGS "-std=c++14")
322endif(MSVC)
323
319if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")324if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
320 if(MSVC)325 if(MSVC)
321 set(EXE_CFLAGS "${EXE_CFLAGS} /w")326 set(EXE_CFLAGS "${EXE_CFLAGS} /w")
...@@ -333,7 +338,11 @@ else()...@@ -333,7 +338,11 @@ else()
333 endif()338 endif()
334endif()339endif()
335340
336set(OPTIMIZED_C_FLAGS "-std=c99 -O3")341if(MSVC)
342 set(OPTIMIZED_C_FLAGS "/O2")
343else(MSVC)
344 set(OPTIMIZED_C_FLAGS "-std=c99 -O3")
345endif(MSVC)
337346
338set(EXE_LDFLAGS " ")347set(EXE_LDFLAGS " ")
339if(MSVC)348if(MSVC)