Skip to content

Commit e69427b

Browse files
authored
Merge pull request #91 from build-cpp/clang-condition
Fix the `clang` condition and CI improvements
2 parents 5a0eda7 + bc63598 commit e69427b

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ jobs:
4646
- name: Get lowercase OS name
4747
id: osname
4848
uses: ASzc/change-string-case-action@07c1e24a97f0951e13f88870b99c058fcf0b14cf # v5
49+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
4950
with:
5051
string: ${{ runner.os }}
5152

5253
- name: Compress artifacts
5354
uses: vimtor/action-zip@26a249fb00d43ca98dad77a4b3838025fc226aa1 # v1.1
55+
if: ${{ startsWith(github.ref, 'refs/tags/') }}
5456
with:
5557
files: install/bin/
5658
dest: ${{ github.event.repository.name }}-${{ steps.osname.outputs.lowercase }}.zip

docs/cmake-toml.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ unix = "UNIX"
7272
bsd = "CMAKE_SYSTEM_NAME MATCHES \"BSD\""
7373
linux = "CMAKE_SYSTEM_NAME MATCHES \"Linux\""
7474
gcc = "CMAKE_CXX_COMPILER_ID STREQUAL \"GNU\" OR CMAKE_C_COMPILER_ID STREQUAL \"GNU\""
75-
clang = "CMAKE_CXX_COMPILER_ID MATCHES \"Clang\" OR CMAKE_C_COMPILER_ID MATCHES \"Clang\""
75+
clang = "(CMAKE_CXX_COMPILER_ID MATCHES \"Clang\" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES \"^MSVC$\") OR (CMAKE_C_COMPILER_ID MATCHES \"Clang\" AND NOT CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES \"^MSVC$\")"
7676
msvc = "MSVC"
7777
root = "CMKR_ROOT_PROJECT"
7878
x64 = "CMAKE_SIZEOF_VOID_P EQUAL 8"
@@ -137,6 +137,7 @@ components = ["mycomponent"]
137137
condition = "mycondition"
138138
git = "https://github.com/myuser/gitcontent"
139139
tag = "v0.1"
140+
shallow = false
140141

141142
[fetch-content.svncontent]
142143
condition = "mycondition"
@@ -146,7 +147,10 @@ rev = "svn_rev"
146147
[fetch-content.urlcontent]
147148
condition = "mycondition"
148149
url = "https://content-host.com/urlcontent.zip"
149-
hash = "123123123123"
150+
# These are equivalent, supported algorithms:
151+
# md5, sha1, sha224, sha256, sha384, sha512, sha3_224, sha3_256, sha3_384, sha3_512
152+
hash = "SHA1 502a4e25b8b209889c99c7fa0732102682c2e4ff"
153+
sha1 = "502a4e25b8b209889c99c7fa0732102682c2e4ff"
150154
```
151155

152156
## Targets

include/project_parser.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ struct Project {
199199

200200
Project(const Project *parent, const std::string &path, bool build);
201201
const Project *root() const;
202+
bool cmake_minimum_version(int major, int minor) const;
202203
};
203204

204205
bool is_root_path(const std::string &path);

src/project_parser.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ Project::Project(const Project *parent, const std::string &path, bool build) : p
265265
conditions["bsd"] = R"cmake(CMAKE_SYSTEM_NAME MATCHES "BSD")cmake";
266266
conditions["linux"] = conditions["lunix"] = R"cmake(CMAKE_SYSTEM_NAME MATCHES "Linux")cmake";
267267
conditions["gcc"] = R"cmake(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "GNU")cmake";
268-
conditions["clang"] = R"cmake(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_C_COMPILER_ID MATCHES "Clang")cmake";
268+
conditions["clang"] =
269+
R"cmake((CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_CXX_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$") OR (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_C_COMPILER_FRONTEND_VARIANT MATCHES "^MSVC$"))cmake";
269270
conditions["msvc"] = R"cmake(MSVC)cmake";
270271
conditions["root"] = R"cmake(CMKR_ROOT_PROJECT)cmake";
271272
conditions["x64"] = R"cmake(CMAKE_SIZEOF_VOID_P EQUAL 8)cmake";
@@ -741,6 +742,26 @@ const Project *Project::root() const {
741742
return root;
742743
}
743744

745+
bool Project::cmake_minimum_version(int major, int minor) const {
746+
// NOTE: this code is like pulling teeth, sorry
747+
auto root_version = root()->cmake_version;
748+
puts(root_version.c_str());
749+
auto range_index = root_version.find("...");
750+
if (range_index != std::string::npos) {
751+
root_version.resize(range_index);
752+
}
753+
754+
auto period_index = root_version.find('.');
755+
auto root_major = atoi(root_version.substr(0, period_index).c_str());
756+
int root_minor = 0;
757+
if (period_index != std::string::npos) {
758+
auto end_index = root_version.find('.', period_index + 1);
759+
root_minor = atoi(root_version.substr(period_index + 1, end_index).c_str());
760+
}
761+
762+
return std::tie(root_major, root_minor) >= std::tie(major, minor);
763+
}
764+
744765
bool is_root_path(const std::string &path) {
745766
const auto toml_path = fs::path(path) / "cmake.toml";
746767
if (!fs::exists(toml_path)) {

0 commit comments

Comments
 (0)