Nishikant
Nishikant

Reputation: 95

Set the <Package>_VERSION_MAJOR, <Package>_VERSION_MINOR

I have a simple find_package(pack 1.0.0 REQUIRED EXACT) in top level CMakeLists.txt Now, I want to give a specific format like MAJOR.MINOR.PATCH/TWEAK and set these variables using find_package. How can I do this? I read cmake documenatation about _MAJOR_VERSION etc but could not get an example or details on my specific scenario: https://cmake.org/cmake/help/latest/command/find_package.html#version-selection

Upvotes: 0

Views: 55

Answers (2)

usr1234567
usr1234567

Reputation: 23432

See FindJava.cmake from CMake itself. It contains code like

set(Java_VERSION_STRING "${CMAKE_MATCH_1}")
set(Java_VERSION_MAJOR "${CMAKE_MATCH_2}")
set(Java_VERSION_MINOR "${CMAKE_MATCH_4}")
set(Java_VERSION_PATCH "${CMAKE_MATCH_6}")
set(Java_VERSION_TWEAK "${CMAKE_MATCH_8}")

Upvotes: 0

usr1234567
usr1234567

Reputation: 23432

Use FindPackageHandleStandardArgs and pass your version after VERSION_VAR. See the documentation of FindPackageHandleStandardArgs.

Upvotes: 0

Related Questions