Browse Source

Let CMake decide when to start using constexpr

Michael Hansen 10 years ago
parent
commit
10a827ba52
  1. 10
      Sources/Plasma/CoreLib/HeadSpin.h
  2. 5
      cmake/CompilerChecks.cmake
  3. 6
      cmake/check_constexpr.cpp
  4. 2
      cmake/hsCompilerSpecific.h.cmake

10
Sources/Plasma/CoreLib/HeadSpin.h

@ -238,10 +238,12 @@ inline double hsSwapEndianDouble(double dvalue)
* StrPrintf(buffer, arrsize(buffer), "%u", value); * StrPrintf(buffer, arrsize(buffer), "%u", value);
* *
***/ ***/
#define arrsize(a) (sizeof(a) / sizeof((a)[0])) #ifdef HAVE_CONSTEXPR
/* TODO: Use this safer version when MSVC finally supports constexpr */ template <typename _T, size_t _Sz>
//template <typename _T, size_t _Sz> constexpr size_t arrsize(_T(&)[_Sz]) { return _Sz; }
//constexpr size_t arrsize(_T (&)[_Sz]) { return _Sz; } #else
# define arrsize(a) (sizeof(a) / sizeof((a)[0]))
#endif
/**************************************************************************** /****************************************************************************

5
cmake/CompilerChecks.cmake

@ -51,6 +51,11 @@ try_compile(HAVE_GCC_DEPRECATED_ATTR ${PROJECT_BINARY_DIR}
COMPILE_DEFINITIONS -DTRY_GCC_ATTR COMPILE_DEFINITIONS -DTRY_GCC_ATTR
OUTPUT_VARIABLE OUTPUT) OUTPUT_VARIABLE OUTPUT)
# Look for C++11 constexpr support
try_compile(HAVE_CONSTEXPR ${PROJECT_BINARY_DIR}
${PROJECT_SOURCE_DIR}/cmake/check_constexpr.cpp
OUTPUT_VARIABLE OUTPUT)
configure_file(${PROJECT_SOURCE_DIR}/cmake/hsCompilerSpecific.h.cmake configure_file(${PROJECT_SOURCE_DIR}/cmake/hsCompilerSpecific.h.cmake
${PROJECT_BINARY_DIR}/hsCompilerSpecific.h) ${PROJECT_BINARY_DIR}/hsCompilerSpecific.h)
include_directories(${PROJECT_BINARY_DIR}) include_directories(${PROJECT_BINARY_DIR})

6
cmake/check_constexpr.cpp

@ -0,0 +1,6 @@
constexpr int foo() { return 5; }
int main(int, char **)
{
return foo();
}

2
cmake/hsCompilerSpecific.h.cmake

@ -51,4 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#cmakedefine HAVE_CXX14_DEPRECATED_ATTR #cmakedefine HAVE_CXX14_DEPRECATED_ATTR
#cmakedefine HAVE_GCC_DEPRECATED_ATTR #cmakedefine HAVE_GCC_DEPRECATED_ATTR
#cmakedefine HAVE_CONSTEXPR
#endif #endif

Loading…
Cancel
Save