Skip to content

Upgrade to C++17 #3103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Current Trunk
-------------
- Remove asm2wasm, which supported Emscripten's fastcomp backend, after fastcomp
was removed.
- Binaryen now requires C++17 (was C++14) to build.

v96
---
Expand Down
12 changes: 8 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 3.1.3)
project(binaryen LANGUAGES C CXX VERSION 96)
include(GNUInstallDirs)

# The C++ standard whose features are required to build Binaryen.
# Keep in sync with scripts/test/shared.py cxx_standard
set(CXX_STANDARD 17)

if(NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release")
Expand Down Expand Up @@ -188,7 +192,7 @@ else()
set(THREADS_PREFER_PTHREAD_FLAG ON)
set(CMAKE_THREAD_PREFER_PTHREAD ON)
find_package(Threads REQUIRED)
add_cxx_flag("-std=c++14")
add_cxx_flag("-std=c++${CXX_STANDARD}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why we need this in addition to the CXX_STANDARD property?

if(NOT EMSCRIPTEN)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
# wasm doesn't allow for x87 floating point math
Expand Down Expand Up @@ -312,7 +316,7 @@ function(binaryen_add_executable name sources)
add_executable(${name} ${sources})
target_link_libraries(${name} ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(${name} binaryen)
set_property(TARGET ${name} PROPERTY CXX_STANDARD 14)
set_property(TARGET ${name} PROPERTY CXX_STANDARD ${CXX_STANDARD})
set_property(TARGET ${name} PROPERTY CXX_STANDARD_REQUIRED ON)
binaryen_setup_rpath(${name})
install(TARGETS ${name} DESTINATION ${CMAKE_INSTALL_BINDIR})
Expand Down Expand Up @@ -354,7 +358,7 @@ if(EMSCRIPTEN)
target_link_libraries(binaryen_wasm optimized "--closure-args \"--language_in=ECMASCRIPT6 --language_out=ECMASCRIPT6\"")
target_link_libraries(binaryen_wasm optimized "--llvm-lto 1")
target_link_libraries(binaryen_wasm debug "--profiling")
set_property(TARGET binaryen_wasm PROPERTY CXX_STANDARD 14)
set_property(TARGET binaryen_wasm PROPERTY CXX_STANDARD ${CXX_STANDARD})
set_property(TARGET binaryen_wasm PROPERTY CXX_STANDARD_REQUIRED ON)
install(TARGETS binaryen_wasm DESTINATION ${CMAKE_INSTALL_BINDIR})

Expand All @@ -379,7 +383,7 @@ if(EMSCRIPTEN)
target_link_libraries(binaryen_js optimized "--llvm-lto 1")
target_link_libraries(binaryen_js debug "--profiling")
target_link_libraries(binaryen_js debug "-s ASSERTIONS")
set_property(TARGET binaryen_js PROPERTY CXX_STANDARD 14)
set_property(TARGET binaryen_js PROPERTY CXX_STANDARD ${CXX_STANDARD})
set_property(TARGET binaryen_js PROPERTY CXX_STANDARD_REQUIRED ON)
install(TARGETS binaryen_js DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ Usage instructions for each are below.
cmake . && make
```

A C++14 compiler is required. Note that you can also use `ninja` as your generator: `cmake -G Ninja . && ninja`.
A C++17 compiler is required. Note that you can also use `ninja` as your generator: `cmake -G Ninja . && ninja`.

Binaryen.js can be built using Emscripten, which can be installed via [the SDK](http://kripken.github.io/emscripten-site/docs/getting_started/downloads.html)).

Expand Down
4 changes: 2 additions & 2 deletions auto_update_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def update_example_tests():
'-I' + os.path.join(shared.options.binaryen_root, 'src'), '-g', '-L' + libdir, '-pthread']
print('build: ', ' '.join(extra))
if src.endswith('.cpp'):
extra += ['-std=c++14']
extra += ['-std=c++' + str(shared.cxx_standard)]
print(os.getcwd())
subprocess.check_call(extra)
# Link against the binaryen C library DSO, using rpath
Expand All @@ -65,7 +65,7 @@ def update_example_tests():
if os.environ.get('COMPILER_FLAGS'):
for f in os.environ.get('COMPILER_FLAGS').split(' '):
cmd.append(f)
cmd = [os.environ.get('CXX') or 'g++', '-std=c++14'] + cmd
cmd = [os.environ.get('CXX') or 'g++', '-std=c++' + str(shared.cxx_standard)] + cmd
try:
print('link: ', ' '.join(cmd))
subprocess.check_call(cmd)
Expand Down
4 changes: 2 additions & 2 deletions check.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def run_gcc_tests():
extra = [shared.NATIVECC, src, '-c', '-o', 'example.o',
'-I' + os.path.join(shared.options.binaryen_root, 'src'), '-g', '-L' + libpath, '-pthread']
if src.endswith('.cpp'):
extra += ['-std=c++14']
extra += ['-std=c++' + str(shared.cxx_standard)]
if os.environ.get('COMPILER_FLAGS'):
for f in os.environ.get('COMPILER_FLAGS').split(' '):
extra.append(f)
Expand All @@ -326,7 +326,7 @@ def run_gcc_tests():
if os.environ.get('COMPILER_FLAGS'):
for f in os.environ.get('COMPILER_FLAGS').split(' '):
cmd.append(f)
cmd = [shared.NATIVEXX, '-std=c++14'] + cmd
cmd = [shared.NATIVEXX, '-std=c++' + str(shared.cxx_standard)] + cmd
print('link: ', ' '.join(cmd))
subprocess.check_call(cmd)
print('run...', output_file)
Expand Down
4 changes: 4 additions & 0 deletions scripts/test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import subprocess
import sys

# The C++ standard whose features are required to build Binaryen.
# Keep in sync with CMakeLists.txt CXX_STANDARD
cxx_standard = 17


def parse_args(args):
usage_str = ("usage: 'python check.py [options]'\n\n"
Expand Down