Skip to content

Backport for 5.0.7#2785

Merged
Rot127 merged 1 commit intocapstone-engine:v5from
scribam:v5-backport-cmake-fix
Sep 22, 2025
Merged

Backport for 5.0.7#2785
Rot127 merged 1 commit intocapstone-engine:v5from
scribam:v5-backport-cmake-fix

Conversation

@scribam
Copy link
Copy Markdown

@scribam scribam commented Sep 13, 2025

GitHub Actions has started to roll out CMake 4 so projects using capstone will be hit by this issue #2778 and build workflows will fail.

Hence, I would like to have the fix (f557fa2) added to the v5 branch ASAP and a new tag created (5.0.7) so people can upgrade and avoid build issues.

@KhoraLee
Copy link
Copy Markdown

This commit doesn’t actually fix the root cause. It ends up leaving capstone VERSION empty, which triggers a CMake warning:

-- PROJECT_VERSION:  CAPSTONE_VERSION: 
CMake Warning at external/capstone/CMakeLists.txt:40 (project):
  VERSION keyword not followed by a value or was followed by a value that
  expanded to nothing.

What we need instead is to handle the case where PROJECT_VERSION is an empty string and set value. The next 6.0.0 alpha branch shows the intended behavior:
https://github.com/capstone-engine/capstone/blob/next/CMakeLists.txt#L23

With that in place, the following change shouldn’t be necessary anymore: f557fa2

@scribam
Copy link
Copy Markdown
Author

scribam commented Sep 14, 2025

PR updated with the CMakeLists.txt change from ebe3ef2

@Rot127 Rot127 requested review from jiegec and wargio September 14, 2025 12:15
@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Sep 14, 2025

cc @AndrewQuijano

@Zangetsu38
Copy link
Copy Markdown
Contributor

This commit doesn’t actually fix the root cause. It ends up leaving capstone VERSION empty, which triggers a CMake warning:

-- PROJECT_VERSION:  CAPSTONE_VERSION: 
CMake Warning at external/capstone/CMakeLists.txt:40 (project):
  VERSION keyword not followed by a value or was followed by a value that
  expanded to nothing.

What we need instead is to handle the case where PROJECT_VERSION is an empty string and set value. The next 6.0.0 alpha branch shows the intended behavior: https://github.com/capstone-engine/capstone/blob/next/CMakeLists.txt#L23

With that in place, the following change shouldn’t be necessary anymore: f557fa2

My commit is obligatory for get works in old cmd, it no reconize argument without "..."
Both change is request for good works

@KhoraLee
Copy link
Copy Markdown

KhoraLee commented Sep 15, 2025

It happened because PROJECT_VERSION was defined but set to an empty string. Since we now handle both the undefined and empty string cases when setting PROJECT_VERSION, this issue should no longer occur

@Zangetsu38
Copy link
Copy Markdown
Contributor

Zangetsu38 commented Sep 15, 2025

It happened because PROJECT_VERSION was defined but set to an empty string. Since we now handle both the undefined and empty string cases when setting PROJECT_VERSION, this issue should no longer occur

Should works yes, but keep need " " for correct passe full argument of version in regex match

for more info:
In CMake, quotes are required when expanding variables like ${PROJECT_VERSION} in commands such as string(REGEX MATCH ...).

Without quotes:

string(REGEX MATCH "^[vV]?([0-9]+\.[0-9]+\.[0-9]+)" _ ${PROJECT_VERSION})

If PROJECT_VERSION is 6.0.0, CMake expands this to:

string(REGEX MATCH "^[vV]?([0-9]+\.[0-9]+\.[0-9]+)" _ 6.0.0)

CMake interprets 6.0.0 as three separate arguments (6, 0, 0) instead of a single string.
This breaks the command.

With quotes:

string(REGEX MATCH "^[vV]?([0-9]+\.[0-9]+\.[0-9]+)" _ "${PROJECT_VERSION}")

The value is passed as one single string ("6.0.0"), and the regex works correctly.

So while the logic for handling undefined or empty variables avoids the “empty string” issue, quotes are still required to prevent argument splitting when the variable contains dots, spaces, or other special characters.

@KhoraLee
Copy link
Copy Markdown

In CMake, arguments are split by whitespace and by semicolons (list separators), not by dots. So it does not become three arguments 6 0 0.

6.0.0 is a single unquoted token, so this works fine.

You can try

cmake_minimum_required(VERSION 3.15)

if(NOT DEFINED PROJECT_VERSION OR PROJECT_VERSION STREQUAL "")
    set(PROJECT_VERSION "5.0.6")
