Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vcpkg_find_acquire_program] add version check for ninja #12895

Merged
merged 9 commits into from
Aug 16, 2020
37 changes: 33 additions & 4 deletions scripts/cmake/vcpkg_find_acquire_program.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ function(vcpkg_find_acquire_program VAR)
set(HASH f73b04e2d9f29d4393fde572dcf3c3f0f6fa27e747e5df292294ab7536ae24c239bf917689d71eb10cc49f6b9a4ace26d7c122ee887d93cc935f268c404e9067)
elseif(VAR MATCHES "NINJA")
set(PROGNAME ninja)
set(SUBDIR "ninja-1.10.0")
set(NINJA_VERSION 1.10.0)
set(SUBDIR "ninja-${VERSION}")
if(CMAKE_HOST_WIN32)
set(PATHS "${DOWNLOADS}/tools/${SUBDIR}-windows")
list(APPEND PATHS "${DOWNLOADS}/tools/ninja/${SUBDIR}")
Expand All @@ -218,9 +219,10 @@ function(vcpkg_find_acquire_program VAR)
endif()
set(BREW_PACKAGE_NAME "ninja")
set(APT_PACKAGE_NAME "ninja-build")
Neumann-A marked this conversation as resolved.
Show resolved Hide resolved
set(URL "https:/ninja-build/ninja/releases/download/v1.10.0/ninja-win.zip")
set(ARCHIVE "ninja-win-1.10.0.zip")
set(URL "https:/ninja-build/ninja/releases/download/v${NINJA_VERSION}/ninja-win.zip")
set(ARCHIVE "ninja-win-${NINJA_VERSION}.zip")
set(HASH a196e243c53daa1df9d287af658d6d38d6b830b614f2d5704e8c88ffc61f179a533ae71cdb6d0d383d1559d65dacccbaaab270fb2a33aa211e5dba42ff046f97)
set(VERSION_CMD --version)
elseif(VAR MATCHES "NUGET")
set(PROGNAME nuget)
set(SUBDIR "5.5.1")
Expand Down Expand Up @@ -379,10 +381,37 @@ function(vcpkg_find_acquire_program VAR)
message(FATAL "unknown tool ${VAR} -- unable to acquire.")
endif()

macro(do_version_check)
if(VERSION_CMD)
_execute_process(
COMMAND ${VAR} ${VERSION_CMD}
WORKING_DIRECTORY ${DOWNLOADS}
OUTPUT_VARIABLE ${VAR}_VERSION_OUTPUT
)
string(STRIP "${${VAR}_VERSION_OUTPUT}" ${VAR}_VERSION_OUTPUT)
#TODO: REGEX MATCH case for more complex cases!
if(NOT ${VAR}_VERSION_OUTPUT VERSION_GREATER_EQUAL VERSION)
message(STATUS "Found ${PROGNAME}('${${VAR}_VERSION_OUTPUT}') but at least version ${VERSION} is required! Trying to use internal version if possible!")
Neumann-A marked this conversation as resolved.
Show resolved Hide resolved
set(${VAR} "${VAR}-NOTFOUND")
set(${VAR} "${VAR}-NOTFOUND" CACHE INTERNAL "")
else()
message(STATUS "Found external ${PROGNAME}('${${VAR}_VERSION_OUTPUT}').")
endif()
endif()
endmacro()

macro(do_find)
if(NOT DEFINED REQUIRED_INTERPRETER)
find_program(${VAR} ${PROGNAME} PATHS ${PATHS} NO_DEFAULT_PATH)
find_program(${VAR} ${PROGNAME})
if(NOT ${VAR})
find_program(${VAR} ${PROGNAME})
if(${VAR} AND NOT ${VAR}_VERSION_CHECKED)
do_version_check()
set(${VAR}_VERSION_CHECKED ON)
elseif(${VAR}_VERSION_CHECKED)
message(FATAL_ERROR "Unable to find ${PROGNAME} with min version of ${${VAR}_VERSION}")
endif()
endif()
else()
vcpkg_find_acquire_program(${REQUIRED_INTERPRETER})
find_file(SCRIPT_${VAR} ${SCRIPTNAME} PATHS ${PATHS} NO_DEFAULT_PATH)
Expand Down