Unverified Commit 82e36424 authored by Dominik Charousset's avatar Dominik Charousset Committed by GitHub

Merge pull request #39

Move to C++17
parents af0ba8f5 fa9784be
# -- project setup -------------------------------------------------------------
cmake_minimum_required(VERSION 2.8.12)
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(caf_incubator C CXX)
# -- CMake includes for C/C++ features -----------------------------------------
......@@ -10,6 +10,38 @@ include(CheckCSourceRuns)
# -- set useful CMake options --------------------------------------------------
if(NOT CMAKE_CROSSCOMPILING)
# Check whether the user already provided flags that enable C++ >= 17.
try_compile(caf_has_cxx_17
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/check-compiler-features.cpp")
# Try enabling C++17 mode if user-provided flags aren't sufficient.
if(NOT caf_has_cxx_17)
if(MSVC)
set(cxx_flag "/std:c++17")
else()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang"
AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
set(cxx_flag "-std=c++1z")
else()
set(cxx_flag "-std=c++17")
endif()
endif()
# Re-run compiler check.
try_compile(caf_has_cxx_17
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/check-compiler-features.cpp"
COMPILE_DEFINITIONS "${cxx_flag}"
OUTPUT_VARIABLE cxx_check_output)
if(NOT caf_has_cxx_17)
MESSAGE(FATAL_ERROR "\nFatal error: unable activate C++17 mode!\
\nPlease see README.md for supported compilers.\
\n\ntry_compile output:\n${cxx_check_output}")
endif()
add_compile_options("${cxx_flag}")
endif()
endif()
# Be nice to VIM users and Clang tools.
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
......@@ -132,33 +164,6 @@ find_package(CAF COMPONENTS core io test)
# -- compiler setup ------------------------------------------------------------
# Check for g++ >= 4.8 or clang++ > = 3.2.
if(NOT WIN32 AND NOT CAF_NO_COMPILER_CHECK AND NOT CMAKE_CROSSCOMPILING)
try_run(ProgramResult
CompilationSucceeded
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/get_compiler_version.cpp"
RUN_OUTPUT_VARIABLE CompilerVersion)
if(NOT CompilationSucceeded OR NOT ProgramResult EQUAL 0)
message(FATAL_ERROR "Cannot determine compiler version")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
if(CompilerVersion VERSION_GREATER 4.7)
message(STATUS "Found g++ version ${CompilerVersion}")
else()
message(FATAL_ERROR "g++ >= 4.8 required (found: ${CompilerVersion})")
endif()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(CompilerVersion VERSION_GREATER 3.1)
message(STATUS "Found clang++ version ${CompilerVersion}")
else()
message(FATAL_ERROR "clang++ >= 3.2 required (found: ${CompilerVersion})")
endif()
else()
message(FATAL_ERROR "Your C++ compiler does not support C++11 "
"or is not supported")
endif()
endif()
# Enable a ton of warnings if --more-clang-warnings is used.
if(CAF_MORE_WARNINGS)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
......@@ -195,43 +200,11 @@ if(CAF_MORE_WARNINGS)
build_string("EXTRA_FLAGS" "${WFLAGS_STR}")
endif()
# Add -stdlib=libc++ when using Clang if possible.
if(NOT CAF_NO_AUTO_LIBCPP AND CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CXXFLAGS_BACKUP "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "-std=c++11 -stdlib=libc++")
try_run(ProgramResult
CompilationSucceeded
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/get_compiler_version.cpp"
RUN_OUTPUT_VARIABLE CompilerVersion)
if(NOT CompilationSucceeded OR NOT ProgramResult EQUAL 0)
message(STATUS "Use clang with GCC's libstdc++")
else()
message(STATUS "Automatically added '-stdlib=libc++' flag "
"(set CAF_NO_AUTO_LIBCPP to suppress this)")
build_string("EXTRA_FLAGS" "-stdlib=libc++")
endif()
# restore CXX flags
set(CMAKE_CXX_FLAGS "${CXXFLAGS_BACKUP}")
endif()
# Enable ASAN if requested by the user.
if(CAF_ENABLE_ADDRESS_SANITIZER AND NOT WIN32)
# check whether address sanitizer is available
set(CXXFLAGS_BACKUP "${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "-fsanitize=address -fno-omit-frame-pointer")
try_run(ProgramResult
CompilationSucceeded
"${CMAKE_CURRENT_BINARY_DIR}"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/get_compiler_version.cpp")
if(NOT CompilationSucceeded)
message(STATUS "ASAN not available on selected compiler")
else()
message(STATUS "Enable Address Sanitizer")
build_string("EXTRA_FLAGS" "-fsanitize=address -fno-omit-frame-pointer")
endif()
# restore CXX flags
set(CMAKE_CXX_FLAGS "${CXXFLAGS_BACKUP}")
add_compile_options("-fsanitize=address"
"-fno-omit-frame-pointer")
list(APPEND CAF_EXTRA_LDFLAGS "-fsanitize=address")
endif()
# -pthread is ignored on MacOSX but required on other platforms
......@@ -277,12 +250,7 @@ endif()
# -- check if the user provided CXXFLAGS, set defaults otherwise ---------------
if(NOT CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "-std=c++11 -Wextra -Wall -pedantic ${EXTRA_FLAGS}")
endif()
if (NOT "${CMAKE_CXX_FLAGS}" MATCHES "-std=")
message(STATUS "Supplied CXXFLAGS do not contain a C++ standard, setting std to c++11")
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS "-Wextra -Wall -pedantic ${EXTRA_FLAGS}")
endif()
if(NOT CMAKE_CXX_FLAGS_DEBUG)
......
......@@ -35,19 +35,38 @@ config = [
],
// Our build matrix. Keys are the operating system labels and values are build configurations.
buildMatrix: [
['Linux', [
builds: ['debug'],
tools: ['gcc4.8', 'gcc4.9', 'gcc5', 'gcc6', 'gcc7'],
// Various Linux builds for debug and release.
['debian-8', [
builds: ['debug', 'release'],
tools: ['clang-4'],
]],
['centos-6', [
builds: ['debug', 'release'],
tools: ['gcc-7'],
]],
['centos-7', [
builds: ['debug', 'release'],
tools: ['gcc-7'],
]],
['ubuntu-16.04', [
builds: ['debug', 'release'],
tools: ['clang-4'],
]],
['ubuntu-18.04', [
builds: ['debug', 'release'],
tools: ['gcc-7'],
]],
['Linux', [
// On Fedora 28, our debug build also produces the coverage report.
['fedora-28', [
builds: ['debug'],
tools: ['gcc8'],
tools: ['gcc-8'],
extraSteps: ['coverageReport'],
]],
['Linux', [
['fedora-28', [
builds: ['release'],
tools: ['gcc8'],
tools: ['gcc-8'],
]],
// Other UNIX systems.
['macOS', [
builds: ['debug', 'release'],
tools: ['clang'],
......@@ -56,6 +75,7 @@ config = [
builds: ['debug', 'release'],
tools: ['clang'],
]],
// Non-UNIX systems.
['Windows', [
// TODO: debug build currently broken
//builds: ['debug', 'release'],
......
#ifndef __cpp_noexcept_function_type
# error "Noexcept not part of the type system (__cpp_noexcept_function_type)"
#endif
#ifndef __cpp_fold_expressions
# error "No support for fold expression (__cpp_fold_expressions)"
#endif
#ifndef __cpp_if_constexpr
# error "No support for 'if constexpr' (__cpp_if_constexpr)"
#endif
int main(int, char**) {
return 0;
}
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