Skip to content

Commit 369f131

Browse files
inkychrisChris WrightTheLartians
authored
Treat relative paths as relative to parent project's remote (#522)
* Treat relative paths as relative to parent project's remote * replace unit test case with integration test * run relative URL test only on supported CMake versions (3.27) * omit cmake 2.25.x test runner as replaced by 2.27.x --------- Co-authored-by: Chris Wright <[email protected]> Co-authored-by: Lars Melchior <[email protected]>
1 parent a9c8c6f commit 369f131

File tree

5 files changed

+26
-2
lines changed

5 files changed

+26
-2
lines changed

Diff for: .github/workflows/style.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup cmake
2020
uses: jwlawson/[email protected]
2121
with:
22-
cmake-version: '3.25.x'
22+
cmake-version: '3.27.x'
2323

2424
- name: Install format dependencies
2525
run: pip3 install clang-format==14.0.6 cmake_format==0.6.11 pyyaml

Diff for: .github/workflows/test.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
os: [ubuntu-latest, windows-2022, macos-latest]
2020
# we want to ensure compatibility with a recent CMake version as well as the lowest officially supported
2121
# legacy version that we define as the default version of the second-latest Ubuntu LTS release currently available
22-
cmake_version: ['3.16.3', '3.25.1']
22+
cmake_version: ['3.16.3', '3.27.5']
2323
exclude:
2424
# there seems to be an issue with CMake 3.16 not finding a C++ compiler on windows-2022
2525
- os: windows-2022

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ Dependencies using CPM will automatically use the updated script of the outermos
142142
- **Some CMake policies set to `NEW`** Including CPM.cmake will lead to several CMake policies being set to `NEW`. Users which need the old behavior will need to manually modify their CMake code to ensure they're set to `OLD` at the appropriate places. The policies are:
143143
- [CMP0077](https://cmake.org/cmake/help/latest/policy/CMP0077.html) and [CMP0126](https://cmake.org/cmake/help/latest/policy/CMP0126.html). They make setting package options from `CMPAddPackage` possible.
144144
- [CMP0135](https://cmake.org/cmake/help/latest/policy/CMP0135.html) It allows for proper package rebuilds of packages which are archives, source cache is not used, and the package URL is changed to an older version.
145+
- [CMP0150](https://cmake.org/cmake/help/latest/policy/CMP0150.html) Relative paths provided to `GIT_REPOSITORY` are treated as relative to the parent project's remote.
145146

146147
For projects with more complex needs and where an extra setup step doesn't matter, it may be worth to check out an external C++ package manager such as [vcpkg](https://github.com/microsoft/vcpkg), [conan](https://conan.io) or [hunter](https://github.com/ruslo/hunter).
147148
Dependencies added with `CPMFindPackage` should work with external package managers.

Diff for: cmake/CPM.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ macro(cpm_set_policies)
9999
cmake_policy(SET CMP0135 NEW)
100100
set(CMAKE_POLICY_DEFAULT_CMP0135 NEW)
101101
endif()
102+
103+
# treat relative git repository paths as being relative to the parent project's remote
104+
if(POLICY CMP0150)
105+
cmake_policy(SET CMP0150 NEW)
106+
set(CMAKE_POLICY_DEFAULT_CMP0150 NEW)
107+
endif()
102108
endmacro()
103109
cpm_set_policies()
104110

Diff for: test/integration/test_relative_urls.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require_relative './lib'
2+
3+
class RelativeURLs < IntegrationTest
4+
def setup
5+
# relative URLs were introduced in CMake 3.27
6+
@relative_urls_supported = (!ENV['CMAKE_VERSION']) || (Gem::Version.new(ENV['CMAKE_VERSION']) >= Gem::Version.new('3.27'))
7+
end
8+
9+
def test_add_project_with_relative_urls
10+
omit_if !@relative_urls_supported do
11+
prj = make_project from_template: 'using-fibadder'
12+
prj.create_lists_from_default_template package: 'CPMAddPackage("gh:cpm-cmake/[email protected]")'
13+
assert_success prj.configure
14+
assert_success prj.build
15+
end
16+
end
17+
end

0 commit comments

Comments
 (0)