Skip to content

Commit a7be406

Browse files
committed
CMakeLists.txt: set correct __cplusplus for MSVC
VC **always** sets __cplusplus to 199711L (sic!) unless passed /Zc:__cplusplus for compat reasons. We now assume __cplusplus is at least 201107L for C++ (in our case the CUDA code) for static_assert. See also: <https://gitlab.kitware.com/cmake/cmake/-/issues/18837>
1 parent 973e84b commit a7be406

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
5757
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})
5858

5959
if(NOT MSVC OR MSVC_TOOLSET_VERSION GREATER 140)
60-
list(APPEND NEEDED_COMPILER_FEATURES c_std_11)
60+
set(NEEDED_COMPILER_FEATURES c_std_11)
6161
endif()
6262

6363
set(COMPILED_OPTIONS)
@@ -74,6 +74,9 @@ endif()
7474
if (MSVC)
7575
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
7676
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler /W4")
77+
if (MSVC_VERSION GREATER_EQUAL 1914)
78+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler /Zc:__cplusplus")
79+
endif()
7780
else()
7881
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic")
7982
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler -Wall -Xcompiler -Wextra")

src/gpujpeg_common_internal.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@
4646
// static_assert compat
4747
#if defined __cplusplus
4848
#if __cplusplus < 201103L
49-
#error "compiler is not supporting C++11 - perhaps not passed std?"
49+
#if defined _MSC_VER
50+
#if _MSC_VER >= 1914
51+
#error "compiler is not advertising C++11 - perhaps not passed /Zc:__cplusplus?"
52+
#endif
53+
// do nothing for earlier versions - unsolvable, __cplusplus is always 199711L
54+
#else
55+
#error "compiler is not supporting C++11 - perhaps not passed std?"
56+
#endif
5057
#endif
5158
#elif __STDC_VERSION__ < 201112L
5259
#if defined _MSC_VER && _MSC_VER <= 1900

0 commit comments

Comments
 (0)