Generator expression COMPILE_LANGUAGE doesn't support ${VAR} if ${VAR} is a list.
I wrote a function
function(target_disable_warning TARGETNAME VISIBILITY)
unset(options)
unset(oneValueArgs)
set(multiValueArgs LANGS MANDATORY_WARNINGS)
cmake_parse_arguments(FUNC_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(FUNC_ARGS_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown arguments to target_disable_warning.")
endif()
foreach(WARNING ${FUNC_ARGS_MANDATORY_WARNINGS})
target_compile_options(${TARGETNAME} ${VISIBILITY} $<$<COMPILE_LANGUAGE:${FUNC_ARGS_LANGS}>:-Wno-${WARNING}>)
endforeach()
endfunction()
I call it like this, and it doesn't work.
target_disable_warning(${PROJECT_NAME} PRIVATE LANGS C CXX
MANDATORY_WARNINGS
uninitialized
mismatched-tags
deprecated-copy
unused-function
)
I call it like this (remove the C
) and it works
target_disable_warning(${PROJECT_NAME} PRIVATE LANGS CXX
MANDATORY_WARNINGS
uninitialized
mismatched-tags
deprecated-copy
unused-function
)
I change the function to this, and it starts working with C CXX
for LANGS
function(target_disable_warning TARGETNAME VISIBILITY)
unset(options)
unset(oneValueArgs)
set(multiValueArgs LANGS MANDATORY_WARNINGS)
cmake_parse_arguments(FUNC_ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if(FUNC_ARGS_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown arguments to target_disable_warning.")
endif()
foreach(LANG ${FUNC_ARGS_LANGS})
foreach(WARNING ${FUNC_ARGS_MANDATORY_WARNINGS})
target_compile_options(${TARGETNAME} ${VISIBILITY} $<$<COMPILE_LANGUAGE:${LANG}>:-Wno-${WARNING}>)
endforeach()
endforeach()
endfunction()
I attempted to use $<JOIN:${FUNC_ARGS_LANGS},",">
instead.
It didn't work.
End users expect trivial things, like a list variable working properly on a generator expression that takes a comma separated list, to work without having to do anything extra.