Skip to content

Commit

Permalink
Merge branch 'cmake320policies'
Browse files Browse the repository at this point in the history
  • Loading branch information
dzenanz committed Jul 16, 2021
2 parents 9c0adc4 + d3e151f commit 9d474f9
Show file tree
Hide file tree
Showing 14 changed files with 62 additions and 178 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Expand Up @@ -24,12 +24,12 @@ cmake_policy(VERSION ${ITK_CMAKE_POLICY_VERSION})
# Now enumerate specific policies newer than ITK_NEWEST_VALIDATED_POLICIES_VERSION
# that may need to be individually set to NEW/OLD
#
foreach(pnew "") # Currently Empty
foreach(pnew "CMP0120")
if(POLICY ${pnew})
cmake_policy(SET ${pnew} NEW)
endif()
endforeach()
foreach(pold "CMP0120" "CMP0091") # CMP0120 will require non-trivial effort to address
foreach(pold "CMP0091")
if(POLICY ${pold})
cmake_policy(SET ${pold} OLD)
endif()
Expand Down Expand Up @@ -243,7 +243,7 @@ mark_as_advanced(CMAKE_DEBUG_POSTFIX)

# Configure find_package behavior
if(NOT DEFINED CMAKE_FIND_USE_PACKAGE_REGISTRY)
set(CMAKE_FIND_USE_PACKAGE_REGISTRY 0)
set(CMAKE_FIND_USE_PACKAGE_REGISTRY 0)
endif()

# Setup build locations for shared libraries ----START
Expand Down

This file was deleted.

13 changes: 0 additions & 13 deletions Modules/Core/Common/CMakeLists.txt
Expand Up @@ -145,21 +145,8 @@ set(ITKCommon_LIBRARIES ITKCommon)

itk_module_impl()

# configure and install compiler feature header files
# that have fine granular support of C++11 features
# identified in a way consistent with CMake 3.1.0 and
# greater
include(CMake/itkGenerateNewCompilerFeatureDetectionHeaders.cmake)

install(FILES
${ITKCommon_BINARY_DIR}/itkConfigure.h
${CMAKE_CURRENT_BINARY_DIR}/itk_compiler_detection.h
DESTINATION ${ITKCommon_INSTALL_INCLUDE_DIR}
COMPONENT Development
)

install(FILES
${ITK_compiler_detection_support_headers}
DESTINATION ${ITKCommon_INSTALL_INCLUDE_DIR}/compilers
COMPONENT Development
)
18 changes: 18 additions & 0 deletions Modules/Core/Common/include/itkMacro.h
Expand Up @@ -1371,4 +1371,22 @@ itkDynamicCastInDebugMode(TSource x)
return static_cast<TTarget>(x);
#endif
}

// Defines which used to be in itk_compiler_detection.h
#define ITK_ALIGNAS(X) alignas(X)
#define ITK_ALIGNOF(X) alignof(X)
#define ITK_DEPRECATED [[deprecated]]
#define ITK_DEPRECATED_MSG(MSG) [[deprecated(MSG)]]
#define ITK_CONSTEXPR constexpr
#define ITK_DELETED_FUNCTION = delete
#define ITK_EXTERN_TEMPLATE extern
#define ITK_FINAL final
#define ITK_NOEXCEPT noexcept
#define ITK_NOEXCEPT_EXPR(X) noexcept(X)
#define ITK_NULLPTR nullptr
#define ITK_OVERRIDE override
#define ITK_STATIC_ASSERT(X) static_assert(X, #X)
#define ITK_STATIC_ASSERT_MSG(X, MSG) static_assert(X, MSG)
#define ITK_THREAD_LOCAL thread_local

#endif // end of itkMacro.h
46 changes: 6 additions & 40 deletions Modules/Core/Common/include/itkStaticAssert.h
Expand Up @@ -21,52 +21,18 @@

#include "itkMacro.h"

#if ITK_COMPILER_CXX_STATIC_ASSERT
// Use the C++11 static_assert if available

#if !defined(ITK_LEGACY_REMOVE)
/** Static assertion.
* This macro will either emulate static assertions on the current compiler or
* use C++11 \c static_assert() keyword.
* This macro will use C++11 \c static_assert() keyword.
* \param expr compile-time expression to check
* \param str string literal that will appear (C++11, GCC 4.3+) as compiler
* error if \c expr is \c false.
* \param str string literal that will appear as compiler error if \c expr is \c false.
* \ingroup ITKCommon
*/
# define itkStaticAssert(expr, str) static_assert(expr, str)
#elif defined(__GNUC__) && !defined(__INTEL_COMPILER)
// This trick restricts the static assertion to non global contexts (-> functions)
# define itkStaticAssert(expr, str) \
({ \
extern int __attribute__((error(str))) StaticAssertFailure(); \
((void)((expr) ? 0 : StaticAssertFailure()), 0); \
})
#else
// Usual trick (boost, clang, ...), but it will loose the error message on the
// way
# define ITK_JOIN(X, Y) ITK_DO_JOIN(X, Y)
# define ITK_DO_JOIN(X, Y) ITK_DO_JOIN2(X, Y)
# define ITK_DO_JOIN2(X, Y) X##Y

