Commit dacf5bc6 authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

cmake: compile with -std=gnu++1z by default

Summary:
Switch from `-std=gnu++14` to `-std=gnu++1z`

This is required in order to allow downstream projects that use folly to build
with `-std=gnu++1z`.  The linkage for how constexpr variables are emitted
has changed between `gnu++14` and `gnu++1z`.  If folly is compiled with
`gnu++14` but downstream dependencies try to build with `gnu++1z` they will
get link errors (multiple definitions) for constexpr variables defined in
folly header files.

The reverse (compiling folly with `gnu++1z` but downstream projects with
`gnu++14`) does not seem to cause any problems.  Nonetheless, I have provided
`CXX_STD` as a CMake option so that users can override this setting if it does
cause any problems for some reason.

Reviewed By: yfeldblum

Differential Revision: D10448691

fbshipit-source-id: c44f568a7ff175c432865badeaaa9b3ebbaf8987
parent 92d74b9b
# 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.
#
# Most users probably want to stick with the default here. However, gnu++1z
# does change the linkage of how some symbols are emitted (e.g., constexpr
# variables defined in headers). In case this causes problems for downstream
# libraries that aren't using gnu++1z yet, provide an option to let them still
# override this with gnu++14 if they need to.
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)
set(CMAKE_CXX_FLAGS_COMMON "-g -Wall -Wextra") set(CMAKE_CXX_FLAGS_COMMON "-g -Wall -Wextra")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_COMMON}") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_COMMON}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_COMMON} -O3") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_COMMON} -O3")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=gnu++14") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=${CXX_STD}")
function(apply_folly_compile_options_to_target THETARGET) function(apply_folly_compile_options_to_target THETARGET)
target_compile_definitions(${THETARGET} target_compile_definitions(${THETARGET}
PRIVATE PRIVATE
...@@ -13,7 +29,7 @@ function(apply_folly_compile_options_to_target THETARGET) ...@@ -13,7 +29,7 @@ function(apply_folly_compile_options_to_target THETARGET)
target_compile_options(${THETARGET} target_compile_options(${THETARGET}
PRIVATE PRIVATE
-g -g
-std=gnu++14 -std=${CXX_STD}
-finput-charset=UTF-8 -finput-charset=UTF-8
-fsigned-char -fsigned-char
-Werror -Werror
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment