Skip to content

CPack: Support component names with special characters, too

The cpack_add_component function from CPackComponent.cmake takes the name of a component and sets several variables for CPack. Those variables' names often contain the name of the given component.
However, that can lead to errors if such a component's name contains special characters as e.g. :.

Then again, it should be totally fine for a component's name to contain such characters.

And luckily, it seems to be quite simple to fix these errors in CPackComponent.cmake, which is what this merge-request does.


Some background information for better understanding the problem:

CMake supports several special characters (e.g. :) in variable names, as long as such a variable is never referenced directly:

set( VAR:WITH:SPECIAL:CHARACTERS "value" )
# message( STATUS "Direct reference = ${VAR:WITH:SPECIAL:CHARACTERS}" )  # ERROR!

set( INDIRECTION "VAR:WITH:SPECIAL:CHARACTERS" )
message( STATUS "Indirect reference = ${${INDIRECTION}}" )  # SUCCESS

Likewise, a macro which takes a variable var and references it to get its value (${${var}}) might trigger the same error if var contains special characters. Using a function instead does not trigger that error:

macro( print_var_and_val_macro arg )
    message( STATUS "${arg} = ${${arg}}" )
endmacro()
function( print_var_and_val_func arg )
    message( STATUS "${arg} = ${${arg}}" )
endfunction()

set( VAR:WITH:SPECIAL:CHARACTERS "value" )

# print_var_and_val_macro( VAR:WITH:SPECIAL:CHARACTERS )  # ERROR
print_var_and_val_func( VAR:WITH:SPECIAL:CHARACTERS )  # SUCCESS

Topic-rename: cpack-component-special-chars

Edited by Deniz Bahadir

Merge request reports