Skip to content

Commit

Permalink
Fix cxx standard detection under windows with msvc. Closes #1307
Browse files Browse the repository at this point in the history
  • Loading branch information
fspindle committed Jan 12, 2024
1 parent 02e8cb3 commit fa2672f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
1 change: 1 addition & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ ViSP 3.x.x (Version in development)
. [#1274] Build issue no member named clamp in namespace std
. [#1279] Issue in vpPoseVector json serialization
. [#1296] Unable to parse camera parameters with vpXmlParserCamera::parse() when camera name is empty
. [#1307] Cannot set cxx standard when configuring for Visual Studio
----------------------------------------------
ViSP 3.6.0 (released September 22, 2023)
- Contributors:
Expand Down
53 changes: 37 additions & 16 deletions cmake/VISPDetectCXXStandard.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -48,39 +48,60 @@ else()
# Setting CMAKE_CXX_STANDARD doesn't affect check_cxx_source_compiles() used to detect isnan() in FindIsNaN.cmake
# or erfc() in FindErfc.cmake.
# That's why we have the following lines that are used to set cxx flags corresponding to the c++ standard
vp_check_compiler_flag(CXX "-std=c++11" HAVE_STD_CXX11_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx11.cpp")
if(HAVE_STD_CXX11_FLAG)
set(CXX11_CXX_FLAGS "-std=c++11" CACHE STRING "C++ compiler flags for C++11 support")
vp_check_compiler_flag(CXX "" HAVE_CXX11_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx11.cpp")
if(HAVE_CXX11_FLAG)
set(CXX11_STANDARD_FOUND ON CACHE STRING "cxx11 standard")
mark_as_advanced(CXX11_STANDARD_FOUND)
mark_as_advanced(CXX11_CXX_FLAGS)
mark_as_advanced(HAVE_STD_CXX11_FLAG)
mark_as_advanced(HAVE_CXX11_FLAG)
else()
vp_check_compiler_flag(CXX "-std=c++11" HAVE_STD_CXX11_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx11.cpp")
if(HAVE_STD_CXX11_FLAG)
set(CXX11_CXX_FLAGS "-std=c++11" CACHE STRING "C++ compiler flags for C++11 support")
set(CXX11_STANDARD_FOUND ON CACHE STRING "cxx11 standard")
mark_as_advanced(CXX11_STANDARD_FOUND)
mark_as_advanced(CXX11_CXX_FLAGS)
mark_as_advanced(HAVE_STD_CXX11_FLAG)
endif()
endif()
endif()
endif()

if(CMAKE_CXX14_COMPILE_FEATURES)
# Additionnal check in case of c++14 is incomplete and also needed to set CXX14_CXX_FLAGS
vp_check_compiler_flag(CXX "-std=c++14" HAVE_STD_CXX14_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx14.cpp")
if(HAVE_STD_CXX14_FLAG)
set(CXX14_CXX_FLAGS "-std=c++14" CACHE STRING "C++ compiler flags for C++14 support")
vp_check_compiler_flag(CXX "" HAVE_CXX14_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx14.cpp")
if(HAVE_CXX14_FLAG)
set(CXX14_STANDARD_FOUND ON CACHE STRING "cxx14 standard")
mark_as_advanced(CXX14_STANDARD_FOUND)
mark_as_advanced(CXX14_CXX_FLAGS)
mark_as_advanced(HAVE_STD_CXX14_FLAG)
mark_as_advanced(HAVE_CXX14_FLAG)
else()
vp_check_compiler_flag(CXX "-std=c++14" HAVE_STD_CXX14_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx14.cpp")
if(HAVE_STD_CXX14_FLAG)
set(CXX14_CXX_FLAGS "-std=c++14" CACHE STRING "C++ compiler flags for C++14 support")
set(CXX14_STANDARD_FOUND ON CACHE STRING "cxx14 standard")
mark_as_advanced(CXX14_STANDARD_FOUND)
mark_as_advanced(CXX14_CXX_FLAGS)
mark_as_advanced(HAVE_STD_CXX14_FLAG)
endif()
endif()
endif()

if(CMAKE_CXX17_COMPILE_FEATURES)
# c++17 seems available, but on Fedora 25 and g++ 6.3.1 it seems incomplete where
# optional header is not found as well as std::clamp()
vp_check_compiler_flag(CXX "-std=c++17" HAVE_STD_CXX17_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx17.cpp")
if(HAVE_STD_CXX17_FLAG)
set(CXX17_CXX_FLAGS "-std=c++17" CACHE STRING "C++ compiler flags for C++17 support")
vp_check_compiler_flag(CXX "" HAVE_CXX17_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx17.cpp")
if(HAVE_CXX17_FLAG)
set(CXX17_STANDARD_FOUND ON CACHE STRING "cxx17 standard")
mark_as_advanced(CXX17_STANDARD_FOUND)
mark_as_advanced(CXX17_CXX_FLAGS)
mark_as_advanced(HAVE_STD_CXX17_FLAG)
mark_as_advanced(HAVE_CXX17_FLAG)
else()
vp_check_compiler_flag(CXX "-std=c++17" HAVE_STD_CXX17_FLAG "${PROJECT_SOURCE_DIR}/cmake/checks/cxx17.cpp")
if(HAVE_STD_CXX17_FLAG)
set(CXX17_CXX_FLAGS "-std=c++17" CACHE STRING "C++ compiler flags for C++17 support")
set(CXX17_STANDARD_FOUND ON CACHE STRING "cxx17 standard")
mark_as_advanced(CXX17_STANDARD_FOUND)
mark_as_advanced(CXX17_CXX_FLAGS)
mark_as_advanced(HAVE_STD_CXX17_FLAG)
endif()
endif()
endif()

Expand All @@ -102,7 +123,7 @@ else()

if(AVAILABLE_CXX_STANDARD)
if(CXX11_STANDARD_FOUND)
set_property(CACHE USE_CXX_STANDARD APPEND_STRING PROPERTY STRINGS ";11")
set_property(CACHE USE_CXX_STANDARD APPEND_STRING PROPERTY STRINGS "11")
endif()
if(CXX14_STANDARD_FOUND)
set_property(CACHE USE_CXX_STANDARD APPEND_STRING PROPERTY STRINGS ";14")
Expand Down

0 comments on commit fa2672f

Please sign in to comment.