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
50 changes: 44 additions & 6 deletions scripts/cmake/vcpkg_find_acquire_program.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,31 @@ 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-${NINJA_VERSION}")
if(CMAKE_HOST_WIN32)
set(ARCHIVE "ninja-win-${NINJA_VERSION}.zip")
set(PATHS "${DOWNLOADS}/tools/${SUBDIR}-windows")
list(APPEND PATHS "${DOWNLOADS}/tools/ninja/${SUBDIR}")
set(URL "https://github.com/ninja-build/ninja/releases/download/v${NINJA_VERSION}/ninja-win.zip")
set(HASH a196e243c53daa1df9d287af658d6d38d6b830b614f2d5704e8c88ffc61f179a533ae71cdb6d0d383d1559d65dacccbaaab270fb2a33aa211e5dba42ff046f97)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
set(ARCHIVE "ninja-mac-${NINJA_VERSION}.zip")
set(URL "https://github.com/ninja-build/ninja/releases/download/v${NINJA_VERSION}/ninja-mac.zip")
set(PATHS "${DOWNLOADS}/tools/${SUBDIR}-osx")
set(HASH 619a1924067a0b30fc5f8887f868d3ee5481838d2f0f158d031f7614a2a10b95a73d4a56b658d5d560283ebf809e2e536b968c6c01ff0108075c3f393f5780ba)
elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "FreeBSD")
set(PATHS "${DOWNLOADS}/tools/${SUBDIR}-freebsd")
else()
set(ARCHIVE "ninja-linux-${NINJA_VERSION}.zip")
set(URL "https://github.com/ninja-build/ninja/releases/download/v${NINJA_VERSION}/ninja-linux.zip")
set(PATHS "${DOWNLOADS}/tools/${SUBDIR}-linux")
set(HASH ffb179ab8ea315167fcc99a8f13286e1363590185b18cf819cc73e09f2a7553790e9dc45fd1ccd0bd1d2dbf543aee3f6c0951cf9ce453a7168ffd2ac873cdd29)
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://github.com/ninja-build/ninja/releases/download/v1.10.0/ninja-win.zip")
set(ARCHIVE "ninja-win-1.10.0.zip")
set(HASH a196e243c53daa1df9d287af658d6d38d6b830b614f2d5704e8c88ffc61f179a533ae71cdb6d0d383d1559d65dacccbaaab270fb2a33aa211e5dba42ff046f97)
set(VERSION_CMD --version)
set(_vfa_SUPPORTED ON)
Neumann-A marked this conversation as resolved.
Show resolved Hide resolved
elseif(VAR MATCHES "NUGET")
set(PROGNAME nuget)
set(SUBDIR "5.5.1")
Expand Down Expand Up @@ -379,10 +388,36 @@ 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 ${VAR}_VERSION)
message(STATUS "Found ${PROGNAME}('${${VAR}_VERSION_OUTPUT}') but at least version ${${VAR}_VERSION} is required! Trying to use internal version if possible!")
Copy link
Contributor

Choose a reason for hiding this comment

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

If we ask for the lowest version but do not match, there may be a problem when using the lower version of the tool in the system.
Related: #18955 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is a VERSION_GREATER_EQUAL check. So if meson on the system is equal or greater it will be used. Otherwise it should use the vcpkg version. This is the same logic vcpkg applies to cmake. If the system CMake version is greater or equal to the minimum set by vcpkg it will be used. Otherwise vcpkg will download its own cmake.

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 Expand Up @@ -456,8 +491,11 @@ function(vcpkg_find_acquire_program VAR)
LOGNAME ${VAR}-tool-post-install
)
endif()

unset(${VAR} CACHE)
do_find()
if(NOT ${VAR})
message(FATAL_ERROR "Unable to find ${VAR}")
endif()
endif()

set(${VAR} "${${VAR}}" PARENT_SCOPE)
Expand Down
2 changes: 1 addition & 1 deletion scripts/cmake/vcpkg_find_fortran.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function(vcpkg_find_fortran additional_cmake_args_out)
else()
message(FATAL_ERROR "Unknown architecture '${VCPKG_TARGET_ARCHITECTURE}' for MinGW Fortran build!")
endif()
vcpkg_acquire_msys(MSYS_ROOT "mingw-w64-${MSYS_TARGET}-gcc-fortran")
vcpkg_acquire_msys(MSYS_ROOT PACKAGES "mingw-w64-${MSYS_TARGET}-gcc-fortran")
set(MINGW_BIN "${MSYS_ROOT}/${MINGW_PATH}/bin")
vcpkg_add_to_path(PREPEND "${MINGW_BIN}")
list(APPEND ARGS_OUT -DCMAKE_GNUtoMS=ON
Expand Down