Skip to content

Commit

Permalink
cmake: compile with -std=gnu++1z by default
Browse files Browse the repository at this point in the history
Summary:
Update thrift's CMakeLists.txt file to compile with `-std=gnu++1z`

This is required in order to allow downstream projects that use fbthrift to
build with `-std=gnu++1z`.  The linkage for how constexpr variables are
emitted has changed between `gnu++14` and `gnu++1z`.  If fbthrift 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
fbthrift header files.

I manually updated the code to pass `-std=gnu++1z` on the compile line rather
than using `CMAKE_CXX_STANDARD` so that we can still support older versions of
CMake.  Support for C++17 through `CMAKE_CXX_STANDARD` was not added until
CMake 3.8.

Reviewed By: yfeldblum

Differential Revision: D10498113

fbshipit-source-id: 407c605174ef80ebdb87dbe05c30a8831ed0b278
  • Loading branch information
simpkins authored and facebook-github-bot committed Oct 25, 2018
1 parent c2976ce commit 32f536d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ cmake_minimum_required(VERSION 3.1.3 FATAL_ERROR)

# Package information
project("fbthrift" C CXX)
set(CMAKE_CXX_STANDARD 14) #Requires CMake 3.1.3

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
Expand Down Expand Up @@ -47,6 +46,19 @@ find_package(
)
include_directories(${Boost_INCLUDE_DIRS})

# 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)
if("${CMAKE_CXX_COMPILER_ID}" MATCHES Clang
OR "${CMAKE_CXX_COMPILER_ID}" MATCHES GNU)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=${CXX_STD}")
endif()

# Enable modular builds
option(compiler_only "Build the Thrift Compiler only" OFF)
option(lib_only "Build the Thrift Libraries only" OFF)
Expand Down

0 comments on commit 32f536d

Please sign in to comment.