-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[vcpkg-gn] New port vcpkg-gn (#21498)
* [vcpkg-gn] Adding gn as a host only port * Disable support for x86 and fix variable name usage. * [vcpkg-gn] Version information. * Updating documentation. Co-authored-by: David McCloskey <davmcclo@gmail.com>
- Loading branch information
1 parent
a515872
commit 2496d23
Showing
12 changed files
with
336 additions
and
4 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
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
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
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 @@ | ||
set(VCPKG_POLICY_EMPTY_PACKAGE enabled) | ||
|
||
if(NOT TARGET_TRIPLET STREQUAL _HOST_TRIPLET) | ||
message(FATAL_ERROR "vcpkg-gn is a host-only port; please mark it as a host port in your dependencies.") | ||
endif() | ||
|
||
set(BASE_URL "https://chrome-infra-packages.appspot.com/dl/gn/gn") | ||
set(PLATFORM "") | ||
set(ID "") | ||
set(HASH "") | ||
|
||
if(VCPKG_TARGET_IS_WINDOWS) | ||
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") | ||
set(PLATFORM "windows-amd64") | ||
set(ID "UXzb_By8w0nZJ4HNiOo0-ylLKn97JMEGeFgu7lh-5bYC") | ||
set(HASH "4508eee7a8d594d31d34a9810371ba13f0b233642ed89b0185ef209165af1c1b2df49d4b5020e01f333a0724b66bcae80133db8f6256d37295b02927743eaddf") | ||
else() | ||
message(FATAL_ERROR "Only x64 is supported on Windows") | ||
endif() | ||
elseif(VCPKG_TARGET_IS_OSX) | ||
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") | ||
set(PLATFORM "mac-amd64") | ||
set(ID "Al2dYNoD4IBgOnjJSohdXIZMhZJIqHeyaE2AiqWYfIYC") | ||
set(HASH "98b0f6c99ab5e9f6aac448e19aa22d6f2a4924cff51493ce905be7329e1575575c5b9be96e86b07eb0be7215718bf6384bcee01233c8ef0d5554bfa3f51fc811") | ||
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") | ||
set(PLATFORM "mac-arm64") | ||
set(ID "WVStyq9u1pq0xScIl-o4nOlNBYTHCQQCV0KPhgRAAhEC") | ||
set(HASH "ec7a46574d6dc4177e02ac0e558da59dfaa503bf2263c904b09145bc5cbee759c91f0b55b4bc9f372953af78eb3ac6ad98e0fc1b1cf419689a1f7615c786311d") | ||
else() | ||
message(FATAL_ERROR "Only x64 and arm64 are supported on osx") | ||
endif() | ||
elseif(VCPKG_TARGET_IS_LINUX) | ||
if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") | ||
set(PLATFORM "linux-amd64") | ||
set(ID "bMLaJoqEAsCsT5M_sG6KxlaiRQ5aS2RVhrC2qLPilE8C") | ||
set(HASH "fd073139b4ca816dd9f742232d565017237589ec62d02dcb2e54a1d22350450e61b11cc8aa9acd645565f7aac62f9d0bf64ca30f8e6c07f547c746cea3998064") | ||
elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") | ||
set(PLATFORM "linux-arm64") | ||
set(ID "A_VzbiVBrgO0cxX_Iyt8FomIH-WU8YAG2LW8FAhSaOgC") | ||
set(HASH "71da448fd496f803d241ef3656a0c69889a7084624f7f6f92c5326b6e7c0a67b386c69f5cff1a07402b5aa57f5d754a23e09191bbecae8d443ad9896198e36a7") | ||
else() | ||
message(FATAL_ERROR "Only x64 and arm64 are supported on linux") | ||
endif() | ||
else() | ||
message(FATAL_ERROR "Target not yet supported by '${PORT}'") | ||
endif() | ||
|
||
set(URL "${BASE_URL}/${PLATFORM}/+/${ID}") | ||
message(STATUS "URL: '${URL}'") | ||
|
||
vcpkg_download_distfile(ARCHIVE_PATH | ||
URLS "${URL}" | ||
SHA512 "${HASH}" | ||
FILENAME "gn-${PLATFORM}-${ID}.zip" | ||
#ALWAYS_REDOWNLOAD | ||
#SKIP_SHA512 | ||
) | ||
|
||
file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/${PORT}") | ||
message(STATUS "ARCHIVE_PATH: '${ARCHIVE_PATH}'") | ||
|
||
vcpkg_execute_in_download_mode( | ||
COMMAND ${CMAKE_COMMAND} -E tar xzf "${ARCHIVE_PATH}" | ||
WORKING_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/${PORT}" | ||
) | ||
file(GLOB_RECURSE folders "${CURRENT_PACKAGES_DIR}/tools/${PORT}/*" LIST_DIRECTORIES true) | ||
message(STATUS "Files and Folders: '${folders}'") | ||
|
||
file(INSTALL | ||
"${CMAKE_CURRENT_LIST_DIR}/vcpkg_gn_configure.cmake" | ||
"${CMAKE_CURRENT_LIST_DIR}/vcpkg_gn_install.cmake" | ||
"${CMAKE_CURRENT_LIST_DIR}/vcpkg-port-config.cmake" | ||
DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") |
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,4 @@ | ||
include("${CMAKE_CURRENT_LIST_DIR}/vcpkg_gn_configure.cmake") | ||
include("${CMAKE_CURRENT_LIST_DIR}/vcpkg_gn_install.cmake") | ||
|
||
file(REAL_PATH "${CMAKE_CURRENT_LIST_DIR}/../../tools/vcpkg-gn/gn${CMAKE_EXECUTABLE_SUFFIX}" VCPKG_GN) |
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,6 @@ | ||
{ | ||
"name": "vcpkg-gn", | ||
"version-date": "2021-11-16", | ||
"description": "https://gn.googlesource.com/gn/+/4aa9bdfa05b688c58d3d7d3e496f3f18cbb3d89e", | ||
"supports": "native & !x86" | ||
} |
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,80 @@ | ||
#[===[.md: | ||
# vcpkg_gn_configure | ||
|
||
Generate Ninja (GN) targets | ||
|
||
## Usage: | ||
```cmake | ||
vcpkg_gn_configure( | ||
SOURCE_PATH <SOURCE_PATH> | ||
[OPTIONS <OPTIONS>] | ||
[OPTIONS_DEBUG <OPTIONS_DEBUG>] | ||
[OPTIONS_RELEASE <OPTIONS_RELEASE>] | ||
) | ||
``` | ||
|
||
## Parameters: | ||
### SOURCE_PATH (required) | ||
The path to the GN project. | ||
|
||
### OPTIONS | ||
Options to be passed to both the debug and release targets. | ||
Note: Must be provided as a space-separated string. | ||
|
||
### OPTIONS_DEBUG (space-separated string) | ||
Options to be passed to the debug target. | ||
|
||
### OPTIONS_RELEASE (space-separated string) | ||
Options to be passed to the release target. | ||
#]===] | ||
if(Z_VCPKG_GN_CONFIGURE_GUARD) | ||
return() | ||
endif() | ||
set(Z_VCPKG_GN_CONFIGURE_GUARD ON CACHE INTERNAL "guard variable") | ||
|
||
function(z_vcpkg_gn_configure_generate) | ||
cmake_parse_arguments(PARSE_ARGV 0 "arg" "" "SOURCE_PATH;CONFIG;ARGS" "") | ||
if(DEFINED arg_UNPARSED_ARGUMENTS) | ||
message(FATAL_ERROR "Internal error: generate was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") | ||
endif() | ||
|
||
message(STATUS "Generating build (${arg_CONFIG})...") | ||
vcpkg_execute_required_process( | ||
COMMAND "${VCPKG_GN}" gen "${CURRENT_BUILDTREES_DIR}/${arg_CONFIG}" "${arg_ARGS}" | ||
WORKING_DIRECTORY "${arg_SOURCE_PATH}" | ||
LOGNAME "generate-${arg_CONFIG}" | ||
) | ||
endfunction() | ||
|
||
function(vcpkg_gn_configure) | ||
cmake_parse_arguments(PARSE_ARGV 0 "arg" "" "SOURCE_PATH;OPTIONS;OPTIONS_DEBUG;OPTIONS_RELEASE" "") | ||
|
||
if(DEFINED arg_UNPARSED_ARGUMENTS) | ||
message(WARNING "vcpkg_gn_configure was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") | ||
endif() | ||
if(NOT DEFINED arg_SOURCE_PATH) | ||
message(FATAL_ERROR "SOURCE_PATH must be specified.") | ||
endif() | ||
|
||
vcpkg_find_acquire_program(PYTHON2) | ||
get_filename_component(PYTHON2_DIR "${PYTHON2}" DIRECTORY) | ||
vcpkg_add_to_path(PREPEND "${PYTHON2_DIR}") | ||
|
||
vcpkg_find_acquire_program(GN) | ||
|
||
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") | ||
z_vcpkg_gn_configure_generate( | ||
SOURCE_PATH "${arg_SOURCE_PATH}" | ||
CONFIG "${TARGET_TRIPLET}-dbg" | ||
ARGS "--args=${arg_OPTIONS} ${arg_OPTIONS_DEBUG}" | ||
) | ||
endif() | ||
|
||
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") | ||
z_vcpkg_gn_configure_generate( | ||
SOURCE_PATH "${arg_SOURCE_PATH}" | ||
CONFIG "${TARGET_TRIPLET}-rel" | ||
ARGS "--args=${arg_OPTIONS} ${arg_OPTIONS_RELEASE}" | ||
) | ||
endif() | ||
endfunction() |
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,144 @@ | ||
#[===[.md: | ||
# vcpkg_gn_install | ||
|
||
Installs a GN project. | ||
|
||
In order to build a GN project without installing, use [`vcpkg_build_ninja()`]. | ||
|
||
## Usage: | ||
```cmake | ||
vcpkg_gn_install( | ||
SOURCE_PATH <SOURCE_PATH> | ||
[TARGETS <target>...] | ||
) | ||
``` | ||
|
||
## Parameters: | ||
### SOURCE_PATH | ||
The path to the source directory | ||
|
||
### TARGETS | ||
Only install the specified targets. | ||
|
||
Note: includes must be handled separately | ||
|
||
[`vcpkg_build_ninja()`]: vcpkg_build_ninja.md | ||
#]===] | ||
if(Z_VCPKG_GN_INSTALL_GUARD) | ||
return() | ||
endif() | ||
set(Z_VCPKG_GN_INSTALL_GUARD ON CACHE INTERNAL "guard variable") | ||
|
||
function(z_vcpkg_gn_install_get_target_type out_var) | ||
cmake_parse_arguments(PARSE_ARGV 1 "arg" "" "SOURCE_PATH;BUILD_DIR;TARGET" "") | ||
if(DEFINED arg_UNPARSED_ARGUMENTS) | ||
message(FATAL_ERROR "Internal error: get_target_type was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") | ||
endif() | ||
|
||
execute_process( | ||
COMMAND "${VCPKG_GN}" desc "${arg_BUILD_DIR}" "${arg_TARGET}" | ||
WORKING_DIRECTORY "${arg_SOURCE_PATH}" | ||
OUTPUT_VARIABLE output | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
if(output MATCHES [[type: ([A-Za-z0-9_]+)]]) | ||
set("${out_var}" "${CMAKE_MATCH_1}" PARENT_SCOPE) | ||
else() | ||
message(FATAL_ERROR "invalid result from `gn desc`: ${output}") | ||
endif() | ||
endfunction() | ||
|
||
function(z_vcpkg_gn_install_get_desc out_var) | ||
cmake_parse_arguments(PARSE_ARGV 1 "arg" "" "SOURCE_PATH;BUILD_DIR;TARGET;WHAT_TO_DISPLAY" "") | ||
if(DEFINED arg_UNPARSED_ARGUMENTS) | ||
message(FATAL_ERROR "Internal error: get_desc was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") | ||
endif() | ||
|
||
execute_process( | ||
COMMAND "${VCPKG_GN}" desc "${arg_BUILD_DIR}" "${arg_TARGET}" "${arg_WHAT_TO_DISPLAY}" | ||
WORKING_DIRECTORY "${arg_SOURCE_PATH}" | ||
OUTPUT_VARIABLE output | ||
OUTPUT_STRIP_TRAILING_WHITESPACE | ||
) | ||
string(REPLACE ";" "\\;" output "${output}") | ||
string(REGEX REPLACE "\n|(\r\n)" ";" output "${output}") | ||
set("${out_var}" "${output}" PARENT_SCOPE) | ||
endfunction() | ||
|
||
function(z_vcpkg_gn_install_install) | ||
cmake_parse_arguments(PARSE_ARGV 0 "arg" "" "SOURCE_PATH;BUILD_DIR;INSTALL_DIR" "TARGETS") | ||
if(DEFINED arg_UNPARSED_ARGUMENTS) | ||
message(FATAL_ERROR "Internal error: install was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") | ||
endif() | ||
|
||
foreach(target IN LISTS arg_TARGETS) | ||
# GN targets must start with a // | ||
z_vcpkg_gn_install_get_desc(outputs | ||
SOURCE_PATH "${arg_SOURCE_PATH}" | ||
BUILD_DIR "${arg_BUILD_DIR}" | ||
TARGET "//${target}" | ||
WHAT_TO_DISPLAY outputs | ||
) | ||
z_vcpkg_gn_install_get_target_type(target_type | ||
SOURCE_PATH "${arg_SOURCE_PATH}" | ||
BUILD_DIR "${arg_BUILD_DIR}" | ||
TARGET "//${target}" | ||
) | ||
|
||
foreach(output IN LISTS outputs) | ||
if(output MATCHES "^//") | ||
# relative path (e.g. //out/Release/target.lib) | ||
string(REGEX REPLACE "^//" "${arg_SOURCE_PATH}/" output "${output}") | ||
elseif(output MATCHES "^/" AND CMAKE_HOST_WIN32) | ||
# absolute path (e.g. /C:/path/to/target.lib) | ||
string(REGEX REPLACE "^/" "" output "${output}") | ||
endif() | ||
|
||
if(NOT EXISTS "${output}") | ||
message(WARNING "Output for target `${target}` doesn't exist: ${output}.") | ||
continue() | ||
endif() | ||
|
||
if(target_type STREQUAL "executable") | ||
file(INSTALL "${output}" DESTINATION "${arg_INSTALL_DIR}/tools") | ||
elseif(output MATCHES "(\\.dll|\\.pdb)$") | ||
file(INSTALL "${output}" DESTINATION "${arg_INSTALL_DIR}/bin") | ||
else() | ||
file(INSTALL "${output}" DESTINATION "${arg_INSTALL_DIR}/lib") | ||
endif() | ||
endforeach() | ||
endforeach() | ||
endfunction() | ||
|
||
function(vcpkg_gn_install) | ||
cmake_parse_arguments(PARSE_ARGV 0 arg "" "SOURCE_PATH" "TARGETS") | ||
|
||
if(DEFINED arg_UNPARSED_ARGUMENTS) | ||
message(WARNING "vcpkg_gn_install was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") | ||
endif() | ||
if(NOT DEFINED arg_SOURCE_PATH) | ||
message(FATAL_ERROR "SOURCE_PATH must be specified.") | ||
endif() | ||
|
||
vcpkg_build_ninja(TARGETS ${arg_TARGETS}) | ||
|
||
vcpkg_find_acquire_program(GN) | ||
|
||
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") | ||
z_vcpkg_gn_install_install( | ||
SOURCE_PATH "${arg_SOURCE_PATH}" | ||
BUILD_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg" | ||
INSTALL_DIR "${CURRENT_PACKAGES_DIR}/debug" | ||
TARGETS ${arg_TARGETS} | ||
) | ||
endif() | ||
|
||
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") | ||
z_vcpkg_gn_install_install( | ||
SOURCE_PATH "${arg_SOURCE_PATH}" | ||
BUILD_DIR "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel" | ||
INSTALL_DIR "${CURRENT_PACKAGES_DIR}" | ||
TARGETS ${arg_TARGETS} | ||
) | ||
endif() | ||
endfunction() |
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
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
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
Oops, something went wrong.