folly icon indicating copy to clipboard operation
folly copied to clipboard

Mixed -std= flags

Open dmacks opened this issue 2 years ago • 2 comments

Building on OS X 10.13 using gcc-12 and cmake-3.24.1 (both via fink), I see compiler calls like:

/sw/bin/g++-fsf-12 -DFMT_SHARED -DFOLLY_XLOG_STRIP_PREFIXES=\"/sw/build.build/libfolly-2022.12.05.00-1:/sw/build.build/libfolly-2022.12.05.00-1/finkbuild\" -DGFLAGS_IS_A_DLL=0 -D_GNU_SOURCE -D_REENTRANT -I/sw/build.build/libfolly-2022.12.05.00-1 -I/sw/build.build/libfolly-2022.12.05.00-1/finkbuild -I/sw/opt/boost-1_68/include -I/sw/include -Wno-nonnull -O3 -DNDEBUG -g -Wall -Wextra -O3 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -mmacosx-version-min=10.13 -fcoroutines -g -std=gnu++1z -finput-charset=UTF-8 -fsigned-char -Wall -Wno-deprecated -Wno-deprecated-declarations -Wno-sign-compare -Wno-unused -Wuninitialized -Wunused-label -Wunused-result -Wshadow-compatible-local -Wno-noexcept-type -faligned-new -fopenmp -std=gnu++17 -MD -MT CMakeFiles/folly_base.dir/folly/CancellationToken.cpp.o -MF CMakeFiles/folly_base.dir/folly/CancellationToken.cpp.o.d -o CMakeFiles/folly_base.dir/folly/CancellationToken.cpp.o -c /sw/build.build/libfolly-2022.12.05.00-1/folly/CancellationToken.cpp

There is both -std=gnu++1z and -std=gnu++17. The former is set in CMake/FollyCompilerUnix.cmake as of dacf5bc601b03648d3da23eb9046e244ff5c51f2:

# Provide an option to control the -std argument for the C++ compiler.
# We don't use CMAKE_CXX_STANDARD since it requires at least CMake 3.8
# to support C++17.
...
set(
  CXX_STD "gnu++1z"
  CACHE STRING
  "The C++ standard argument to pass to the compiler.  Defaults to gnu++1z"
)
mark_as_advanced(CXX_STD)

The latter comes from the top-level CMakeLists.txt as of 9fdb0d52e3f5805724de51a418b54ac9ece5afb1:

cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
...
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

It's confusing to debug when there are contradictory flags, and it require me two use two separate mechanisms if I want to change the -std locally. Given the CMakeLists.txt setting, does that mean cmake-3.8 actually is now required and the CXX_STD hand-coded setting is not needed? Or if a -std is desired that CMAKE_CXX_STANDARD doesn't support, that method shouldn't be used, so it doesn't result in also setting an undesired flag.

dmacks avatar Dec 10 '22 14:12 dmacks

folly/memcpy.S is the only compiler that does not pass both (only passes the CXX_STD one). That makes sense, since it's not a C++ source, so cmake's native flag isn't used, but folly's hardcoded flag is used everywhere.

dmacks avatar Dec 10 '22 14:12 dmacks

See also #1740, which at least implements a flag to override the CMakeLists.txt one.

dmacks avatar Dec 12 '22 05:12 dmacks