@@ -161,35 +161,41 @@ option(BUILD_WERROR "Enable warnings as errors")
161161# Note that clang-cl.exe should use MSVC flavor flags, not GNU
162162if (CMAKE_C_COMPILER_ID STREQUAL "MSVC" OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "MSVC" ))
163163 if (BUILD_WERROR)
164- target_compile_options (loader_common_options INTERFACE /WX)
164+ target_compile_options (loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>: /WX> )
165165 endif ()
166- target_compile_options (loader_common_options INTERFACE /W4)
166+ target_compile_options (loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>: /W4> )
167167elseif (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" )
168168 # using GCC or Clang with the regular front end
169169 if (BUILD_WERROR)
170- target_compile_options (loader_common_options INTERFACE -Werror)
170+ target_compile_options (loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>: -Werror> )
171171 endif ()
172- target_compile_options (loader_common_options INTERFACE -Wall -Wextra)
172+ target_compile_options (loader_common_options INTERFACE
173+ $<$<COMPILE_LANGUAGE::CXX,C>:-Wall>
174+ $<$<COMPILE_LANGUAGE::CXX,C>:-Wextra>
175+ )
173176endif ()
174177
175178if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang" )
176- target_compile_options (loader_common_options INTERFACE -Wno-missing-field-initializers)
179+ target_compile_options (loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>: -Wno-missing-field-initializers> )
177180
178181 # need to prepend /clang: to compiler arguments when using clang-cl
179182 if (CMAKE_C_COMPILER_ID STREQUAL "Clang" AND "${CMAKE_C_COMPILER_FRONTEND_VARIANT} " MATCHES "MSVC" )
180- target_compile_options (loader_common_options INTERFACE /clang:-fno-strict-aliasing)
183+ target_compile_options (loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>: /clang:-fno-strict-aliasing> )
181184 else ()
182- target_compile_options (loader_common_options INTERFACE -fno-strict-aliasing)
185+ target_compile_options (loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>: -fno-strict-aliasing> )
183186 endif ()
184187
185188 if (CMAKE_C_COMPILER_ID STREQUAL "GNU" )
186- target_compile_options (loader_common_options INTERFACE -Wno-stringop-truncation -Wno-stringop-overflow)
189+ target_compile_options (loader_common_options INTERFACE
190+ $<$<COMPILE_LANGUAGE::CXX,C>:-Wno-stringop-truncation>
191+ $<$<COMPILE_LANGUAGE::CXX,C>:-Wno-stringop-overflow>
192+ )
187193 if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 7.1)
188- target_compile_options (loader_common_options INTERFACE -Wshadow=local) #only added in GCC 7
194+ target_compile_options (loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>: -Wshadow=local> ) #only added in GCC 7
189195 endif ()
190196 endif ()
191197
192- target_compile_options (loader_common_options INTERFACE -Wpointer-arith)
198+ target_compile_options (loader_common_options INTERFACE $<$<COMPILE_LANGUAGE::CXX,C>: -Wpointer-arith> )
193199
194200 # Force GLIBC to use the 64 bit interface for file operations instead of 32 bit - More info in issue #1551
195201 if ("${CMAKE_SIZEOF_VOID_P} " EQUAL "4" )
@@ -203,7 +209,13 @@ if(CMAKE_C_COMPILER_ID MATCHES "MSVC" OR (CMAKE_C_COMPILER_ID STREQUAL "Clang" A
203209 # /guard:cf: Enable control flow guard
204210 # /wd4152: Disable warning on conversion of a function pointer to a data pointer
205211 # /wd4201: Disable warning on anonymous struct/unions
206- target_compile_options (loader_common_options INTERFACE /sdl /GR- /guard:cf /wd4152 /wd4201)
212+ target_compile_options (loader_common_options INTERFACE
213+ $<$<COMPILE_LANGUAGE::CXX,C>:/sdl>
214+ $<$<COMPILE_LANGUAGE::CXX,C>:/GR->
215+ $<$<COMPILE_LANGUAGE::CXX,C>:/guard:cf>
216+ $<$<COMPILE_LANGUAGE::CXX,C>:/wd4152>
217+ $<$<COMPILE_LANGUAGE::CXX,C>:/wd4201>
218+ )
207219
208220 # Enable control flow guard
209221 target_link_options (loader_common_options INTERFACE "LINKER:/guard:cf" )
0 commit comments