cginternals / globjects

C++ library strictly wrapping OpenGL objects.
https://globjects.org
MIT License
538 stars 59 forks source link

Why globjects uses /GL flag on MSVC? #366

Open NukeBird opened 6 years ago

NukeBird commented 6 years ago

When I'm trying to compile a project in Visual Studio 2017 I getting an warning "founded .netmodule MSIL or module, compiled with parameter /GL, restarting a linkage with parameter /LTCG"

Compilation time and output file size are big...

scheibel commented 6 years ago

I recall having multiple long sessions fine-tuning the compilation and linker flags on MSVC. Back then, we majorly tested MSVC 2013 and 2015, probably we have to reconsider the flags for 2017. Thanks for reporting.

Update: What I wrote holds for glbinding (I misread the project name). For globjects there may be an actual mismatch of compiler options. We'll investigate.

NukeBird commented 6 years ago

Thank you for reply, hope this behavior of MSVC will be fixed soon ^^

j-o commented 6 years ago

As for the /GL option, see here: https://docs.microsoft.com/en-us/cpp/build/reference/gl-whole-program-optimization. It enables compiler optimizations across compilation units and implies /LTCG, which is not currently supplied, hence the warning.

IMHO, this is a cmake-init issue, that probably stems from the fact that adding a linker flag is a bit cumbersome in cmake, as there is no target_link_options. To fix this, append the following to CompileOptions.cmake:

# MSVC linker options
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "MSVC")
    set(DEFAULT_LINKER_OPTIONS ${DEFAULT_LINKER_OPTIONS}
        "$<$<CONFIG:Release>:-LTCG>"
    )
endif()

This might reduce compile time (as per warning message), but won't affect output file size.

scheibel commented 6 years ago

Thanks for investigating.