From a2f044a34c70b361d4927728b67714517cfd59ed Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Sun, 28 Jul 2024 22:22:01 -0700 Subject: [PATCH] build: A few cmake cleanups and minor code rearrangements (#4359) * Get rid of some obsolete cmake code. * Movement (but no change) to some parts of CMakeLists.txt, primarily to make it closer to the corresponding file in OSL to make it easy for me to diff them and port innovations back and forth between them. * Some typo/etc fixes * Remove unused OIIO_UNUSED_OK macro that's been deprecated since 2.0, and OIIO_CONSTEXPR and OIIO_CONSTEXPR14, neither of which have been needed for years. Signed-off-by: Larry Gritz --- CMakeLists.txt | 5 -- docs/Deprecations-3.0.md | 10 +++ src/cmake/compiler.cmake | 6 +- src/cmake/dependency_utils.cmake | 96 ++++++++++++------------- src/include/OpenImageIO/platform.h | 110 +++++++++++++---------------- 5 files changed, 111 insertions(+), 116 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aebb4eafd5..16398af606 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -265,11 +265,6 @@ if (NUKE_FOUND) add_subdirectory (src/nuke/txWriter) endif () -# Last minute site-specific instructions, if they exist -if (OIIO_SITE AND EXISTS "${PROJECT_SOURCE_DIR}/site/${OIIO_SITE}/cmake/sitecustom.cmake") - include ("${PROJECT_SOURCE_DIR}/site/${OIIO_SITE}/cmake/sitecustom.cmake") -endif () - # install pkgconfig file if (NOT MSVC) configure_file(src/build-scripts/OpenImageIO.pc.in "${CMAKE_BINARY_DIR}/OpenImageIO.pc" @ONLY) diff --git a/docs/Deprecations-3.0.md b/docs/Deprecations-3.0.md index bef5af6f8e..3200e3ea28 100644 --- a/docs/Deprecations-3.0.md +++ b/docs/Deprecations-3.0.md @@ -138,6 +138,16 @@ about being deprecated will be removed in the final 3.0 release. been considered deprecated since OIIO 2.3. Please use task functions that do not take a thread ID parameter. +## platform.h + +* Removed macros `OIIO_CONSTEXPR`, `OIIO_CONSTEXPR14`, and + `OIIO_CONSTEXPR_OR_CONST` and deprecated `OIIO_CONSTEXPR17` (use regular C++ + `constexpr` in place of all of these). Removed macro `OIIO_NOEXCEPT` (use + C++ `noexcept`). +* Removed macro `OIIO_UNUSED_OK`, which had been deprecated since 2.0. Marked + `OIIO_MAYBE_UNUSED` as deprecated as well, now that C++17 is the minimum, + there's no reason not to directly use the C++ attribute `[[maybe_unused]]`. + ## strutil.h * Added deprecation warnings to all the old (printf-convention) string diff --git a/src/cmake/compiler.cmake b/src/cmake/compiler.cmake index 844fce09c9..fb2b2c20ab 100644 --- a/src/cmake/compiler.cmake +++ b/src/cmake/compiler.cmake @@ -28,7 +28,7 @@ message (VERBOSE "CMAKE_CXX_COMPILE_FEATURES = ${CMAKE_CXX_COMPILE_FEATURES}") # set (CMAKE_CXX_MINIMUM 17) set (CMAKE_CXX_STANDARD 17 CACHE STRING - "C++ standard to build with (14, 17, 20, etc.) Minimum is ${CMAKE_CXX_MINIMUM}.") + "C++ standard to build with (17, 20, etc.) Minimum is ${CMAKE_CXX_MINIMUM}.") set (DOWNSTREAM_CXX_STANDARD 17 CACHE STRING "C++ minimum standard to impose on downstream clients") set (CMAKE_CXX_STANDARD_REQUIRED ON) @@ -69,13 +69,17 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER MATCHES "[Cc]lan set (CMAKE_CXX_COMPILER_ID "AppleClang") set (CMAKE_COMPILER_IS_APPLECLANG 1) string (REGEX REPLACE ".* version ([0-9]+\\.[0-9]+).*" "\\1" APPLECLANG_VERSION_STRING ${clang_full_version_string}) + set (ANY_CLANG_VERSION_STRING ${APPLECLANG_VERSION_STRING}) message (VERBOSE "The compiler is Clang: ${CMAKE_CXX_COMPILER_ID} version ${APPLECLANG_VERSION_STRING}") elseif (CMAKE_CXX_COMPILER_ID MATCHES "IntelLLVM") set (CMAKE_COMPILER_IS_INTELCLANG 1) string (REGEX MATCH "[0-9]+(\\.[0-9]+)+" INTELCLANG_VERSION_STRING ${clang_full_version_string}) + set (ANY_CLANG_VERSION_STRING ${INTELCLANG_VERSION_STRING}) message (VERBOSE "The compiler is Intel Clang: ${CMAKE_CXX_COMPILER_ID} version ${INTELCLANG_VERSION_STRING}") else () + set (CMAKE_COMPILER_IS_GENERICCLANG 1) string (REGEX REPLACE ".* version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string}) + set (ANY_CLANG_VERSION_STRING ${CLANG_VERSION_STRING}) message (VERBOSE "The compiler is Clang: ${CMAKE_CXX_COMPILER_ID} version ${CLANG_VERSION_STRING}") endif () elseif (CMAKE_CXX_COMPILER_ID MATCHES "Intel") diff --git a/src/cmake/dependency_utils.cmake b/src/cmake/dependency_utils.cmake index a1470a1c70..99504819db 100644 --- a/src/cmake/dependency_utils.cmake +++ b/src/cmake/dependency_utils.cmake @@ -74,57 +74,55 @@ endfunction () # Helper: Print a report about missing dependencies and give insructions on # how to turn on automatic local dependency building. function (print_package_notfound_report) - if (CFP_ALL_BUILD_DEPS_NOTFOUND OR CFP_ALL_BUILD_DEPS_BADVERSION) - message (STATUS) - message (STATUS "${ColorBoldYellow}=========================================================================${ColorReset}") - message (STATUS "${ColorBoldYellow}= Dependency report =${ColorReset}") - message (STATUS "${ColorBoldYellow}=========================================================================${ColorReset}") - message (STATUS) - if (CFP_EXTERNAL_BUILD_DEPS_FOUND) - message (STATUS "${ColorBoldWhite}The following dependencies found externally:${ColorReset}") - list (SORT CFP_EXTERNAL_BUILD_DEPS_FOUND CASE INSENSITIVE) - list (REMOVE_DUPLICATES CFP_EXTERNAL_BUILD_DEPS_FOUND) - foreach (_pkg IN LISTS CFP_EXTERNAL_BUILD_DEPS_FOUND) - message (STATUS " ${_pkg} ${${_pkg}_VERSION}") - endforeach () - endif () - if (CFP_ALL_BUILD_DEPS_BADVERSION) - message (STATUS "${ColorBoldWhite}The following dependencies were found but were too old:${ColorReset}") - list (SORT CFP_ALL_BUILD_DEPS_BADVERSION CASE INSENSITIVE) - list (REMOVE_DUPLICATES CFP_ALL_BUILD_DEPS_BADVERSION) - foreach (_pkg IN LISTS CFP_ALL_BUILD_DEPS_BADVERSION) - if (_pkg IN_LIST CFP_LOCALLY_BUILT_DEPS) - message (STATUS " ${_pkg} ${${_pkg}_NOT_FOUND_EXPLANATION} ${ColorMagenta}(${${_pkg}_VERSION} BUILT LOCALLY)${ColorReset}") - else () - message (STATUS " ${_pkg} ${${_pkg}_NOT_FOUND_EXPLANATION}") - endif () - endforeach () - endif () - if (CFP_ALL_BUILD_DEPS_NOTFOUND) - message (STATUS "${ColorBoldWhite}The following dependencies were not found:${ColorReset}") - list (SORT CFP_ALL_BUILD_DEPS_NOTFOUND CASE INSENSITIVE) - list (REMOVE_DUPLICATES CFP_ALL_BUILD_DEPS_NOTFOUND) - foreach (_pkg IN LISTS CFP_ALL_BUILD_DEPS_NOTFOUND) - if (_pkg IN_LIST CFP_LOCALLY_BUILT_DEPS) - message (STATUS " ${_pkg} ${_${_pkg}_version_range} ${${_pkg}_NOT_FOUND_EXPLANATION} ${ColorMagenta}(${${_pkg}_VERSION} BUILT LOCALLY)${ColorReset}") - else () - message (STATUS " ${_pkg} ${_${_pkg}_version_range} ${${_pkg}_NOT_FOUND_EXPLANATION}") - endif () - endforeach () - endif () - if (CFP_LOCALLY_BUILDABLE_DEPS_NOTFOUND OR CFP_LOCALLY_BUILDABLE_DEPS_BADVERSION) - message (STATUS) - message (STATUS "${ColorBoldWhite}For some of these, we can build them locally:${ColorReset}") - foreach (_pkg IN LISTS CFP_LOCALLY_BUILDABLE_DEPS_NOTFOUND CFP_LOCALLY_BUILDABLE_DEPS_BADVERSION) - message (STATUS " ${_pkg}") - endforeach () - message (STATUS "${ColorBoldWhite}To build them automatically if not found, build again with option:${ColorReset}") - message (STATUS " ${ColorBoldGreen}-D${PROJECT_NAME}_BUILD_MISSING_DEPS=all${ColorReset}") - endif () - message (STATUS) - message (STATUS "${ColorBoldYellow}=========================================================================${ColorReset}") + message (STATUS) + message (STATUS "${ColorBoldYellow}=========================================================================${ColorReset}") + message (STATUS "${ColorBoldYellow}= Dependency report =${ColorReset}") + message (STATUS "${ColorBoldYellow}=========================================================================${ColorReset}") + message (STATUS) + if (CFP_EXTERNAL_BUILD_DEPS_FOUND) + message (STATUS "${ColorBoldWhite}The following dependencies found externally:${ColorReset}") + list (SORT CFP_EXTERNAL_BUILD_DEPS_FOUND CASE INSENSITIVE) + list (REMOVE_DUPLICATES CFP_EXTERNAL_BUILD_DEPS_FOUND) + foreach (_pkg IN LISTS CFP_EXTERNAL_BUILD_DEPS_FOUND) + message (STATUS " ${_pkg} ${${_pkg}_VERSION}") + endforeach () + endif () + if (CFP_ALL_BUILD_DEPS_BADVERSION) + message (STATUS "${ColorBoldWhite}The following dependencies were found but were too old:${ColorReset}") + list (SORT CFP_ALL_BUILD_DEPS_BADVERSION CASE INSENSITIVE) + list (REMOVE_DUPLICATES CFP_ALL_BUILD_DEPS_BADVERSION) + foreach (_pkg IN LISTS CFP_ALL_BUILD_DEPS_BADVERSION) + if (_pkg IN_LIST CFP_LOCALLY_BUILT_DEPS) + message (STATUS " ${_pkg} ${${_pkg}_NOT_FOUND_EXPLANATION} ${ColorMagenta}(${${_pkg}_VERSION} BUILT LOCALLY)${ColorReset}") + else () + message (STATUS " ${_pkg} ${${_pkg}_NOT_FOUND_EXPLANATION}") + endif () + endforeach () + endif () + if (CFP_ALL_BUILD_DEPS_NOTFOUND) + message (STATUS "${ColorBoldWhite}The following dependencies were not found:${ColorReset}") + list (SORT CFP_ALL_BUILD_DEPS_NOTFOUND CASE INSENSITIVE) + list (REMOVE_DUPLICATES CFP_ALL_BUILD_DEPS_NOTFOUND) + foreach (_pkg IN LISTS CFP_ALL_BUILD_DEPS_NOTFOUND) + if (_pkg IN_LIST CFP_LOCALLY_BUILT_DEPS) + message (STATUS " ${_pkg} ${_${_pkg}_version_range} ${${_pkg}_NOT_FOUND_EXPLANATION} ${ColorMagenta}(${${_pkg}_VERSION} BUILT LOCALLY)${ColorReset}") + else () + message (STATUS " ${_pkg} ${_${_pkg}_version_range} ${${_pkg}_NOT_FOUND_EXPLANATION}") + endif () + endforeach () + endif () + if (CFP_LOCALLY_BUILDABLE_DEPS_NOTFOUND OR CFP_LOCALLY_BUILDABLE_DEPS_BADVERSION) message (STATUS) + message (STATUS "${ColorBoldWhite}For some of these, we can build them locally:${ColorReset}") + foreach (_pkg IN LISTS CFP_LOCALLY_BUILDABLE_DEPS_NOTFOUND CFP_LOCALLY_BUILDABLE_DEPS_BADVERSION) + message (STATUS " ${_pkg}") + endforeach () + message (STATUS "${ColorBoldWhite}To build them automatically if not found, build again with option:${ColorReset}") + message (STATUS " ${ColorBoldGreen}-D${PROJECT_NAME}_BUILD_MISSING_DEPS=all${ColorReset}") endif () + message (STATUS) + message (STATUS "${ColorBoldYellow}=========================================================================${ColorReset}") + message (STATUS) endfunction () diff --git a/src/include/OpenImageIO/platform.h b/src/include/OpenImageIO/platform.h index 7fb09b43b5..1371096a64 100644 --- a/src/include/OpenImageIO/platform.h +++ b/src/include/OpenImageIO/platform.h @@ -52,64 +52,6 @@ #include #include -// Detect which C++ standard we're using, and handy macros. -// See https://en.cppreference.com/w/cpp/compiler_support -// -// OIIO_CPLUSPLUS_VERSION : which C++ standard is compiling (14, 17, ...) -// OIIO_CONSTEXPR14 : -// OIIO_CONSTEXPR17 : -// OIIO_CONSTEXPR20 : constexpr for C++ >= the designated version, otherwise -// nothing (this is useful for things that can only be -// constexpr for particular versions or greater). -// OIIO_INLINE_CONSTEXPR : inline constexpr variables, added in C++17. For -// older C++, static constexpr. -// -// Note: oiioversion.h defines OIIO_BUILD_CPP (set to 17, 20, etc.) -// reflecting what OIIO itself was *built* with. In contrast, -// OIIO_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 OIIO, but they may not be the same if another -// package is compiling against OIIO and using these headers (OIIO 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 OIIO_CPLUSPLUS_VERSION 20 -# define OIIO_CONSTEXPR17 constexpr -# define OIIO_CONSTEXPR20 constexpr -# define OIIO_INLINE_CONSTEXPR inline constexpr -#elif (__cplusplus >= 201703L) || (defined(_MSC_VER) && _MSC_VER >= 1914) -# define OIIO_CPLUSPLUS_VERSION 17 -# define OIIO_CONSTEXPR17 constexpr -# define OIIO_CONSTEXPR20 /* not constexpr before C++20 */ -# define OIIO_INLINE_CONSTEXPR inline constexpr -#else -# error "This version of OIIO is meant to work only with C++17 and above" -#endif - -// DEPRECATED(2.3): use C++14 constexpr -#define OIIO_CONSTEXPR14 constexpr - -// DEPRECATED(1.8): use C++11 constexpr -#define OIIO_CONSTEXPR constexpr -#define OIIO_CONSTEXPR_OR_CONST constexpr - -// DEPRECATED(1.8): use C++11 noexcept -#define OIIO_NOEXCEPT noexcept - - -// In C++20 (and some compilers before that), __has_cpp_attribute can -// test for understand of [[attr]] tests. -#ifndef __has_cpp_attribute -# define __has_cpp_attribute(x) 0 -#endif - -// On gcc & clang, __has_attribute can test for __attribute__((attr)) -#ifndef __has_attribute -# define __has_attribute(x) 0 -#endif - - - // Detect which compiler and version we're using // Notes: @@ -227,6 +169,55 @@ #endif +// Detect which C++ standard we're using, and handy macros. +// See https://en.cppreference.com/w/cpp/compiler_support +// +// OIIO_CPLUSPLUS_VERSION : which C++ standard is compiling (14, 17, ...) +// OIIO_CONSTEXPR14 : +// OIIO_CONSTEXPR17 : +// OIIO_CONSTEXPR20 : constexpr for C++ >= the designated version, otherwise +// nothing (this is useful for things that can only be +// constexpr for particular versions or greater). +// OIIO_INLINE_CONSTEXPR : inline constexpr variables, added in C++17. For +// older C++, static constexpr. +// +// Note: oiioversion.h defines OIIO_BUILD_CPP (set to 17, 20, etc.) +// reflecting what OIIO itself was *built* with. In contrast, +// OIIO_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 OIIO, but they may not be the same if another +// package is compiling against OIIO and using these headers (OIIO may be +// C++17 but the client package may be newer, or vice versa -- use these two +// symbols to differentiate these cases, when important). +#if (__cplusplus >= 202001L) +# define OIIO_CPLUSPLUS_VERSION 20 +# define OIIO_CONSTEXPR20 constexpr +# define OIIO_INLINE_CONSTEXPR inline constexpr +#elif (__cplusplus >= 201703L) || (defined(_MSC_VER) && _MSC_VER >= 1914) +# define OIIO_CPLUSPLUS_VERSION 17 +# define OIIO_CONSTEXPR20 /* not constexpr before C++20 */ +# define OIIO_INLINE_CONSTEXPR inline constexpr +#else +# error "This version of OIIO is meant to work only with C++17 and above" +#endif + +// DEPRECATED(3.0): use C++17 constexpr +#define OIIO_CONSTEXPR17 constexpr + + +// In C++20 (and some compilers before that), __has_cpp_attribute can +// test for understand of [[attr]] tests. +#ifndef __has_cpp_attribute +# define __has_cpp_attribute(x) 0 +#endif + +// On gcc & clang, __has_attribute can test for __attribute__((attr)) +#ifndef __has_attribute +# define __has_attribute(x) 0 +#endif + + + // Pragma control // // OIIO_PRAGMA(x) make a pragma for *unquoted* x @@ -426,9 +417,6 @@ // [[maybe_unused]] attribute. #define OIIO_MAYBE_UNUSED [[maybe_unused]] -// DEPRECATED(1.9) name: -#define OIIO_UNUSED_OK OIIO_MAYBE_UNUSED - // OIIO_RESTRICT is a parameter attribute that indicates a promise that the // parameter definitely will not alias any other parameters in such a way // that creates a data dependency. Use with caution!