diff --git a/cmake/cmaize/globals.cmake b/cmake/cmaize/globals.cmake index ecf1870b..b6dbd759 100644 --- a/cmake/cmaize/globals.cmake +++ b/cmake/cmaize/globals.cmake @@ -10,6 +10,17 @@ cpp_set_global( "H;h;HPP;hpp;HXX;hxx;HH;hh" ) +#[[[ +# URL prefix for GitHub SSH access. Defaults to ``git@github.com``. +# This option allows for SSH aliases, e.g. ``git@github-alt-account`` +# where ``githut-alt-account` is a user-defined alias for GitHub +# SSH access defined in a user's $HOME/.ssh/config. +#]] +cpp_set_global( + CMAIZE_GITHUB_SSH_PREFIX + "git@github.com" +) + #[[[ # GitHub token used to access private repositories. It is defaulted to the # value of the old ``CPP_GITHUB_TOKEN`` for backwards compatability and @@ -20,6 +31,16 @@ cpp_set_global( "${CPP_GITHUB_TOKEN}" ) +#[[[ +# Use SSH access for private GitHub repositories toa void OAuth token +# requirements. See ``CMAIZE_GITHUB_SSH_PREFIX`` for details pertaining +# to chaging default GitHub SSH access prefixes. +#]] +cpp_set_global( + CMAIZE_GITHUB_USE_SSH + OFF +) + #[[[ # Current CMaize project. #]] diff --git a/cmake/cmaize/package_managers/cmake/dependency/github.cmake b/cmake/cmaize/package_managers/cmake/dependency/github.cmake index d15a7421..c88a2db6 100644 --- a/cmake/cmaize/package_managers/cmake/dependency/github.cmake +++ b/cmake/cmaize/package_managers/cmake/dependency/github.cmake @@ -37,6 +37,10 @@ cpp_class(GitHubDependency Dependency) GitHubDependency(GET "${_bd_this}" _bd_name name) GitHubDependency(GET "${_bd_this}" _bd_cmake_args cmake_args) + if( _bd_private AND CMAIZE_GITHUB_USE_SSH ) + string( REPLACE "github.com/" "${CMAIZE_GITHUB_SSH_PREFIX}:" _bd_url "${_bd_url}") + endif( ) + # TODO: In the future, this might need to be generalized more to # accommodate those who use multiple accounts with SSH keys # associated with them. In these situations, the string @@ -47,7 +51,7 @@ cpp_class(GitHubDependency Dependency) # REGEX MATCH below should do this, but the `cmaize_sanitize_url` # function also must be redesigned for these URLs to be allowed. # string(REGEX MATCH "^git@[A-Za-z0-9_-]:" _bd_is_ssh "${_bd_url}") - string(FIND "${_bd_url}" "git@github.com:" _bd_is_ssh) + string(FIND "${_bd_url}" "${CMAIZE_GITHUB_SSH_PREFIX}:" _bd_is_ssh) # Determine what type of URL to generate to access the repository if(_bd_is_ssh GREATER -1)