diff --git a/cmake/modules/SanitizeHelper.cmake b/cmake/modules/SanitizeHelper.cmake --- a/cmake/modules/SanitizeHelper.cmake +++ b/cmake/modules/SanitizeHelper.cmake @@ -30,3 +30,11 @@ # `ISO C99 requires whitespace after the macro name [-Wc99-extensions]` _sanitize("([^a-zA-Z0-9_])" "_" "${PREFIX}${RAW_VAR}" ${SANITIZED_VAR}) endmacro() + +# Sanitize a variable intended to be used as a cmake target name. +macro(sanitize_target_name PREFIX RAW_VAR SANITIZED_VAR) + # Only allow for alphanum chars plus underscore. This will prevent the + # compiler to issue a warning like: + # `ISO C99 requires whitespace after the macro name [-Wc99-extensions]` + _sanitize("([^a-zA-Z0-9_])" "_" "${PREFIX}${RAW_VAR}" ${SANITIZED_VAR}) +endmacro() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -25,14 +25,18 @@ ### # Setup symlinks for testing ### -macro(make_link src dest) +include(SanitizeHelper) +function(make_link src dest) add_custom_command( OUTPUT "${dest}" COMMAND ${CMAKE_COMMAND} -E create_symlink "${src}" "${dest}" COMMENT "make_link ${src} -> ${dest}" MAIN_DEPENDENCY "${src}" ) -endmacro() + # Add a phony target to make sure the files are linked by default. + sanitize_target_name("link-" "${dest}" NAME) + add_custom_target(${NAME} ALL DEPENDS "${dest}") +endfunction() file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/functional/) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/util/)