diff --git a/kde-modules/KDECompilerSettings.cmake b/kde-modules/KDECompilerSettings.cmake index 63a5ce1..c42fd55 100644 --- a/kde-modules/KDECompilerSettings.cmake +++ b/kde-modules/KDECompilerSettings.cmake @@ -210,6 +210,46 @@ if (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-operator-names") endif() +# allow projects that do require named operators to (re)activate them +# (this includes projects using boost) +function(KDE_ENABLE_NAMED_OPERATORS) + set(WMSG "Using C++ named operators is not compatible with MSVC prior to version 2017 (19.1).\ + You should reconsider using this macro if your code is meant to be cross-platform") + if (MSVC) + if (MSVC_VERSION LESS 1910) + # https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/ and + # https://blogs.msdn.microsoft.com/vcblog/2016/06/07/standards-version-switches-in-the-compiler/ + # https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance + message(WARNING ${WMSG}) + else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /permissive-") + endif() + else() + string(REPLACE "-fno-operator-names" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + message(WARNING ${WMSG}) + endif() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE) +endfunction() + +function(KDE_TARGET_ENABLE_NAMED_OPERATORS target mode) + set(WMSG "Using C++ named operators is not compatible with MSVC prior to version 2017 (19.1).\ + You should reconsider using this macro if \"${target}\" is meant to be cross-platform") + if (MSVC) + if (MSVC_VERSION LESS 1910) + # https://blogs.msdn.microsoft.com/vcblog/2016/11/16/permissive-switch/ and + # https://blogs.msdn.microsoft.com/vcblog/2016/06/07/standards-version-switches-in-the-compiler/ + # https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance + message(WARNING ${WMSG}) + else() + target_compile_options(${target} ${mode} "/permissive-") + endif() + else() + target_compile_options(${target} ${mode} + "$<$,$,$>:-foperator-names>") + message(WARNING ${WMSG}) + endif() +endfunction() + # Default to hidden visibility for symbols set(CMAKE_C_VISIBILITY_PRESET hidden) set(CMAKE_CXX_VISIBILITY_PRESET hidden)