Skip to content

Commit

Permalink
Fixing (again) C++17 support for Clang
Browse files Browse the repository at this point in the history
  • Loading branch information
khuck committed Dec 6, 2018
1 parent f6448ea commit cc0c533
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
41 changes: 18 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -253,37 +253,32 @@ set (APEX_VERSION_MINOR 5)

# add_definitions(-std=c++11)
include(CheckCXXCompilerFlag)
### CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
### if(COMPILER_SUPPORTS_CXX17)
### set(CMAKE_CXX_SUPPORT_FLAG "-std=c++17" CACHE STRING "CXX Support Flag" FORCE)
### else()
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
if(COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_SUPPORT_FLAG "-std=c++17" CACHE STRING "CXX Support Flag" FORCE)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
if(COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_SUPPORT_FLAG "-std=c++17" CACHE STRING "CXX Support Flag" FORCE)
else()
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
if(COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_SUPPORT_FLAG "-std=c++14" CACHE STRING "CXX Support Flag" FORCE)
else()
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
if(COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_SUPPORT_FLAG "-std=c++14" CACHE STRING "CXX Support Flag" FORCE)
CHECK_CXX_COMPILER_FLAG("-std=c++1y" COMPILER_SUPPORTS_CXX1Y)
if(COMPILER_SUPPORTS_CXX1Y)
set(CMAKE_CXX_SUPPORT_FLAG "-std=c++1y" CACHE STRING "CXX Support Flag" FORCE)
else()
CHECK_CXX_COMPILER_FLAG("-std=c++1y" COMPILER_SUPPORTS_CXX1Y)
if(COMPILER_SUPPORTS_CXX1Y)
set(CMAKE_CXX_SUPPORT_FLAG "-std=c++1y" CACHE STRING "CXX Support Flag" FORCE)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_SUPPORT_FLAG "-std=c++11" CACHE STRING "CXX Support Flag" FORCE)
else()
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_SUPPORT_FLAG "-std=c++11" CACHE STRING "CXX Support Flag" FORCE)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_SUPPORT_FLAG "-std=c++0x" CACHE STRING "CXX Support Flag" FORCE)
else()
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_SUPPORT_FLAG "-std=c++0x" CACHE STRING "CXX Support Flag" FORCE)
else()
message(FATAL_ERROR " Compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
endif()
message(FATAL_ERROR " Compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
endif()
endif()
endif()
endif()
### endif()
endif()

# By the way, GCC lies. It accepts the flag, but doesn't have the support.
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
Expand Down
14 changes: 9 additions & 5 deletions src/apex/apex_cxx_shared_lock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

// It's gotten fun. Apparently gcc 7 supports shared_mutex, but even though
// clang 5/6 *claims* to support c++17, it doesn't have shared_mutex.h
#define GCC_COMPILER (defined(__GNUC__) && !defined(__clang__))
#if (defined(__GNUC__) && !defined(__clang__))
#define GCC_COMPILER_7
#else
#undef GCC_COMPILER_7
#endif

#if __cplusplus > 201701L && defined(GCC_COMPILER)
#if __cplusplus > 201701L && GCC_COMPILER_7
#include <shared_mutex>
#elif __cplusplus >= 201500L && defined(GCC_COMPILER)
#elif __cplusplus >= 201500L && GCC_COMPILER_7
// if we've got gcc 6.1+ and -std=c++17
#include <shared_mutex>
#elif __cplusplus > 201402L
Expand All @@ -27,12 +31,12 @@
namespace apex
{

#if __cplusplus > 201701L && defined(GCC_COMPILER)
#if __cplusplus > 201701L && GCC_COMPILER_7
// if we've got gcc 6.1 and -std=c++17
typedef std::shared_mutex shared_mutex_type;
typedef std::shared_lock<shared_mutex_type> read_lock_type;
typedef std::unique_lock<shared_mutex_type> write_lock_type;
#elif __cplusplus > 201402L // if we've got gcc 4.9+ and -std=c++14
#elif __cplusplus > 201402L && GCC_COMPILER_7 // if we've got gcc 4.9+ and -std=c++14
typedef std::shared_timed_mutex shared_mutex_type;
typedef std::shared_lock<shared_mutex_type> read_lock_type;
typedef std::unique_lock<shared_mutex_type> write_lock_type;
Expand Down

0 comments on commit cc0c533

Please sign in to comment.