@@ -72,7 +72,20 @@ function(export_all_flags _filename)
7272 set (_compile_definitions "$<$<BOOL:${_compile_definitions} >:-D$<JOIN:${_compile_definitions} ,\n -D>\n >" )
7373 set (_compile_flags "$<$<BOOL:${_compile_flags} >:$<JOIN:${_compile_flags} ,\n >\n >" )
7474 set (_compile_options "$<$<BOOL:${_compile_options} >:$<JOIN:${_compile_options} ,\n >\n >" )
75- file (GENERATE OUTPUT "${_filename} " CONTENT "${_compile_definitions}${_include_directories}${_compile_flags}${_compile_options} \n " )
75+
76+ set (_cxx_standard "$<TARGET_PROPERTY:${_target} ,CXX_STANDARD>" )
77+ set (_cxx_extensions "$<TARGET_PROPERTY:${_target} ,CXX_EXTENSIONS>" )
78+ set (_has_extensions "$<OR:$<STREQUAL:${_cxx_extensions} ,>,$<BOOL:${_cxx_extensions} >>" ) # CXX_EXTENSION default to true
79+ set (_cxx_standard_check "$<$<AND:$<STREQUAL:${_cxx_standard} ,17>,$<NOT:${_has_extensions} >>:${CMAKE_CXX17_STANDARD_COMPILE_OPTION} >" )
80+ set (_cxx_standard_check "${_cxx_standard_check} $<$<AND:$<STREQUAL:${_cxx_standard} ,14>,$<NOT:${_has_extensions} >>:${CMAKE_CXX14_STANDARD_COMPILE_OPTION} >" )
81+ set (_cxx_standard_check "${_cxx_standard_check} $<$<AND:$<STREQUAL:${_cxx_standard} ,11>,$<NOT:${_has_extensions} >>:${CMAKE_CXX11_STANDARD_COMPILE_OPTION} >" )
82+ set (_cxx_standard_check "${_cxx_standard_check} $<$<AND:$<STREQUAL:${_cxx_standard} ,98>,$<NOT:${_has_extensions} >>:${CMAKE_CXX98_STANDARD_COMPILE_OPTION} >" )
83+ set (_cxx_standard_check "${_cxx_standard_check} $<$<AND:$<STREQUAL:${_cxx_standard} ,17>,${_has_extensions} >:${CMAKE_CXX17_EXTENSION_COMPILE_OPTION} >" )
84+ set (_cxx_standard_check "${_cxx_standard_check} $<$<AND:$<STREQUAL:${_cxx_standard} ,14>,${_has_extensions} >:${CMAKE_CXX14_EXTENSION_COMPILE_OPTION} >" )
85+ set (_cxx_standard_check "${_cxx_standard_check} $<$<AND:$<STREQUAL:${_cxx_standard} ,11>,${_has_extensions} >:${CMAKE_CXX11_EXTENSION_COMPILE_OPTION} >" )
86+ set (_cxx_standard_check "${_cxx_standard_check} $<$<AND:$<STREQUAL:${_cxx_standard} ,98>,${_has_extensions} >:${CMAKE_CXX98_EXTENSION_COMPILE_OPTION} >" )
87+
88+ file (GENERATE OUTPUT "${_filename} " CONTENT "${_compile_definitions}${_include_directories}${_compile_flags}${_compile_options}${_cxx_standard_check} \n " )
7689endfunction ()
7790
7891function (add_precompiled_header _target _input)
@@ -147,7 +160,7 @@ function(add_precompiled_header _target _input)
147160 endif ()
148161 endif (MSVC )
149162
150- if (CMAKE_COMPILER_IS_GNUCXX )
163+ if (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU|Clang" )
151164 get_filename_component (_name ${_input} NAME )
152165 set (_pch_header "${CMAKE_CURRENT_SOURCE_DIR} /${_input} " )
153166 set (_pch_binary_dir "${CMAKE_CURRENT_BINARY_DIR} /${_target} _pch" )
@@ -210,5 +223,5 @@ function(add_precompiled_header _target _input)
210223 OBJECT_DEPENDS "${_object_depends} " )
211224 endif ()
212225 endforeach ()
213- endif (CMAKE_COMPILER_IS_GNUCXX )
226+ endif (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU|Clang" )
214227endfunction ()
0 commit comments