namespace itk
{
/// \cond HIDE_META_PROGRAMMING
/** Internal class to emulate static assertions of pre-C++11 compilers.
* \sa \c itkStaticAssert
* \ingroup ITKCommon
*/
template <bool V>
struct StaticAssertFailure;
template <>
struct StaticAssertFailure<true>
{};
/// \endcond
} // namespace itk

# define itkStaticAssert(expr, str) \
enum \
{ \
ITK_JOIN(static_assert_typedef, __LINE__) = sizeof(itk::StaticAssertFailure<((expr) == 0 ? false : true)>) \
};
# define itkStaticAssert(expr, str) Use C++ 11 static_assert directly
#endif

// TODO: remove this file entirely in the future (e.g. with ITKv6)

#endif // itkStaticAssert_h
5 changes: 2 additions & 3 deletions Modules/Core/Common/include/itkVariableLengthVector.h
Expand Up @@ -21,7 +21,6 @@
#include <cassert>
#include <algorithm>
#include "itkNumericTraits.h"
#include "itkStaticAssert.h"
#include "itkMetaProgrammingLibrary.h"
#include "itkEnableIf.h"
#include "itkIsBaseOf.h"
Expand Down Expand Up @@ -1206,8 +1205,8 @@ struct VariableLengthVectorExpression
{
// Not neccessary actually as end-user/developer is not expected to
// provide new BinaryOperations
itkStaticAssert((itk::mpl::IsBaseOf<Details::op::BinaryOperationConcept, TBinaryOp>::Value),
"The Binary Operation shall inherit from BinaryOperationConcept");
static_assert((itk::mpl::IsBaseOf<Details::op::BinaryOperationConcept, TBinaryOp>::Value),
"The Binary Operation shall inherit from BinaryOperationConcept");
}

/// Returns the size of the vector expression.
Expand Down
5 changes: 2 additions & 3 deletions Modules/Core/Common/include/itkVariableLengthVector.hxx
Expand Up @@ -23,7 +23,6 @@
#include <cstring>
#include <cstdlib>
#include "itkIsBaseOf.h"
#include "itkStaticAssert.h"
#include "itkMath.h"

