@@ -316,6 +316,9 @@ function(cpm_parse_add_package_single_arg arg outArgs)
316
316
elseif (scheme STREQUAL "bb" )
317
317
set (out "BITBUCKET_REPOSITORY;${uri} " )
318
318
set (packageType "git" )
319
+ elseif (scheme STREQUAL "rel" )
320
+ set (out "RELATIVE_REPOSITORY;${uri} " )
321
+ set (packageType "git" )
319
322
# A CPM-specific scheme was not found. Looks like this is a generic URL so try to determine
320
323
# type
321
324
elseif (arg MATCHES ".git/?(@|#|$)" )
@@ -365,11 +368,11 @@ function(cpm_parse_add_package_single_arg arg outArgs)
365
368
)
366
369
endfunction ()
367
370
371
+ find_package (Git REQUIRED)
372
+
368
373
# Check that the working directory for a git repo is clean
369
374
function (cpm_check_git_working_dir_is_clean repoPath gitTag isClean)
370
375
371
- find_package (Git REQUIRED)
372
-
373
376
if (NOT GIT_EXECUTABLE)
374
377
# No git executable, assume directory is clean
375
378
set (${isClean}
@@ -427,6 +430,48 @@ function(cpm_check_git_working_dir_is_clean repoPath gitTag isClean)
427
430
428
431
endfunction ()
429
432
433
+ # Convert a URI relative to that of the URL of the remote of our current Git repository
434
+ # e.g. github.com/user/repo.git + ../other.git = github.com/user/other.git
435
+ function (cpm_git_relative_uri_to_url relative_uri absolute_url)
436
+ if (NOT Git_FOUND)
437
+ message (SEND_ERROR "Git not found, cannot convert relative URI to absolute Git URL" )
438
+ return ()
439
+ endif ()
440
+
441
+ # Get the list of remotes available
442
+ execute_process (COMMAND ${GIT_EXECUTABLE} remote
443
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR} "
444
+ OUTPUT_VARIABLE remotes_names
445
+ OUTPUT_STRIP_TRAILING_WHITESPACE
446
+ ERROR_QUIET)
447
+
448
+ string (REPLACE "\n " ";" remotes_names_list ${remotes_names} )
449
+
450
+ list (LENGTH remotes_names_list remotes_count)
451
+
452
+ if (remotes_count EQUAL 0)
453
+ message (ERROR "Repository located at ${CMAKE_CURRENT_SOURCE_DIR} has no remote, cannot use relative URLs" )
454
+ return ()
455
+ endif ()
456
+
457
+ # Get the first remote
458
+ list (GET remotes_names_list 0 remote_name)
459
+
460
+ # Get the fetch URL of that remote
461
+ execute_process (COMMAND ${GIT_EXECUTABLE} remote get -url ${remote_name}
462
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR} "
463
+ OUTPUT_VARIABLE remote_url
464
+ OUTPUT_STRIP_TRAILING_WHITESPACE
465
+ ERROR_QUIET)
466
+
467
+ string (CONCAT absolute_url_local "${remote_url} " "/" "${relative_uri} " )
468
+
469
+ set (${absolute_url}
470
+ "${absolute_url_local} "
471
+ PARENT_SCOPE
472
+ )
473
+ endfunction ()
474
+
430
475
# Download and add a package from source
431
476
function (CPMAddPackage)
432
477
list (LENGTH ARGN argnLength)
@@ -446,6 +491,7 @@ function(CPMAddPackage)
446
491
GITHUB_REPOSITORY
447
492
GITLAB_REPOSITORY
448
493
BITBUCKET_REPOSITORY
494
+ RELATIVE_REPOSITORY
449
495
GIT_REPOSITORY
450
496
SOURCE_DIR
451
497
DOWNLOAD_COMMAND
@@ -480,6 +526,9 @@ function(CPMAddPackage)
480
526
set (CPM_ARGS_GIT_REPOSITORY "https://gitlab.com/${CPM_ARGS_GITLAB_REPOSITORY} .git" )
481
527
elseif (DEFINED CPM_ARGS_BITBUCKET_REPOSITORY)
482
528
set (CPM_ARGS_GIT_REPOSITORY "https://bitbucket.org/${CPM_ARGS_BITBUCKET_REPOSITORY} .git" )
529
+ elseif (DEFINED CPM_ARGS_RELATIVE_REPOSITORY)
530
+ cpm_git_relative_uri_to_url("${CPM_ARGS_RELATIVE_REPOSITORY} " absolute_git_url)
531
+ set (CPM_ARGS_GIT_REPOSITORY "${absolute_git_url} .git" )
483
532
endif ()
484
533
485
534
if (DEFINED CPM_ARGS_GIT_REPOSITORY)
0 commit comments