Skip to content

Commit

Permalink
CMakeLists.txt: set correct __cplusplus for MSVC
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
MartinPulec committed Jan 31, 2025
1 parent 973e84b commit a7be406
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR})

if(NOT MSVC OR MSVC_TOOLSET_VERSION GREATER 140)
list(APPEND NEEDED_COMPILER_FEATURES c_std_11)
set(NEEDED_COMPILER_FEATURES c_std_11)
endif()

set(COMPILED_OPTIONS)
Expand All @@ -74,6 +74,9 @@ endif()
if (MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler /W4")
if (MSVC_VERSION GREATER_EQUAL 1914)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler /Zc:__cplusplus")
endif()
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic")
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -Xcompiler -Wall -Xcompiler -Wextra")
Expand Down
9 changes: 8 additions & 1 deletion src/gpujpeg_common_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@
// static_assert compat
#if defined __cplusplus
#if __cplusplus < 201103L
#error "compiler is not supporting C++11 - perhaps not passed std?"
#if defined _MSC_VER
#if _MSC_VER >= 1914
#error "compiler is not advertising C++11 - perhaps not passed /Zc:__cplusplus?"
#endif
// do nothing for earlier versions - unsolvable, __cplusplus is always 199711L
#else
#error "compiler is not supporting C++11 - perhaps not passed std?"
#endif
#endif
#elif __STDC_VERSION__ < 201112L
#if defined _MSC_VER && _MSC_VER <= 1900
Expand Down

0 comments on commit a7be406

Please sign in to comment.