From 2aa18ca3e93a1a32fec2c063010b72335ac795e9 Mon Sep 17 00:00:00 2001 From: Csaba Keszegh Date: Tue, 16 Jan 2018 15:22:26 +0100 Subject: [PATCH] fix: use CXX_STANDARD when extracting compiler flags for PCH with GNUCXX When compiling with cmake using -DCMAKE_CXX_STANDARD=11 use `-std=gnu++11` for PCH compiler flags, otherwise it triggers an error: opencv_core_Release.gch: not used because `__cplusplus' defined as ` 201103L' not ` 199711L' [-Winvalid-pch] Use CXX_EXTENSIONS property to select `gnu++11` or `c++11`. Trying to mimic cmake logic here: https://gitlab.kitware.com/cmake/cmake/blob/master/Source/cmLocalGenerator.cxx#L1527-1557 --- cmake/OpenCVPCHSupport.cmake | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmake/OpenCVPCHSupport.cmake b/cmake/OpenCVPCHSupport.cmake index 0e41130b0f..6a2f6ee655 100644 --- a/cmake/OpenCVPCHSupport.cmake +++ b/cmake/OpenCVPCHSupport.cmake @@ -56,6 +56,15 @@ MACRO(_PCH_GET_COMPILE_FLAGS _out_compile_flags) endforeach() endif() + GET_TARGET_PROPERTY(_cxx_standard ${_PCH_current_target} CXX_STANDARD) + if (_cxx_standard) + GET_TARGET_PROPERTY(_cxx_extensions ${_PCH_current_target} CXX_EXTENSIONS) + if (_cxx_extensions) + LIST(APPEND ${_out_compile_flags} "${CMAKE_CXX${_cxx_standard}_EXTENSION_COMPILE_OPTION}") + else() + LIST(APPEND ${_out_compile_flags} "${CMAKE_CXX${_cxx_standard}_STANDARD_COMPILE_OPTION}") + endif() + endif() ELSE() ## TODO ... ? or does it work out of the box ENDIF()