namespace itk
Expand Down Expand Up @@ -292,10 +291,10 @@ template <typename TReallocatePolicy, typename TKeepValuesPolicy>
void
VariableLengthVector<TValue>::SetSize(unsigned int sz, TReallocatePolicy reallocatePolicy, TKeepValuesPolicy keepValues)
{
itkStaticAssert(
static_assert(
(itk::mpl::IsBaseOf<AllocateRootPolicy, TReallocatePolicy>::Value),
"The allocation policy does not inherit from itk::VariableLengthVector::AllocateRootPolicy as expected");
itkStaticAssert(
static_assert(
(itk::mpl::IsBaseOf<KeepValuesRootPolicy, TKeepValuesPolicy>::Value),
"The old values keeping policy does not inherit from itk::VariableLengthVector::KeepValuesRootPolicy as expected");

Expand Down
3 changes: 0 additions & 3 deletions Modules/Core/Common/src/itkConfigure.h.in
Expand Up @@ -18,9 +18,6 @@
#ifndef itkConfigure_h
#define itkConfigure_h

/* Define granular compiler features. */
#include "itk_compiler_detection.h"

/*
* here is where system computed values get stored these values should only
* change when the target compile platform changes
Expand Down
11 changes: 5 additions & 6 deletions Modules/Core/Common/test/itkIsBaseOf.cxx
Expand Up @@ -17,7 +17,6 @@
*=========================================================================*/

#include "itkIsBaseOf.h"
#include "itkStaticAssert.h"

struct Base
{};
Expand All @@ -27,13 +26,13 @@ struct Child : Base
int
itkIsBaseOf(int, char *[])
{
itkStaticAssert((itk::mpl::IsConvertible<char, double>::Value), "Unit test failed");
itkStaticAssert((!itk::mpl::IsConvertible<char, char *>::Value), "Unit test failed");
static_assert((itk::mpl::IsConvertible<char, double>::Value), "Unit test failed");
static_assert((!itk::mpl::IsConvertible<char, char *>::Value), "Unit test failed");

itkStaticAssert((itk::mpl::IsBaseOf<Base, Child>::Value), "Unit test failed");
itkStaticAssert((!itk::mpl::IsBaseOf<Child, Base>::Value), "Unit test failed");
static_assert((itk::mpl::IsBaseOf<Base, Child>::Value), "Unit test failed");
static_assert((!itk::mpl::IsBaseOf<Child, Base>::Value), "Unit test failed");

itkStaticAssert((!itk::mpl::IsBaseOf<void, Child>::Value), "Unit test failed");
static_assert((!itk::mpl::IsBaseOf<void, Child>::Value), "Unit test failed");

return EXIT_SUCCESS;
}
9 changes: 4 additions & 5 deletions Modules/Core/Common/test/itkIsConvertible.cxx
Expand Up @@ -17,7 +17,6 @@
*=========================================================================*/

#include "itkIsConvertible.h"
#include "itkStaticAssert.h"

struct Base
{};
Expand All @@ -27,11 +26,11 @@ struct Child : Base
int
itkIsConvertible(int, char *[])
{
itkStaticAssert((itk::IsConvertible<char, double>::Value), "Unit test failed");
itkStaticAssert((!itk::IsConvertible<char, char *>::Value), "Unit test failed");
static_assert((itk::IsConvertible<char, double>::Value), "Unit test failed");
static_assert((!itk::IsConvertible<char, char *>::Value), "Unit test failed");

itkStaticAssert((itk::IsConvertible<Child *, void *>::Value), "Unit test failed");
itkStaticAssert((!itk::IsConvertible<void *, Child *>::Value), "Unit test failed");
static_assert((itk::IsConvertible<Child *, void *>::Value), "Unit test failed");
static_assert((!itk::IsConvertible<void *, Child *>::Value), "Unit test failed");

return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions Modules/Core/Common/test/itkMetaProgrammingLibraryTest.cxx
Expand Up @@ -16,6 +16,9 @@
*
*=========================================================================*/

// we need to test the deprecated itkStaticAssert
#define ITK_LEGACY_TEST

#include "itkMetaProgrammingLibrary.h"
#include "itkIsSame.h"
#include "itkStaticAssert.h"
Expand Down
32 changes: 15 additions & 17 deletions Modules/Core/Common/test/itkPromoteType.cxx
Expand Up @@ -18,7 +18,6 @@

#include "itkPromoteType.h"
#include <complex>
#include <itkStaticAssert.h>
#include <itkIsSame.h>

namespace itk
Expand Down Expand Up @@ -55,22 +54,21 @@ itkPromoteType(int, char *[])
// the following list able to hold their entire value range: int, unsigned
// int, long, unsigned long, long long, unsigned long long.

itkStaticAssert((IsSame<PromoteType<signed char, int>::Type, int>::Value), "test failed");
itkStaticAssert((IsSame<PromoteType<signed char, short>::Type, int>::Value), "test failed");
itkStaticAssert((IsSame<PromoteType<unsigned char, int>::Type, int>::Value), "test failed");
itkStaticAssert((IsSame<PromoteType<unsigned char, unsigned int>::Type, unsigned int>::Value), "test failed");
itkStaticAssert((IsSame<PromoteType<int, int>::Type, int>::Value), "test failed");
itkStaticAssert((IsSame<PromoteType<short, int>::Type, int>::Value), "test failed");
itkStaticAssert((IsSame<PromoteType<double, int>::Type, double>::Value), "test failed");
itkStaticAssert((IsSame<PromoteType<float, int>::Type, float>::Value), "test failed");
itkStaticAssert((IsSame<PromoteType<long, int>::Type, long>::Value), "test failed");
itkStaticAssert((IsSame<PromoteType<long long, int>::Type, long long>::Value), "test failed");
itkStaticAssert((IsSame<PromoteType<int, long long>::Type, long long>::Value), "test failed");
itkStaticAssert((IsSame<PromoteType<long, long double>::Type, long double>::Value), "test failed");
itkStaticAssert((IsSame<PromoteType<double, std::complex<double>>::Type, std::complex<double>>::Value),
"test failed");
static_assert((IsSame<PromoteType<signed char, int>::Type, int>::Value), "test failed");
static_assert((IsSame<PromoteType<signed char, short>::Type, int>::Value), "test failed");
static_assert((IsSame<PromoteType<unsigned char, int>::Type, int>::Value), "test failed");
static_assert((IsSame<PromoteType<unsigned char, unsigned int>::Type, unsigned int>::Value), "test failed");
static_assert((IsSame<PromoteType<int, int>::Type, int>::Value), "test failed");
static_assert((IsSame<PromoteType<short, int>::Type, int>::Value), "test failed");
static_assert((IsSame<PromoteType<double, int>::Type, double>::Value), "test failed");
static_assert((IsSame<PromoteType<float, int>::Type, float>::Value), "test failed");
static_assert((IsSame<PromoteType<long, int>::Type, long>::Value), "test failed");
static_assert((IsSame<PromoteType<long long, int>::Type, long long>::Value), "test failed");
static_assert((IsSame<PromoteType<int, long long>::Type, long long>::Value), "test failed");
static_assert((IsSame<PromoteType<long, long double>::Type, long double>::Value), "test failed");
static_assert((IsSame<PromoteType<double, std::complex<double>>::Type, std::complex<double>>::Value), "test failed");

itkStaticAssert((IsSame<PromoteType<std::complex<int>, std::complex<double>>::Type, std::complex<double>>::Value),
"test failed");
static_assert((IsSame<PromoteType<std::complex<int>, std::complex<double>>::Type, std::complex<double>>::Value),
"test failed");
return EXIT_SUCCESS;
}

0 comments on commit 9d474f9

Please sign in to comment.