Sort version strings in CMake












0















I am converting a qmake project to cmake, and I am able to get it work, except the part that equivalent to !versionAtLeast(QT_VERSION, 5.11): error("Use at least Qt version 5.11".



The issue here is that I am currently using a user-supplied variable -DQt5_PREFIX=/path/to/Qt5/prefix to inform CMake the location of the Qt libs. In macOS, this is /Applications/Qt5/5.xx.x/clang_64 by default.



What I would like to achieve in my cmake scripts is a function that works as the following:



set(Qt_ROOT "/Applications/Qt")
GetQt5Prefix(Qt5_PREFIX ${Qt_ROOT} version_spec)
message("use Qt5 from ${Qt5_PREFIX}")

# suppose that in /Applications/Qt,
# I have three Qt: 5.11.2, 5.10.3 5.12.1
# the above will print "use Qt5 from"
# 5.12.1 if version_spec is 5
# 5.11.2 if version_spec is 5.11
# empty if version_spec is 5.10.1


From what I've got so far, I would image this function should do




  1. glob to find all subdirectories that looks like version string within Qt5_ROOT

  2. sort the directories according to the version strings (also dir names), this probably involves to parse the string to major, minor and patch.

  3. compare the parsed version strings with version_spec to get the requested version

  4. set the output variable


Could anyone help on any of the above 1, 2, or 3? Thank you!










share|improve this question


















  • 1





    What is wrong in using find_package(QT5 5.11 REQUIRED) when search for QT? Such way CMake will emit an error if version of QT5 is too small.

    – Tsyvarev
    Jan 1 at 9:54











  • The problem is that to make find_package work, one has to add the Qt folder, whose name is the version string such as "5.11.2" within ${QT_ROOT}, to CMAKE_PREFIX_PATH. Therefore, specifications such as 5.11 in find_package does not make sense because one has to specify the exact full version string to locate the exact Qt lib. What I am trying to do is only specify Qt_ROOT, and let cmake look into the directory, select the correct subdirectory (i.e., the exact version) according to the version specification, e.g., 5 or 5.11, or 5.11.2

    – Jerry Ma
    Jan 3 at 4:12
















0















I am converting a qmake project to cmake, and I am able to get it work, except the part that equivalent to !versionAtLeast(QT_VERSION, 5.11): error("Use at least Qt version 5.11".



The issue here is that I am currently using a user-supplied variable -DQt5_PREFIX=/path/to/Qt5/prefix to inform CMake the location of the Qt libs. In macOS, this is /Applications/Qt5/5.xx.x/clang_64 by default.



What I would like to achieve in my cmake scripts is a function that works as the following:



set(Qt_ROOT "/Applications/Qt")
GetQt5Prefix(Qt5_PREFIX ${Qt_ROOT} version_spec)
message("use Qt5 from ${Qt5_PREFIX}")

# suppose that in /Applications/Qt,
# I have three Qt: 5.11.2, 5.10.3 5.12.1
# the above will print "use Qt5 from"
# 5.12.1 if version_spec is 5
# 5.11.2 if version_spec is 5.11
# empty if version_spec is 5.10.1


From what I've got so far, I would image this function should do




  1. glob to find all subdirectories that looks like version string within Qt5_ROOT

  2. sort the directories according to the version strings (also dir names), this probably involves to parse the string to major, minor and patch.

  3. compare the parsed version strings with version_spec to get the requested version

  4. set the output variable


Could anyone help on any of the above 1, 2, or 3? Thank you!










share|improve this question


















  • 1





    What is wrong in using find_package(QT5 5.11 REQUIRED) when search for QT? Such way CMake will emit an error if version of QT5 is too small.

    – Tsyvarev
    Jan 1 at 9:54











  • The problem is that to make find_package work, one has to add the Qt folder, whose name is the version string such as "5.11.2" within ${QT_ROOT}, to CMAKE_PREFIX_PATH. Therefore, specifications such as 5.11 in find_package does not make sense because one has to specify the exact full version string to locate the exact Qt lib. What I am trying to do is only specify Qt_ROOT, and let cmake look into the directory, select the correct subdirectory (i.e., the exact version) according to the version specification, e.g., 5 or 5.11, or 5.11.2

    – Jerry Ma
    Jan 3 at 4:12














0












0








0








I am converting a qmake project to cmake, and I am able to get it work, except the part that equivalent to !versionAtLeast(QT_VERSION, 5.11): error("Use at least Qt version 5.11".



The issue here is that I am currently using a user-supplied variable -DQt5_PREFIX=/path/to/Qt5/prefix to inform CMake the location of the Qt libs. In macOS, this is /Applications/Qt5/5.xx.x/clang_64 by default.



What I would like to achieve in my cmake scripts is a function that works as the following:



set(Qt_ROOT "/Applications/Qt")
GetQt5Prefix(Qt5_PREFIX ${Qt_ROOT} version_spec)
message("use Qt5 from ${Qt5_PREFIX}")

# suppose that in /Applications/Qt,
# I have three Qt: 5.11.2, 5.10.3 5.12.1
# the above will print "use Qt5 from"
# 5.12.1 if version_spec is 5
# 5.11.2 if version_spec is 5.11
# empty if version_spec is 5.10.1


From what I've got so far, I would image this function should do




  1. glob to find all subdirectories that looks like version string within Qt5_ROOT

  2. sort the directories according to the version strings (also dir names), this probably involves to parse the string to major, minor and patch.

  3. compare the parsed version strings with version_spec to get the requested version

  4. set the output variable


Could anyone help on any of the above 1, 2, or 3? Thank you!










share|improve this question














I am converting a qmake project to cmake, and I am able to get it work, except the part that equivalent to !versionAtLeast(QT_VERSION, 5.11): error("Use at least Qt version 5.11".



The issue here is that I am currently using a user-supplied variable -DQt5_PREFIX=/path/to/Qt5/prefix to inform CMake the location of the Qt libs. In macOS, this is /Applications/Qt5/5.xx.x/clang_64 by default.



What I would like to achieve in my cmake scripts is a function that works as the following:



set(Qt_ROOT "/Applications/Qt")
GetQt5Prefix(Qt5_PREFIX ${Qt_ROOT} version_spec)
message("use Qt5 from ${Qt5_PREFIX}")

# suppose that in /Applications/Qt,
# I have three Qt: 5.11.2, 5.10.3 5.12.1
# the above will print "use Qt5 from"
# 5.12.1 if version_spec is 5
# 5.11.2 if version_spec is 5.11
# empty if version_spec is 5.10.1


From what I've got so far, I would image this function should do




  1. glob to find all subdirectories that looks like version string within Qt5_ROOT

  2. sort the directories according to the version strings (also dir names), this probably involves to parse the string to major, minor and patch.

  3. compare the parsed version strings with version_spec to get the requested version

  4. set the output variable


Could anyone help on any of the above 1, 2, or 3? Thank you!







cmake qmake






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Jan 1 at 4:16









Jerry MaJerry Ma

14610




14610








  • 1





    What is wrong in using find_package(QT5 5.11 REQUIRED) when search for QT? Such way CMake will emit an error if version of QT5 is too small.

    – Tsyvarev
    Jan 1 at 9:54











  • The problem is that to make find_package work, one has to add the Qt folder, whose name is the version string such as "5.11.2" within ${QT_ROOT}, to CMAKE_PREFIX_PATH. Therefore, specifications such as 5.11 in find_package does not make sense because one has to specify the exact full version string to locate the exact Qt lib. What I am trying to do is only specify Qt_ROOT, and let cmake look into the directory, select the correct subdirectory (i.e., the exact version) according to the version specification, e.g., 5 or 5.11, or 5.11.2

    – Jerry Ma
    Jan 3 at 4:12














  • 1





    What is wrong in using find_package(QT5 5.11 REQUIRED) when search for QT? Such way CMake will emit an error if version of QT5 is too small.

    – Tsyvarev
    Jan 1 at 9:54











  • The problem is that to make find_package work, one has to add the Qt folder, whose name is the version string such as "5.11.2" within ${QT_ROOT}, to CMAKE_PREFIX_PATH. Therefore, specifications such as 5.11 in find_package does not make sense because one has to specify the exact full version string to locate the exact Qt lib. What I am trying to do is only specify Qt_ROOT, and let cmake look into the directory, select the correct subdirectory (i.e., the exact version) according to the version specification, e.g., 5 or 5.11, or 5.11.2

    – Jerry Ma
    Jan 3 at 4:12








1




1





What is wrong in using find_package(QT5 5.11 REQUIRED) when search for QT? Such way CMake will emit an error if version of QT5 is too small.

– Tsyvarev
Jan 1 at 9:54





What is wrong in using find_package(QT5 5.11 REQUIRED) when search for QT? Such way CMake will emit an error if version of QT5 is too small.

– Tsyvarev
Jan 1 at 9:54













The problem is that to make find_package work, one has to add the Qt folder, whose name is the version string such as "5.11.2" within ${QT_ROOT}, to CMAKE_PREFIX_PATH. Therefore, specifications such as 5.11 in find_package does not make sense because one has to specify the exact full version string to locate the exact Qt lib. What I am trying to do is only specify Qt_ROOT, and let cmake look into the directory, select the correct subdirectory (i.e., the exact version) according to the version specification, e.g., 5 or 5.11, or 5.11.2

– Jerry Ma
Jan 3 at 4:12





The problem is that to make find_package work, one has to add the Qt folder, whose name is the version string such as "5.11.2" within ${QT_ROOT}, to CMAKE_PREFIX_PATH. Therefore, specifications such as 5.11 in find_package does not make sense because one has to specify the exact full version string to locate the exact Qt lib. What I am trying to do is only specify Qt_ROOT, and let cmake look into the directory, select the correct subdirectory (i.e., the exact version) according to the version specification, e.g., 5 or 5.11, or 5.11.2

– Jerry Ma
Jan 3 at 4:12












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992971%2fsort-version-strings-in-cmake%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53992971%2fsort-version-strings-in-cmake%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

Npm cannot find a required file even through it is in the searched directory