Skip to content

Commit

Permalink
Bump minimum C++ to 14 and update compiler mins to match (#1369)
Browse files Browse the repository at this point in the history
As discussed at the TSC meeting and on the mail list, I won't merge this
change until June 1. It will only be in master (future OSL 1.12), not
backported to any release branch.

Signed-off-by: Larry Gritz <[email protected]>
  • Loading branch information
lgritz authored Jun 1, 2021
1 parent 0c0e6d4 commit d755edf
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 108 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ on:

jobs:
vfxplatform-2019:
name: "Linux VFXP-2019: gcc6 C++11 llvm7 py2.7 boost-1.66 exr-2.3 OIIO-2.1 sse2"
name: "Linux VFXP-2019: gcc6 C++14 llvm7 py2.7 boost-1.66 exr-2.3 OIIO-2.1 sse2"
runs-on: ubuntu-latest
container:
image: aswf/ci-osl:2019-clang7
env:
CXX: g++
CC: gcc
CMAKE_CXX_STANDARD: 11
CMAKE_CXX_STANDARD: 14
PYTHON_VERSION: 2.7
USE_PYTHON: 0
OPENIMAGEIO_VERSION: Release-2.1.20.0
Expand Down Expand Up @@ -475,14 +475,14 @@ jobs:
linux-oldest:
# Oldest versions of the dependencies that we can muster, and various
# things disabled.
name: "Linux oldest everything: gcc6 C++11 llvm7 py2.7 boost-1.66 oiio-2.1 no-simd exr2.3"
name: "Linux oldest everything: gcc6 C++14 llvm7 py2.7 boost-1.66 oiio-2.1 no-simd exr2.3"
runs-on: ubuntu-latest
container:
image: aswf/ci-osl:2019-clang7
env:
CXX: g++
CC: gcc
CMAKE_CXX_STANDARD: 11
CMAKE_CXX_STANDARD: 14
PYTHON_VERSION: 2.7
USE_SIMD: 0
USE_PYTHON: 0
Expand Down
16 changes: 4 additions & 12 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ NEW or CHANGED dependencies since the last major release are **bold**.

* Build system: [CMake](https://cmake.org/) 3.12 or newer (tested through 3.20)

* A suitable C++11 compiler to build OSL itself, which may be any of:
- GCC 4.8.5 or newer (tested through gcc 10)
* A suitable **C++14 or C++17** compiler to build OSL itself, which may be any of:
- **GCC 6.1 or newer** (tested through gcc 10)
- Clang 3.4 or newer (tested through clang 12)
- Microsoft Visual Studio 2015 or newer
- Intel C++ compiler icc version 13 (?) or newer

OSL should compile also properly with C++14 or C++17, but they are not
required (unless you are using LLVM >= 10, in which case at least C++14
is needed).
- Microsoft Visual Studio **2017 or newer**
- Intel C++ compiler icc **version 17 or newer**

* **[OpenImageIO](http://openimageio.org) 2.1 or newer** (tested through 2.2)

Expand All @@ -46,10 +42,6 @@ NEW or CHANGED dependencies since the last major release are **bold**.
* **[LLVM](http://www.llvm.org) 7, 8, 9, 10, 11, or 12**, including clang
libraries.

Note that LLVM 10+ is not compatible with C++11, and requires C++14 or
later. If you *must* build OSL with C++11, you need to use an LLVM that
is LLVM 9 or earlier.

* [Boost](https://www.boost.org) 1.55 or newer (tested through boost 1.73)
* [Ilmbase or Imath](http://openexr.com/downloads.html) 2.0 or newer (tested through 3.0)
* [Flex](https://github.com/westes/flex) 2.5.35 or newer and
Expand Down
2 changes: 1 addition & 1 deletion src/cmake/compiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ message (STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
# C++ language standard
#
set (CMAKE_CXX_STANDARD 14 CACHE STRING
"C++ standard to prefer (11, 14, 17, 20, etc.)")
"C++ standard to prefer (14, 17, 20, etc.)")
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
message (STATUS "Building for C++${CMAKE_CXX_STANDARD}")
Expand Down
62 changes: 8 additions & 54 deletions src/include/OSL/oslconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -137,47 +137,14 @@ enum class SymArena {

namespace pvt {

#if (OSL_CPLUSPLUS_VERSION >= 14)
template<int... IntegerListT>
using int_sequence = std::integer_sequence<int, IntegerListT...>;
template<int... IntegerListT>
using int_sequence = std::integer_sequence<int, IntegerListT...>;

template<int EndBeforeT>
using make_int_sequence = std::make_integer_sequence<int, EndBeforeT>;
template<int EndBeforeT>
using make_int_sequence = std::make_integer_sequence<int, EndBeforeT>;

template<bool... BoolListT >
using bool_sequence = std::integer_sequence<bool, BoolListT... >;
#else
// std::integer_sequence requires c++14 library support,
// we have our own version here in case the environment is c++14 compiler
// building against c++11 library.
template<int... IntegerListT>
struct int_sequence
{
};

template<int StartAtT, int EndBeforeT, typename IntSequenceT>
struct int_sequence_generator;

template<int StartAtT, int EndBeforeT, int... IntegerListT>
struct int_sequence_generator<StartAtT, EndBeforeT, int_sequence<IntegerListT...>>
{
typedef typename int_sequence_generator<StartAtT+1, EndBeforeT, int_sequence<IntegerListT..., StartAtT>>::type type;
};

template<int EndBeforeT, int... IntegerListT>
struct int_sequence_generator<EndBeforeT, EndBeforeT, int_sequence<IntegerListT...>>
{
typedef int_sequence<IntegerListT...> type;
};

template<int EndBeforeT>
using make_int_sequence = typename int_sequence_generator<0, EndBeforeT, int_sequence<> >::type;

template<bool... BoolListT >
struct bool_sequence
{
};
#endif
template<bool... BoolListT >
using bool_sequence = std::integer_sequence<bool, BoolListT... >;

#if (OSL_CPLUSPLUS_VERSION >= 17)
template<class... ListT>
Expand Down Expand Up @@ -211,21 +178,8 @@ static OSL_FORCEINLINE OSL_HOSTDEVICE void static_foreach(const FunctorT &iFunct
static_foreach<ConstantWrapperT>(pvt::make_int_sequence<N>(), iFunctor);
}

#if (OSL_CPLUSPLUS_VERSION >= 14)
template<int N>
using ConstIndex = std::integral_constant<int, N>;
#else
template<int N>
struct ConstIndex : public std::integral_constant<int, N>
{
// C++14 adds this conversion operator we need to allow non-generic
// lambda functions (pre C++14) to accept an "int" instead of a
// typed ConstIndex<N> with "auto"
constexpr int operator()() const noexcept {
return N;
}
};
#endif
template<int N>
using ConstIndex = std::integral_constant<int, N>;


// During development it can be useful to output extra information
Expand Down
35 changes: 16 additions & 19 deletions src/include/OSL/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@

// Tests for MSVS versions, always 0 if not MSVS at all.
#if defined(_MSC_VER)
# if _MSC_VER < 1900
# error "This version of OSL is meant to work only with Visual Studio 2015 or later"
# endif
# define OSL_MSVS_AT_LEAST_2013 (_MSC_VER >= 1800)
# define OSL_MSVS_BEFORE_2013 (_MSC_VER < 1800)
# define OSL_MSVS_AT_LEAST_2015 (_MSC_VER >= 1900)
# define OSL_MSVS_BEFORE_2015 (_MSC_VER < 1900)
# define OSL_MSVS_AT_LEAST_2017 (_MSC_VER >= 1910)
# define OSL_MSVS_BEFORE_2017 (_MSC_VER < 1910)
# if OSL_MSVS_BEFORE_2017
# error "This version of OSL is meant to work only with Visual Studio 2017 or later"
# endif
#else
# define OSL_MSVS_AT_LEAST_2013 0
# define OSL_MSVS_BEFORE_2013 0
Expand All @@ -103,37 +103,34 @@
// Detect which C++ standard we're using, and handy macros.
// See https://en.cppreference.com/w/cpp/compiler_support
//
// Note: oslversion.h defines OSL_BUILD_CPP11 to be 1 if OSL was built
// using C++11. In contrast, OSL_CPLUSPLUS_VERSION defined below will be set
// to the right number for the C++ standard being compiled RIGHT NOW. These
// two things may be the same when compiling OSL, but they may not be the
// same if another package is compiling against OSL and using these headers
// (OSL may be C++11 but the client package may be newer, or vice versa --
// use these two symbols to differentiate these cases, when important).
// Note: oslversion.h defines OSL_BUILD_CPP to be 14, 17, etc., to reflect
// the version that OSL itself was built with. In contrast,
// OSL_CPLUSPLUS_VERSION defined below will be set to the right number for
// the C++ standard being compiled RIGHT NOW by whomever is parsing these
// header files. These two things may be the same when compiling OSL, but
// they may not be the same if another package is compiling against OSL and
// using these headers (e.g., OSL may be C++14 but the client package may be
// newer, or vice versa -- use these two symbols to differentiate these
// cases, when important).
#if (__cplusplus >= 202001L)
# define OSL_CPLUSPLUS_VERSION 20
# define OSL_CONSTEXPR14 constexpr
# define OSL_CONSTEXPR17 constexpr
# define OSL_CONSTEXPR20 constexpr
#elif (__cplusplus >= 201703L)
# define OSL_CPLUSPLUS_VERSION 17
# define OSL_CONSTEXPR14 constexpr
# define OSL_CONSTEXPR17 constexpr
# define OSL_CONSTEXPR20 /* not constexpr before C++20 */
#elif (__cplusplus >= 201402L) || (defined(_MSC_VER) && _MSC_VER >= 1914)
# define OSL_CPLUSPLUS_VERSION 14
# define OSL_CONSTEXPR14 constexpr
# define OSL_CONSTEXPR17 /* not constexpr before C++17 */
# define OSL_CONSTEXPR20 /* not constexpr before C++20 */
#elif (__cplusplus >= 201103L) || _MSC_VER >= 1900
# define OSL_CPLUSPLUS_VERSION 11
# define OSL_CONSTEXPR14 /* not constexpr before C++14 */
# define OSL_CONSTEXPR17 /* not constexpr before C++17 */
# define OSL_CONSTEXPR20 /* not constexpr before C++20 */
#else
# error "This version of OSL requires C++11"
# error "This version of OSL requires C++14 or above"
#endif

// DEPRECATED(1.12): use C++14 constexpr
#define OSL_CONSTEXPR14 constexpr



// In C++20 (and some compilers before that), __has_cpp_attribute can
Expand Down
3 changes: 3 additions & 0 deletions src/liboslcomp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ if (MSVC)
target_link_libraries (${local_lib} PRIVATE "Version.lib")
endif()

target_compile_features (${local_lib}
PUBLIC cxx_std_${CMAKE_CXX_STANDARD})

set_target_properties (${local_lib}
PROPERTIES
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
Expand Down
3 changes: 3 additions & 0 deletions src/liboslexec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,9 @@ target_link_libraries (${local_lib}
${LLVM_LIBRARIES} ${LLVM_LDFLAGS} ${LLVM_SYSTEM_LIBRARIES}
)

target_compile_features (${local_lib}
PUBLIC cxx_std_${CMAKE_CXX_STANDARD})

set_target_properties (${local_lib}
PROPERTIES
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
Expand Down
11 changes: 0 additions & 11 deletions src/liboslexec/llvm_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,6 @@ using namespace OSL;
#include <OpenImageIO/fmath.h>
#include <OpenImageIO/simd.h>

#if defined(_MSC_VER) && _MSC_VER < 1700
using OIIO::isinf;
#endif

#if defined(_MSC_VER) && _MSC_VER < 1800
using OIIO::roundf;
using OIIO::truncf;
using OIIO::erff;
using OIIO::erfcf;
#endif

#if defined(__FreeBSD__)
#include <sys/param.h>
#if __FreeBSD_version < 803000
Expand Down
5 changes: 0 additions & 5 deletions src/liboslexec/opcolor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@

#include <OpenImageIO/fmath.h>

#if defined(_MSC_VER) && _MSC_VER < 1800
using OIIO::expm1;
using OIIO::cbrtf;
#endif

#ifdef __CUDACC__
#include <optix.h>
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/liboslnoise/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ target_link_libraries (${local_lib}
${Boost_LIBRARIES} ${CMAKE_DL_LIBS}
)

target_compile_features (${local_lib}
PUBLIC cxx_std_${CMAKE_CXX_STANDARD})

set_target_properties (${local_lib}
PROPERTIES
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
Expand Down
3 changes: 3 additions & 0 deletions src/liboslquery/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ target_link_libraries (${local_lib}
${Boost_LIBRARIES}
)

target_compile_features (${local_lib}
PUBLIC cxx_std_${CMAKE_CXX_STANDARD})

set_target_properties (${local_lib}
PROPERTIES
VERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}
Expand Down
2 changes: 1 addition & 1 deletion testsuite/example-cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ set(CUDA_TARGET_ARCH sm_35)

# Compile our "renderer" to PTX
cuda_compile_ptx(CUDA_PTX_FILES cuda_grid_renderer.cu
OPTIONS --gpu-architecture=${CUDA_TARGET_ARCH} --use_fast_math -dc --std=c++11
OPTIONS --gpu-architecture=${CUDA_TARGET_ARCH} --use_fast_math -dc --std=c++14
--expt-relaxed-constexpr
-I${OSL_INCLUDES}
-I${IMATH_INCLUDES}
Expand Down
2 changes: 1 addition & 1 deletion testsuite/example-deformer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ set (CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

# Use C++11
set (CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard to prefer (11, 14, 17, etc.)")
set (CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to prefer (14, 17, 20, etc.)")
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)

Expand Down

0 comments on commit d755edf

Please sign in to comment.