zproject icon indicating copy to clipboard operation
zproject copied to clipboard

MSVC uses C++ compiler for C code?

Open sphaero opened this issue 5 years ago • 4 comments

Why is in Cmake the compiler forced to use the C++ compiler?

if (WIN32)
    #The MSVC C compiler is too out of date,
    #so the sources have to be compiled as c++
    if (MSVC AND NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
        enable_language(CXX)
        file(GLOB sources "${SOURCE_DIR}/src/*.c")
        set_source_files_properties(
            ${sources}
            PROPERTIES LANGUAGE CXX
        )
    endif()
    set(MORE_LIBRARIES ws2_32 Rpcrt4 Iphlpapi)
endif()

This gives errors when using ifdef cplusplus from what I've seen so far.

What was the reasoning behind this? Is it really needed?

sphaero avatar Jun 04 '20 12:06 sphaero

Btw, when commenting those lines czmq builds fine, with some conversion warnings though.

sphaero avatar Jun 04 '20 12:06 sphaero

Git blame tells my I'm responsible for that particular piece of configuration :laughing:

This configuration was copied from czmq's CMakefile when zproject came to life. I'm not sure if the comment about MSVC being out of date still holds.

If you feel it unnecessary remove it!

sappo avatar Jun 04 '20 15:06 sappo

I think MSVC only supports C89 from what I know so indeed it's very old. I could remove it but it probably will influence other projects. In czmq it only generates more warnings which then need to be fixed.

For my purpose it did resolve some issues with the __cplusplus define but I don't know where it will bite us.

Any others thoughts about this?

sphaero avatar Jun 04 '20 18:06 sphaero

https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/

Microsoft is working on it apparently

sphaero avatar Sep 29 '20 19:09 sphaero