endif()

string(REGEX MATCH "^[vV]?([0-9]+\\.[0-9]+\\.[0-9]+)" _ ${PROJECT_VERSION})
if(CMAKE_MATCH_1 STREQUAL "")
    message(FATAL_ERROR "Could not extract version from ${PROJECT_VERSION}")
endif()

message("Matched string: ${CMAKE_MATCH_1}")

string(REGEX MATCH "^[vV]?([0-9]+\\.[0-9]+\\.[0-9]+)" _ 6.0.0)
message("Matched string: ${CMAKE_MATCH_1}")

and this and it results in :

Matched string: 5.0.6
Matched string: 6.0.0

@Rot127 Rot127 requested a review from kabeor September 15, 2025 12:57
@Zangetsu38
Copy link
Copy Markdown
Contributor

Zangetsu38 commented Sep 16, 2025

In CMake, arguments are split by whitespace and by semicolons (list separators), not by dots. So it does not become three arguments 6 0 0.

6.0.0 is a single unquoted token, so this works fine.

You can try

cmake_minimum_required(VERSION 3.15)

if(NOT DEFINED PROJECT_VERSION OR PROJECT_VERSION STREQUAL "")
    set(PROJECT_VERSION "5.0.6")
endif()

string(REGEX MATCH "^[vV]?([0-9]+\\.[0-9]+\\.[0-9]+)" _ ${PROJECT_VERSION})
if(CMAKE_MATCH_1 STREQUAL "")
    message(FATAL_ERROR "Could not extract version from ${PROJECT_VERSION}")
endif()

message("Matched string: ${CMAKE_MATCH_1}")

string(REGEX MATCH "^[vV]?([0-9]+\\.[0-9]+\\.[0-9]+)" _ 6.0.0)
message("Matched string: ${CMAKE_MATCH_1}")

and this and it results in :

Matched string: 5.0.6
Matched string: 6.0.0

i have open my pr and and fixed issue litterlay because with also adding (OR PROJECT_VERSION STREQUAL "")
already present in next branch, i no success compiled, and after search i have see, both if request, if only adding my code, generating works, but it no success get version, need both for max compatbility and preccision

in match, argument request " "
481367398-43444405-0f5b-49f8-98f3-5ef57835aee2

Copy link
Copy Markdown
Collaborator

@Rot127 Rot127 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Zangetsu38 What is your cmake version?

@Zangetsu38
Copy link
Copy Markdown
Contributor

@Zangetsu38 What is your cmake version?

i have updated again, so here works fine, but during particular inside build and cmake version, if using old cmd, it request obloigatory " " on argument in regex for works

@Zangetsu38
Copy link
Copy Markdown
Contributor

also,j change on seqtral is from here
ebe3ef2#diff-1e7de1ae2d059d21e1dd75d5812d5a34b0222cef273b7c3a2af62eb747f9d20a

is better take commit with original author i thinks, same for my commit

@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Sep 17, 2025

i have updated again, so here works fine, but during particular inside build and cmake version, if using old cmd, it request obloigatory " " on argument in regex for works

This is ok. But what is your cmake version? We need to bump the minimum required version in the build files.

If we know your version it is easier to find the exact version the behavior changes.

@Zangetsu38
Copy link
Copy Markdown
Contributor

Zangetsu38 commented Sep 18, 2025

i have updated again, so here works fine, but during particular inside build and cmake version, if using old cmd, it request obloigatory " " on argument in regex for works

This is ok. But what is your cmake version? We need to bump the minimum required version in the build files.

If we know your version it is easier to find the exact version the behavior changes.

here i have just last version, or recent, 4.1.1, but i no remmember for preview have get issue

@Rot127 Rot127 merged commit cd6dd7b into capstone-engine:v5 Sep 22, 2025
16 checks passed
@Rot127
Copy link
Copy Markdown
Collaborator

Rot127 commented Sep 22, 2025

@Zangetsu38 Please check if you maybe run into the https://cmake.org/cmake/help/latest/policy/CMP0054.html behavior.

@scribam scribam deleted the v5-backport-cmake-fix branch September 22, 2025 11:40
@Zangetsu38
Copy link
Copy Markdown
Contributor

@Zangetsu38 Please check if you maybe run into the https://cmake.org/cmake/help/latest/policy/CMP0054.html behavior.

Thanks for the hint! In my case it was not related to CMP0054 and if().
The problem came from using string(REGEX MATCH ...) without quotes around ${PROJECT_VERSION}.
Adding the quotes fixed it, since otherwise CMake splits 6.0.0 into 6 0 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants