forked from git/git
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add nuget_install() in cmake/NuGet.cmake
This function downloads nuget.exe to out_dir/nuget if necessary and installs the passed-in NuGet package to that directory. If the package contains a tools/bin directory, it is added to CMAKE_PROGRAM_PATH for find_program() to find any utilities. Add the supporting function file_download() to cmake/Utilities.cmake, which is a wrapper for the cmake file(DOWNLOAD ...) that takes a REQUIRED parameter to throw a fatal error if there are any problems. Signed-off-by: Rafael Kitover <[email protected]>
- Loading branch information
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
include(Utilities) | ||
|
||
# | ||
# nuget_install([pkg_name] [QUIET]) | ||
# | ||
# Installs nuget.exe in the output directory if not already present | ||
# and uses it to install pkg_name if provided. | ||
# | ||
# If the package contains a 'tools/bin' directory, it will be | ||
# appended to CMAKE_PROGRAM_PATH. | ||
# | ||
# With the QUIET option, no status messages will be printed. | ||
# | ||
# Throws a fatal error if any problems are encountered. | ||
# | ||
function(nuget_install pkg) | ||
if(ARGV1 STREQUAL QUIET) | ||
set(quiet TRUE) | ||
endif() | ||
|
||
if(NOT EXISTS "${CMAKE_BINARY_DIR}/nuget/nuget.exe") | ||
file_download("https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" "${CMAKE_BINARY_DIR}/nuget/nuget.exe" REQUIRED) | ||
|
||
# Add nuget package source if not already present. | ||
execute_process( | ||
COMMAND nuget sources add -Name "NuGet official package source" -Source "https://api.nuget.org/v3/index.json" | ||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/nuget" | ||
OUTPUT_QUIET | ||
ERROR_QUIET | ||
) | ||
endif() | ||
|
||
if("${pkg}" STREQUAL "") | ||
return() | ||
endif() | ||
|
||
execute_process( | ||
COMMAND nuget.exe install "${pkg}" -OutputDirectory "${CMAKE_BINARY_DIR}/nuget" | ||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/nuget" | ||
OUTPUT_VARIABLE install_output | ||
RESULT_VARIABLE install_exit_status | ||
) | ||
|
||
if(NOT install_exit_status EQUAL 0) | ||
message(FATAL_ERROR "NuGet installation of package '${pkg}' failed, exit code: ${install_exit_status}") | ||
endif() | ||
|
||
string(REGEX REPLACE ".* package '[^0-9]+([0-9.]+)'.*" "\\1" pkg_ver "${install_output}") | ||
|
||
set(pkg_dir "${CMAKE_BINARY_DIR}/nuget/${pkg}.${pkg_ver}") | ||
|
||
if(NOT IS_DIRECTORY "${pkg_dir}") | ||
message(FATAL_ERROR "NuGet installation of package '${pkg}' failed, package directory '${pkg_dir}' does not exist.") | ||
endif() | ||
|
||
if(NOT quiet) | ||
message(STATUS "Installed NuGet package '${pkg}' successfully.") | ||
endif() | ||
|
||
set(pkg_bin "${pkg_dir}/tools/bin") | ||
|
||
if(IS_DIRECTORY "${pkg_bin}") | ||
list(APPEND CMAKE_PROGRAM_PATH "${pkg_bin}") | ||
set(CMAKE_PROGRAM_PATH "${CMAKE_PROGRAM_PATH}" PARENT_SCOPE) | ||
set(CMAKE_PROGRAM_PATH "${CMAKE_PROGRAM_PATH}" CACHE STRING "External Program Search Path" FORCE) | ||
|
||
if(NOT quiet) | ||
message(STATUS "Added tools/bin from NuGet package '${pkg}' to CMAKE_PROGRAM_PATH.") | ||
endif() | ||
endif() | ||
endfunction() | ||
|
||
# vim:set sw=8 ts=8 noet: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters