diff options
| author | nicole mazzuca <mazzucan@outlook.com> | 2021-02-28 13:17:19 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-02-28 13:17:19 -0800 |
| commit | 3426db05b996481ca31e95fff3734cf23e0f51bc (patch) | |
| tree | f6fada40f86391d87ba0b093f0c17f169d125912 /ports | |
| parent | e25b620cf90d9bb311f91b03916b75d8798afd44 (diff) | |
| download | vcpkg-3426db05b996481ca31e95fff3734cf23e0f51bc.tar.gz vcpkg-3426db05b996481ca31e95fff3734cf23e0f51bc.zip | |
[scripts-audit] Rollup PR 2021-02-26 (#16440)
* [scripts-audit rollup] PR #16419
* pull the cmake doc comment parsing out into its own function
* support cmake helper ports
* add real support for deprecation, as opposed to ad-hoc
* [scripts-audit rollup] PR #16192
* add a z_ in front of internal functions
* move internal functions out
set feature_vars again in parent scope
* [scripts-audit rollup] PR #16309
Audit vcpkg_copy_pdbs
* [scripts-audit rollup] PR #16304
* Fix usage, documentation
* [scripts-audit rollup] PR #16393
* [scripts-audit rollup] PR #16377
Deprecate `vcpkg_*_cmake` in favor of `vcpkg_cmake_*` from the
`vcpkg-cmake` port, as well as `vcpkg_fixup_cmake_targets`
in favor of `vcpkg_cmake_config_fixup` from the
`vcpkg-cmake-config` port.
Diffstat (limited to 'ports')
| -rw-r--r-- | ports/fmt/CONTROL | 5 | ||||
| -rw-r--r-- | ports/fmt/portfile.cmake | 7 | ||||
| -rw-r--r-- | ports/fmt/vcpkg.json | 17 | ||||
| -rw-r--r-- | ports/vcpkg-cmake-config/README.md | 10 | ||||
| -rw-r--r-- | ports/vcpkg-cmake-config/copyright | 23 | ||||
| -rw-r--r-- | ports/vcpkg-cmake-config/portfile.cmake | 11 | ||||
| -rw-r--r-- | ports/vcpkg-cmake-config/vcpkg-port-config.cmake | 1 | ||||
| -rw-r--r-- | ports/vcpkg-cmake-config/vcpkg.json | 4 | ||||
| -rw-r--r-- | ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake | 237 | ||||
| -rw-r--r-- | ports/vcpkg-cmake/README.md | 7 | ||||
| -rw-r--r-- | ports/vcpkg-cmake/copyright | 23 | ||||
| -rw-r--r-- | ports/vcpkg-cmake/portfile.cmake | 13 | ||||
| -rw-r--r-- | ports/vcpkg-cmake/vcpkg-port-config.cmake | 3 | ||||
| -rw-r--r-- | ports/vcpkg-cmake/vcpkg.json | 4 | ||||
| -rw-r--r-- | ports/vcpkg-cmake/vcpkg_cmake_build.cmake | 115 | ||||
| -rw-r--r-- | ports/vcpkg-cmake/vcpkg_cmake_configure.cmake | 391 | ||||
| -rw-r--r-- | ports/vcpkg-cmake/vcpkg_cmake_install.cmake | 46 |
17 files changed, 908 insertions, 9 deletions
diff --git a/ports/fmt/CONTROL b/ports/fmt/CONTROL deleted file mode 100644 index 23ea3ec68..000000000 --- a/ports/fmt/CONTROL +++ /dev/null @@ -1,5 +0,0 @@ -Source: fmt -Version: 7.1.3 -Port-Version: 0 -Homepage: https://github.com/fmtlib/fmt -Description: Formatting library for C++. It can be used as a safe alternative to printf or as a fast alternative to IOStreams. diff --git a/ports/fmt/portfile.cmake b/ports/fmt/portfile.cmake index 692314ff2..c91f568a2 100644 --- a/ports/fmt/portfile.cmake +++ b/ports/fmt/portfile.cmake @@ -6,16 +6,15 @@ vcpkg_from_github( HEAD_REF master PATCHES fix-warning4189.patch ) -vcpkg_configure_cmake( +vcpkg_cmake_configure( SOURCE_PATH ${SOURCE_PATH} - PREFER_NINJA OPTIONS -DFMT_CMAKE_DIR=share/fmt -DFMT_TEST=OFF -DFMT_DOC=OFF ) -vcpkg_install_cmake() +vcpkg_cmake_install() file(INSTALL ${SOURCE_PATH}/LICENSE.rst DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic) if(VCPKG_TARGET_IS_WINDOWS) @@ -40,7 +39,7 @@ if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic) endif() file(REMOVE_RECURSE ${CURRENT_PACKAGES_DIR}/debug/include) -vcpkg_fixup_cmake_targets() +vcpkg_cmake_config_fixup() vcpkg_fixup_pkgconfig() if(VCPKG_TARGET_IS_WINDOWS) diff --git a/ports/fmt/vcpkg.json b/ports/fmt/vcpkg.json new file mode 100644 index 000000000..debc7b8e3 --- /dev/null +++ b/ports/fmt/vcpkg.json @@ -0,0 +1,17 @@ +{ + "name": "fmt", + "version": "7.1.3", + "port-version": 1, + "description": "Formatting library for C++. It can be used as a safe alternative to printf or as a fast alternative to IOStreams.", + "homepage": "https://github.com/fmtlib/fmt", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ] +} diff --git a/ports/vcpkg-cmake-config/README.md b/ports/vcpkg-cmake-config/README.md new file mode 100644 index 000000000..18e7bb9ac --- /dev/null +++ b/ports/vcpkg-cmake-config/README.md @@ -0,0 +1,10 @@ +# vcpkg-cmake-config + +`vcpkg-cmake-config` provides `vcpkg_cmake_config_fixup()`, +a function which both: + +- Fixes common mistakes in port build systems, like using absolute paths +- Merges the debug and release config files. + +This function should almost always be used when a port has `*config.cmake` files, +even when the buildsystem of the project is not CMake. diff --git a/ports/vcpkg-cmake-config/copyright b/ports/vcpkg-cmake-config/copyright new file mode 100644 index 000000000..2e4eac826 --- /dev/null +++ b/ports/vcpkg-cmake-config/copyright @@ -0,0 +1,23 @@ +Copyright (c) Microsoft Corporation + +All rights reserved. + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/ports/vcpkg-cmake-config/portfile.cmake b/ports/vcpkg-cmake-config/portfile.cmake new file mode 100644 index 000000000..45ecf62fd --- /dev/null +++ b/ports/vcpkg-cmake-config/portfile.cmake @@ -0,0 +1,11 @@ +if(NOT TARGET_TRIPLET STREQUAL _HOST_TRIPLET) + message(FATAL_ERROR "vcpkg-cmake-config is a host-only port; please mark it as a host port in your dependencies.") +endif() + +file(INSTALL + "${CMAKE_CURRENT_LIST_DIR}/vcpkg_cmake_config_fixup.cmake" + "${CMAKE_CURRENT_LIST_DIR}/vcpkg-port-config.cmake" + "${CMAKE_CURRENT_LIST_DIR}/copyright" + DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") + +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) diff --git a/ports/vcpkg-cmake-config/vcpkg-port-config.cmake b/ports/vcpkg-cmake-config/vcpkg-port-config.cmake new file mode 100644 index 000000000..980d41131 --- /dev/null +++ b/ports/vcpkg-cmake-config/vcpkg-port-config.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/vcpkg_cmake_config_fixup.cmake") diff --git a/ports/vcpkg-cmake-config/vcpkg.json b/ports/vcpkg-cmake-config/vcpkg.json new file mode 100644 index 000000000..26737e44f --- /dev/null +++ b/ports/vcpkg-cmake-config/vcpkg.json @@ -0,0 +1,4 @@ +{ + "name": "vcpkg-cmake-config", + "version-date": "2021-02-26" +} diff --git a/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake b/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake new file mode 100644 index 000000000..e858c70e6 --- /dev/null +++ b/ports/vcpkg-cmake-config/vcpkg_cmake_config_fixup.cmake @@ -0,0 +1,237 @@ +#[===[.md: +# vcpkg_cmake_config_fixup + +Merge release and debug CMake targets and configs to support multiconfig generators. + +Additionally corrects common issues with targets, such as absolute paths and incorrectly placed binaries. + +```cmake +vcpkg_cmake_config_fixup( + [PACKAGE_NAME <name>] + [CONFIG_PATH <config-directory>] + [DO_NOT_DELETE_CONFIG_PATH_PARENT] + [NO_PREFIX_CORRECTION] +) +``` + +For many ports, `vcpkg_cmake_config_fixup()` on its own should work, +as `PACKAGE_NAME` defaults to `${PORT}` and `CONFIG_PATH` defaults to `share/${PACKAGE_NAME}`. +For ports where the package name passed to `find_package` is distinct from the port name, +`PACKAGE_NAME` should be changed to be that name instead. +For ports where the directory of the `*config.cmake` files cannot be set, +use the `CONFIG_PATH` to change the directory where the files come from. + +By default the parent directory of CONFIG_PATH is removed if it is named "cmake". +Passing the `DO_NOT_DELETE_PARENT_CONFIG_PATH` option disable such behavior, +as it is convenient for ports that install +more than one CMake package configuration file. + +The `NO_PREFIX_CORRECTION` option disables the correction of `_IMPORT_PREFIX` +done by vcpkg due to moving the config files. +Currently the correction does not take into account how the files are moved, +and applies a rather simply correction which in some cases will yield the wrong results. + +## How it Works + +1. Moves `/debug/<CONFIG_PATH>/*targets-debug.cmake` to `/share/${PACKAGE_NAME}`. +2. Removes `/debug/<CONFIG_PATH>/*config.cmake`. +3. Transform all references matching `/bin/*.exe` to `/tools/<port>/*.exe` on Windows. +4. Transform all references matching `/bin/*` to `/tools/<port>/*` on other platforms. +5. Fixes `${_IMPORT_PREFIX}` in auto generated targets. +6. Replace `${CURRENT_INSTALLED_DIR}` with `${_IMPORT_PREFIX}` in configs and targets. + +## Examples + +* [concurrentqueue](https://github.com/Microsoft/vcpkg/blob/master/ports/concurrentqueue/portfile.cmake) +* [curl](https://github.com/Microsoft/vcpkg/blob/master/ports/curl/portfile.cmake) +* [nlohmann-json](https://github.com/Microsoft/vcpkg/blob/master/ports/nlohmann-json/portfile.cmake) +#]===] +if(Z_VCPKG_CMAKE_CONFIG_FIXUP_GUARD) + return() +endif() +set(Z_VCPKG_CMAKE_CONFIG_FIXUP_GUARD ON CACHE INTERNAL "guard variable") + +function(vcpkg_cmake_config_fixup) + cmake_parse_arguments(PARSE_ARGV 0 "arg" "DO_NOT_DELETE_PARENT_CONFIG_PATH" "PACKAGE_NAME;CONFIG_PATH;NO_PREFIX_CORRECTION" "") + + if(DEFINED arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "vcpkg_cmake_config_fixup was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") + endif() + if(NOT arg_PACKAGE_NAME) + set(arg_PACKAGE_NAME "${PORT}") + endif() + if(NOT arg_CONFIG_PATH) + set(arg_CONFIG_PATH "share/${arg_PACKAGE_NAME}") + endif() + set(target_path "share/${arg_PACKAGE_NAME}") + + string(REPLACE "." "\\." EXECUTABLE_SUFFIX "${VCPKG_TARGET_EXECUTABLE_SUFFIX}") + + set(debug_share "${CURRENT_PACKAGES_DIR}/debug/${target_path}") + set(release_share "${CURRENT_PACKAGES_DIR}/${target_path}") + + if(NOT arg_CONFIG_PATH STREQUAL "share/${arg_PACKAGE_NAME}") + if(arg_CONFIG_PATH STREQUAL "share") + set(arg_CONFIG_PATH z_vcpkg_share) + file(RENAME "${CURRENT_PACKAGES_DIR}/debug/share" "${CURRENT_PACKAGES_DIR}/debug/${arg_CONFIG_PATH}") + file(RENAME "${CURRENT_PACKAGES_DIR}/share" "${CURRENT_PACKAGES_DIR}/${arg_CONFIG_PATH}") + endif() + + set(debug_config "${CURRENT_PACKAGES_DIR}/debug/${arg_CONFIG_PATH}") + set(release_config "${CURRENT_PACKAGES_DIR}/${arg_CONFIG_PATH}") + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + if(NOT EXISTS "${debug_config}") + message(FATAL_ERROR "'${debug_config}' does not exist.") + endif() + + # This roundabout handling enables CONFIG_PATH = share + file(MAKE_DIRECTORY "${debug_share}") + file(GLOB files "${debug_config}/*") + file(COPY ${files} DESTINATION "${debug_share}") + file(REMOVE_RECURSE "${debug_config}") + endif() + + file(GLOB files "${release_config}/*") + file(COPY ${files} DESTINATION "${release_share}") + file(REMOVE_RECURSE "${release_config}") + + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + get_filename_component(debug_config_dir_name "${debug_config}" NAME) + string(TOLOWER "${debug_config_dir_name}" debug_config_dir_name) + if(debug_config_dir_name STREQUAL "cmake" AND NOT arg_DO_NOT_DELETE_PARENT_CONFIG_PATH) + file(REMOVE_RECURSE "${debug_config}") + else() + get_filename_component(debug_config_parent_dir "${debug_config}" DIRECTORY) + get_filename_component(debug_config_dir_name "${debug_config_parent_dir}" NAME) + string(TOLOWER "${debug_config_dir_name}" debug_config_dir_name) + if(debug_config_dir_name STREQUAL "cmake" AND NOT arg_DO_NOT_DELETE_PARENT_CONFIG_PATH) + file(REMOVE_RECURSE "${debug_config_parent_dir}") + endif() + endif() + endif() + + get_filename_component(release_config_dir_name "${release_config}" NAME) + string(TOLOWER "${release_config_dir_name}" release_config_dir_name) + if(release_config_dir_name STREQUAL "cmake" AND NOT arg_DO_NOT_DELETE_PARENT_CONFIG_PATH) + file(REMOVE_RECURSE "${release_config}") + else() + get_filename_component(release_config_parent_dir "${release_config}" DIRECTORY) + get_filename_component(release_config_dir_name "${release_config_parent_dir}" NAME) + string(TOLOWER "${release_config_dir_name}" release_config_dir_name) + if(release_config_dir_name STREQUAL "cmake" AND NOT arg_DO_NOT_DELETE_PARENT_CONFIG_PATH) + file(REMOVE_RECURSE "${release_config_parent_dir}") + endif() + endif() + endif() + + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + if(NOT EXISTS "${debug_share}") + message(FATAL_ERROR "'${debug_share}' does not exist.") + endif() + endif() + + file(GLOB_RECURSE unused_files + "${debug_share}/*[Tt]argets.cmake" + "${debug_share}/*[Cc]onfig.cmake" + "${debug_share}/*[Cc]onfigVersion.cmake" + "${debug_share}/*[Cc]onfig-version.cmake" + ) + if(NOT unused_files STREQUAL "") + file(REMOVE "${unused_files}") + endif() + + file(GLOB_RECURSE release_targets + "${release_share}/*-release.cmake" + ) + foreach(release_target IN LISTS release_targets) + file(READ "${release_target}" contents) + string(REPLACE "${CURRENT_INSTALLED_DIR}" "\${_IMPORT_PREFIX}" contents "${contents}") + string(REGEX REPLACE "\\\${_IMPORT_PREFIX}/bin/([^ \"]+${EXECUTABLE_SUFFIX})" "\${_IMPORT_PREFIX}/tools/${PORT}/\\1" contents "${contents}") + file(WRITE "${release_target}" "${contents}") + endforeach() + + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + file(GLOB_RECURSE debug_targets + "${debug_share}/*-debug.cmake" + ) + foreach(debug_target IN LISTS debug_targets) + file(RELATIVE_PATH debug_target_rel "${debug_share}" "${debug_target}") + + file(READ "${debug_target}" contents) + string(REPLACE "${CURRENT_INSTALLED_DIR}" "\${_IMPORT_PREFIX}" contents "${contents}") + string(REGEX REPLACE "\\\${_IMPORT_PREFIX}/bin/([^ \";]+${EXECUTABLE_SUFFIX})" "\${_IMPORT_PREFIX}/tools/${PORT}/\\1" contents "${contents}") + string(REPLACE "\${_IMPORT_PREFIX}/lib" "\${_IMPORT_PREFIX}/debug/lib" contents "${contents}") + string(REPLACE "\${_IMPORT_PREFIX}/bin" "\${_IMPORT_PREFIX}/debug/bin" contents "${contents}") + file(WRITE "${release_share}/${debug_target_rel}" "${contents}") + + file(REMOVE "${debug_target}") + endforeach() + endif() + + #Fix ${_IMPORT_PREFIX} in cmake generated targets and configs; + #Since those can be renamed we have to check in every *.cmake + file(GLOB_RECURSE main_cmakes "${release_share}/*.cmake") + + foreach(main_cmake IN LISTS main_cmakes) + file(READ "${main_cmake}" contents) + # Note: I think the following comment is no longer true, since we now require the path to be `share/blah` + # however, I don't know it for sure. + # - nimazzuc + + #This correction is not correct for all cases. To make it correct for all cases it needs to consider + #original folder deepness to CURRENT_PACKAGES_DIR in comparison to the moved to folder deepness which + #is always at least (>=) 2, e.g. share/${PORT}. Currently the code assumes it is always 2 although + #this requirement is only true for the *Config.cmake. The targets are not required to be in the same + #folder as the *Config.cmake! + if(NOT arg_NO_PREFIX_CORRECTION) + string(REGEX REPLACE +[[get_filename_component\(_IMPORT_PREFIX "\${CMAKE_CURRENT_LIST_FILE}" PATH\)( +get_filename_component\(_IMPORT_PREFIX "\${_IMPORT_PREFIX}" PATH\))*]] +[[get_filename_component(_IMPORT_PREFIX "${CMAKE_CURRENT_LIST_FILE}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH) +get_filename_component(_IMPORT_PREFIX "${_IMPORT_PREFIX}" PATH)]] + contents "${contents}") # see #1044 for details why this replacement is necessary. See #4782 why it must be a regex. + string(REGEX REPLACE +[[get_filename_component\(PACKAGE_PREFIX_DIR "\${CMAKE_CURRENT_LIST_DIR}/\.\./(\.\./)*" ABSOLUTE\)]] +[[get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../" ABSOLUTE)]] + contents "${contents}") + string(REGEX REPLACE +[[get_filename_component\(PACKAGE_PREFIX_DIR "\${CMAKE_CURRENT_LIST_DIR}/\.\.((\\|/)\.\.)*" ABSOLUTE\)]] +[[get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../" ABSOLUTE)]] + contents "${contents}") # This is a meson-related workaround, see https://github.com/mesonbuild/meson/issues/6955 + endif() + + #Fix wrongly absolute paths to install dir with the correct dir using ${_IMPORT_PREFIX} + #This happens if vcpkg built libraries are directly linked to a target instead of using + #an imported target for it. We could add more logic here to identify defect target files. + #Since the replacement here in a multi config build always requires a generator expression + #in front of the absoulte path to ${CURRENT_INSTALLED_DIR}. So the match should always be at + #least >:${CURRENT_INSTALLED_DIR}. + #In general the following generator expressions should be there: + #\$<\$<CONFIG:DEBUG>:${CURRENT_INSTALLED_DIR}/debug/lib/somelib> + #and/or + #\$<\$<NOT:\$<CONFIG:DEBUG>>:${CURRENT_INSTALLED_DIR}/lib/somelib> + #with ${CURRENT_INSTALLED_DIR} being fully expanded + string(REPLACE "${CURRENT_INSTALLED_DIR}" [[${_IMPORT_PREFIX}]] contents "${contents}") + + # Patch out any remaining absolute references + file(TO_CMAKE_PATH "${CURRENT_PACKAGES_DIR}" cmake_current_packages_dir) + string(REPLACE "${CMAKE_CURRENT_PACKAGES_DIR}" [[${_IMPORT_PREFIX}]] contents "${contents}") + + file(WRITE "${main_cmake}" "${contents}") + endforeach() + + # Remove /debug/<target_path>/ if it's empty. + file(GLOB_RECURSE remaining_files "${debug_share}/*") + if(NOT remaining_files STREQUAL "") + file(REMOVE_RECURSE "${debug_share}") + endif() + + # Remove /debug/share/ if it's empty. + file(GLOB_RECURSE remaining_files "${CURRENT_PACKAGES_DIR}/debug/share/*") + if(NOT remaining_files STREQUAL "") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share") + endif() +endfunction() + + diff --git a/ports/vcpkg-cmake/README.md b/ports/vcpkg-cmake/README.md new file mode 100644 index 000000000..b84c58869 --- /dev/null +++ b/ports/vcpkg-cmake/README.md @@ -0,0 +1,7 @@ +# vcpkg-cmake + +This port contains cmake functions for dealing with a CMake buildsystem. + +In the common case, `vcpkg_cmake_configure()` (with appropriate arguments) +followed by `vcpkg_cmake_install()` will be enough to build and install a port. +`vcpkg_cmake_build()` is provided for more complex cases. diff --git a/ports/vcpkg-cmake/copyright b/ports/vcpkg-cmake/copyright new file mode 100644 index 000000000..2e4eac826 --- /dev/null +++ b/ports/vcpkg-cmake/copyright @@ -0,0 +1,23 @@ +Copyright (c) Microsoft Corporation + +All rights reserved. + +MIT License + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/ports/vcpkg-cmake/portfile.cmake b/ports/vcpkg-cmake/portfile.cmake new file mode 100644 index 000000000..7f275926e --- /dev/null +++ b/ports/vcpkg-cmake/portfile.cmake @@ -0,0 +1,13 @@ +if(NOT TARGET_TRIPLET STREQUAL _HOST_TRIPLET) + message(FATAL_ERROR "vcpkg-cmake is a host-only port; please mark it as a host port in your dependencies.") +endif() + +file(INSTALL + "${CMAKE_CURRENT_LIST_DIR}/vcpkg_cmake_configure.cmake" + "${CMAKE_CURRENT_LIST_DIR}/vcpkg_cmake_build.cmake" + "${CMAKE_CURRENT_LIST_DIR}/vcpkg_cmake_install.cmake" + "${CMAKE_CURRENT_LIST_DIR}/vcpkg-port-config.cmake" + "${CMAKE_CURRENT_LIST_DIR}/copyright" + DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") + +set(VCPKG_POLICY_EMPTY_PACKAGE enabled) diff --git a/ports/vcpkg-cmake/vcpkg-port-config.cmake b/ports/vcpkg-cmake/vcpkg-port-config.cmake new file mode 100644 index 000000000..f2a973d4e --- /dev/null +++ b/ports/vcpkg-cmake/vcpkg-port-config.cmake @@ -0,0 +1,3 @@ +include("${CMAKE_CURRENT_LIST_DIR}/vcpkg_cmake_configure.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/vcpkg_cmake_build.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/vcpkg_cmake_install.cmake") diff --git a/ports/vcpkg-cmake/vcpkg.json b/ports/vcpkg-cmake/vcpkg.json new file mode 100644 index 000000000..cc7a12c04 --- /dev/null +++ b/ports/vcpkg-cmake/vcpkg.json @@ -0,0 +1,4 @@ +{ + "name": "vcpkg-cmake", + "version-date": "2021-02-26" +} diff --git a/ports/vcpkg-cmake/vcpkg_cmake_build.cmake b/ports/vcpkg-cmake/vcpkg_cmake_build.cmake new file mode 100644 index 000000000..ef27a6c91 --- /dev/null +++ b/ports/vcpkg-cmake/vcpkg_cmake_build.cmake @@ -0,0 +1,115 @@ +#[===[.md: +# vcpkg_cmake_build + +Build a cmake project. + +```cmake +vcpkg_cmake_build( + [TARGET <target>] + [LOGFILE_BASE <base>] + [DISABLE_PARALLEL] + [ADD_BIN_TO_PATH] +) +``` + +`vcpkg_cmake_build` builds an already-configured cmake project. +You can use the alias [`vcpkg_cmake_install()`] function +if your CMake build system supports the `install` TARGET, +and this is something we recommend doing whenever possible. +Otherwise, you can use `TARGET` to set the target to build. +This function defaults to not passing a target to cmake. + +`LOGFILE_BASE` is used to set the base of the logfile names; +by default, this is `build`, and thus the logfiles end up being something like +`build-x86-windows-dbg.log`; if you use `vcpkg_cmake_install`, +this is set to `install`, so you'll get log names like `install-x86-windows-dbg.log`. + +For build systems that are buggy when run in parallel, +using `DISABLE_PARALLEL` will run the build with only one job. + +Finally, `ADD_BIN_TO_PATH` adds the appropriate (either release or debug) +`bin/` directories to the path during the build, +such that executables run during the build will be able to access those DLLs. +#]===] +if(Z_VCPKG_CMAKE_BUILD_GUARD) + return() +endif() +set(Z_VCPKG_CMAKE_BUILD_GUARD ON CACHE INTERNAL "guard variable") + +function(vcpkg_cmake_build) + cmake_parse_arguments(PARSE_ARGV 0 "arg" "DISABLE_PARALLEL;ADD_BIN_TO_PATH" "TARGET;LOGFILE_BASE" "") + + if(DEFINED arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "vcpkg_cmake_build was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") + endif() + if(NOT DEFINED arg_LOGFILE_BASE) + set(arg_LOGFILE_BASE "build") + endif() + + set(build_args) + set(target_args) + set(parallel_args) + set(no_parallel_args) + + if(Z_VCPKG_CMAKE_GENERATOR STREQUAL "Ninja") + set(build_args "-v") # verbose output + set(parallel_args "-j${VCPKG_CONCURRENCY}") + set(no_parallel_args "-j1") + elseif(Z_VCPKG_CMAKE_GENERATOR MATCHES "^Visual Studio") + set(build_args + "/p:VCPkgLocalAppDataDisabled=true" + "/p:UseIntelMKL=No" + ) + set(parallel_args "/m") + elseif(Z_VCPKG_CMAKE_GENERATOR STREQUAL "NMake Makefiles") + # No options are currently added for nmake builds + else() + message(FATAL_ERROR "Unrecognized GENERATOR setting from vcpkg_configure_cmake(). Valid generators are: Ninja, Visual Studio, and NMake Makefiles") + endif() + + if(DEFINED arg_TARGET) + set(target_args "--target" "${arg_TARGET}") + endif() + + foreach(buildtype IN ITEMS debug release) + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL buildtype) + if(buildtype STREQUAL "debug") + set(short_buildtype "dbg") + set(cmake_config "Debug") + else() + set(short_buildtype "rel") + set(cmake_config "Release") + endif() + + message(STATUS "Building ${TARGET_TRIPLET}-${short_buildtype}") + + if(arg_ADD_BIN_TO_PATH) + set(env_path_backup "$ENV{PATH}") + if(buildtype STREQUAL "debug") + vcpkg_add_to_path(PREPEND "${CURRENT_INSTALLED_DIR}/debug/bin") + else() + vcpkg_add_to_path(PREPEND "${CURRENT_INSTALLED_DIR}/bin") + endif() + endif() + + if (arg_DISABLE_PARALLEL) + vcpkg_execute_build_process( + COMMAND "${CMAKE_COMMAND}" --build . --config "${cmake_config}" ${target_args} -- ${build_args} ${no_parallel_args} + WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${short_buildtype}" + LOGNAME "${arg_LOGFILE_BASE}-${TARGET_TRIPLET}-${short_buildtype}" + ) + else() + vcpkg_execute_build_process( + COMMAND "${CMAKE_COMMAND}" --build . --config "${cmake_config}" ${target_args} -- ${build_args} ${parallel_args} + NO_PARALLEL_COMMAND "${CMAKE_COMMAND}" --build . --config "${cmake_config}" ${target_args} -- ${build_args} ${no_parallel_args} + WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${short_buildtype}" + LOGNAME "${arg_LOGFILE_BASE}-${TARGET_TRIPLET}-${short_buildtype}" + ) + endif() + + if(arg_ADD_BIN_TO_PATH) + set(ENV{PATH} "${env_path_backup}") + endif() + endif() + endforeach() +endfunction() diff --git a/ports/vcpkg-cmake/vcpkg_cmake_configure.cmake b/ports/vcpkg-cmake/vcpkg_cmake_configure.cmake new file mode 100644 index 000000000..a7d96dbc3 --- /dev/null +++ b/ports/vcpkg-cmake/vcpkg_cmake_configure.cmake @@ -0,0 +1,391 @@ +#[===[.md: +# vcpkg_cmake_configure + +Configure a CMake buildsystem. + +```cmake +vcpkg_cmake_configure( + SOURCE_PATH <source-path> + [LOGFILE_BASE <logname-base>] + [DISABLE_PARALLEL_CONFIGURE] + [NO_CHARSET_FLAG] + [WINDOWS_USE_MSBUILD] + [GENERATOR <generator>] + [OPTIONS + <configure-setting>...] + [OPTIONS_RELEASE + <configure-setting>...] + [OPTIONS_DEBUG + <configure-setting>...] +) +``` + +`vcpkg_cmake_configure` configures a CMake build system for use with +`vcpkg_cmake_buildsystem_build` and `vcpkg_cmake_buildsystem_install`. +`source-path` is where the source is located; by convention, +this is usually `${SOURCE_PATH}`, which is set by one of the `vcpkg_from_*` functions. +This function configures the build system for both Debug and Release builds by default, +assuming that `VCPKG_BUILD_TYPE` is not set; if it is, then it will only configure for +that build type. + +Use the `OPTIONS` argument to set the configure settings for both release and debug, +and use `OPTIONS_RELEASE` and `OPTIONS_DEBUG` to set the configure settings for +release only and debug only repsectively. + +By default, when possible, `vcpkg_cmake_configure` uses [ninja-build] +as its build system. If the `WINDOWS_USE_MSBUILD` argument is passed, then +`vcpkg_cmake_configure` will use a Visual Studio generator on Windows; +on every other platform, `vcpkg_cmake_configure` just uses Ninja. + +[ninja-build]: https://ninja-build.org/ + +Additionally, one may pass the specific generator a port should use with `GENERATOR`. +This is useful if some project-specific buildsystem +has been wrapped in a CMake build system that doesn't perform an actual build. +If used for this purpose, it should be set to `"NMake Makefiles"`. +`vcpkg_cmake_buildsystem_build` and `install` do not support this being set to anything +except for NMake. + +For libraries which cannot be configured in parallel, +pass the `DISABLE_PARALLEL_CONFIGURE` flag. This is needed, for example, +if the library's build system writes back into the source directory during configure. +This also disables the `CMAKE_DISABLE_SOURCE_CHANGES` option. + +By default, this function adds flags to `CMAKE_C_FLAGS` and `CMAKE_CXX_FLAGS` +which set the default character set to utf-8 for MSVC. +If the library sets its own code page, pass the `NO_CHARSET_FLAG` option. + +`LOGFILE_BASE` is used to set the base of the logfile names; +by default, this is `config`, and thus the logfiles end up being something like +`config-x86-windows-dbg.log`. You can set it to anything you like; +if you set it to `config-the-first`, +you'll get something like `config-the-first-x86-windows.dbg.log`. + +## Notes +This command supplies many common arguments to CMake. To see the full list, examine the source. + +## Examples + +* [zlib](https://github.com/Microsoft/vcpkg/blob/master/ports/zlib/portfile.cmake) +* [cpprestsdk](https://github.com/Microsoft/vcpkg/blob/master/ports/cpprestsdk/portfile.cmake) +* [poco](https://github.com/Microsoft/vcpkg/blob/master/ports/poco/portfile.cmake) +* [opencv](https://github.com/Microsoft/vcpkg/blob/master/ports/opencv/portfile.cmake) +#]===] +if(Z_VCPKG_CMAKE_CONFIGURE_GUARD) + return() +endif() +set(Z_VCPKG_CMAKE_CONFIGURE_GUARD ON CACHE INTERNAL "guard variable") + +macro(z_vcpkg_cmake_configure_both_set_or_unset var1 var2) + if(DEFINED ${var1} AND NOT DEFINED ${var2}) + message(FATAL_ERROR "If ${var1} is set, then ${var2} must be set.") + elseif(NOT DEFINED ${var1} AND DEFINED ${var2}) + message(FATAL_ERROR "If ${var2} is set, then ${var1} must be set.") + endif() +endmacro() + +function(vcpkg_cmake_configure) + cmake_parse_arguments(PARSE_ARGV 0 "arg" + "PREFER_NINJA;DISABLE_PARALLEL_CONFIGURE;WINDOWS_USE_MSBUILD;NO_CHARSET_FLAG" + "SOURCE_PATH;GENERATOR;LOGFILE_BASE" + "OPTIONS;OPTIONS_DEBUG;OPTIONS_RELEASE" + ) + + if(DEFINED CACHE{Z_VCPKG_CMAKE_GENERATOR}) + message(WARNING "vcpkg_cmake_configure already called; this function should only be called once.") + endif() + + if(DEFINED arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "vcpkg_cmake_buildsystem_build was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") + endif() + if(NOT DEFINED arg_SOURCE_PATH) + message(FATAL_ERROR "SOURCE_PATH must be set") + endif() + if(NOT DEFINED arg_LOGFILE_BASE) + set(arg_LOGFILE_BASE "config") + endif() + + if(CMAKE_HOST_WIN32) + if(DEFINED ENV{PROCESSOR_ARCHITEW6432}) + set(host_architecture "$ENV{PROCESSOR_ARCHITEW6432}") + else() + set(host_architecture "$ENV{PROCESSOR_ARCHITECTURE}") + endif() + endif() + + set(ninja_can_be_used ON) # Ninja as generator + set(ninja_host ON) # Ninja as parallel configurator + + if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore") + set(targetting_uwp ON) + endif() + + if(host_architecture STREQUAL "x86") + # Prebuilt ninja binaries are only provided for x64 hosts + set(ninja_can_be_used OFF) + set(ninja_host OFF) + elseif(targetting_uwp) + # Ninja and MSBuild have many differences when targetting UWP, so use MSBuild to maximize existing compatibility + set(ninja_can_be_used OFF) + endif() + + set(generator) + if(DEFINED arg_GENERATOR) + set(generator "${arg_GENERATOR}") + elseif(arg_WINDOWS_USE_MSBUILD OR NOT ninja_can_be_used) + if(VCPKG_PLATFORM_TOOLSET STREQUAL "v120") + if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") + set(generator "Visual Studio 12 2013") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + set(generator "Visual Studio 12 2013 Win64") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm") + set(generator "Visual Studio 12 2013 ARM") + endif() + elseif(VCPKG_PLATFORM_TOOLSET STREQUAL "v140") + if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") + set(generator "Visual Studio 14 2015") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + set(generator "Visual Studio 14 2015 Win64") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm") + set(generator "Visual Studio 14 2015 ARM") + endif() + elseif(VCPKG_PLATFORM_TOOLSET STREQUAL "v141") + if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") + set(generator "Visual Studio 15 2017") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + set(generator "Visual Studio 15 2017 Win64") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm") + set(generator "Visual Studio 15 2017 ARM") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") + set(generator "Visual Studio 15 2017") + set(arch "ARM64") + endif() + elseif(VCPKG_PLATFORM_TOOLSET STREQUAL "v142") + set(generator "Visual Studio 16 2019") + if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") + set(arch "Win32") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + set(arch "x64") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm") + set(arch "ARM") + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") + set(arch "ARM64") + else() + set(generator) + endif() + endif() + else() + set(generator "Ninja") + endif() + + if(NOT DEFINED generator) + if(NOT VCPKG_CMAKE_SYSTEM_NAME) + set(VCPKG_CMAKE_SYSTEM_NAME Windows) + endif() + message(FATAL_ERROR "Unable to determine appropriate generator for: " + "${VCPKG_CMAKE_SYSTEM_NAME}-${VCPKG_TARGET_ARCHITECTURE}-${VCPKG_PLATFORM_TOOLSET}") + endif() + + # If we use Ninja, make sure it's on PATH + if(generator STREQUAL "Ninja" AND NOT DEFINED ENV{VCPKG_FORCE_SYSTEM_BINARIES}) + vcpkg_find_acquire_program(NINJA) + get_filename_component(ninja_path "${NINJA}" DIRECTORY) + vcpkg_add_to_path("${ninja_path}") + list(APPEND arg_OPTIONS "-DCMAKE_MAKE_PROGRAM=${NINJA}") + endif() + + file(REMOVE_RECURSE + "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel" + "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg") + + if(DEFINED VCPKG_CMAKE_SYSTEM_NAME) + list(APPEND arg_OPTIONS "-DCMAKE_SYSTEM_NAME=${VCPKG_CMAKE_SYSTEM_NAME}") + if(targetting_uwp AND NOT DEFINED VCPKG_CMAKE_SYSTEM_VERSION) + set(VCPKG_CMAKE_SYSTEM_VERSION 10.0) + elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Android" AND NOT DEFINED VCPKG_CMAKE_SYSTEM_VERSION) + set(VCPKG_CMAKE_SYSTEM_VERSION 21) + endif() + endif() + + if(DEFINED VCPKG_CMAKE_SYSTEM_VERSION) + list(APPEND arg_OPTIONS "-DCMAKE_SYSTEM_VERSION=${VCPKG_CMAKE_SYSTEM_VERSION}") + endif() + + if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic") + list(APPEND arg_OPTIONS "-DBUILD_SHARED_LIBS=ON") + elseif(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + list(APPEND arg_OPTIONS "-DBUILD_SHARED_LIBS=OFF") + else() + message(FATAL_ERROR + "Invalid setting for VCPKG_LIBRARY_LINKAGE: \"${VCPKG_LIBRARY_LINKAGE}\". " + "It must be \"static\" or \"dynamic\"") + endif() + + z_vcpkg_cmake_configure_both_set_or_unset(VCPKG_CXX_FLAGS_DEBUG VCPKG_C_FLAGS_DEBUG) + z_vcpkg_cmake_configure_both_set_or_unset(VCPKG_CXX_FLAGS_RELEASE VCPKG_C_FLAGS_RELASE) + z_vcpkg_cmake_configure_both_set_or_unset(VCPKG_CXX_FLAGS VCPKG_C_FLAGS) + + set(VCPKG_SET_CHARSET_FLAG ON) + if(arg_NO_CHARSET_FLAG) + set(VCPKG_SET_CHARSET_FLAG OFF) + endif() + + if(NOT DEFINED VCPKG_CHAINLOAD_TOOLCHAIN_FILE) + if(NOT DEFINED VCPKG_CMAKE_SYSTEM_NAME OR _TARGETTING_UWP) + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/windows.cmake") + elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Linux") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/linux.cmake") + elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Android") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/android.cmake") + elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "Darwin") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/osx.cmake") + elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "iOS") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/ios.cmake") + elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/freebsd.cmake") + elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "OpenBSD") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/openbsd.cmake") + elseif(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "MinGW") + set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${SCRIPTS}/toolchains/mingw.cmake") + endif() + endif() + + + list(APPEND arg_OPTIONS + "-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}" + "-DVCPKG_TARGET_TRIPLET=${TARGET_TRIPLET}" + "-DVCPKG_SET_CHARSET_FLAG=${VCPKG_SET_CHARSET_FLAG}" + "-DVCPKG_PLATFORM_TOOLSET=${VCPKG_PLATFORM_TOOLSET}" + "-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON" + "-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON" + "-DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON" + "-DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=TRUE" + "-DCMAKE_VERBOSE_MAKEFILE=ON" + "-DVCPKG_APPLOCAL_DEPS=OFF" + "-DCMAKE_TOOLCHAIN_FILE=${SCRIPTS}/buildsystems/vcpkg.cmake" + "-DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON" + "-DVCPKG_CXX_FLAGS=${VCPKG_CXX_FLAGS}" + "-DVCPKG_CXX_FLAGS_RELEASE=${VCPKG_CXX_FLAGS_RELEASE}" + "-DVCPKG_CXX_FLAGS_DEBUG=${VCPKG_CXX_FLAGS_DEBUG}" + "-DVCPKG_C_FLAGS=${VCPKG_C_FLAGS}" + "-DVCPKG_C_FLAGS_RELEASE=${VCPKG_C_FLAGS_RELEASE}" + "-DVCPKG_C_FLAGS_DEBUG=${VCPKG_C_FLAGS_DEBUG}" + "-DVCPKG_CRT_LINKAGE=${VCPKG_CRT_LINKAGE}" + "-DVCPKG_LINKER_FLAGS=${VCPKG_LINKER_FLAGS}" + "-DVCPKG_LINKER_FLAGS_RELEASE=${VCPKG_LINKER_FLAGS_RELEASE}" + "-DVCPKG_LINKER_FLAGS_DEBUG=${VCPKG_LINKER_FLAGS_DEBUG}" + "-DVCPKG_TARGET_ARCHITECTURE=${VCPKG_TARGET_ARCHITECTURE}" + "-DCMAKE_INSTALL_LIBDIR:STRING=lib" + "-DCMAKE_INSTALL_BINDIR:STRING=bin" + "-D_VCPKG_ROOT_DIR=${VCPKG_ROOT_DIR}" + "-D_VCPKG_INSTALLED_DIR=${_VCPKG_INSTALLED_DIR}" + "-DVCPKG_MANIFEST_INSTALL=OFF" + ) + + if(DEFINED arch) + list(APPEND arg_OPTIONS "-A${arch}") + endif() + + # Sets configuration variables for macOS builds + foreach(config_var IN ITEMS INSTALL_NAME_DIR OSX_DEPLOYMENT_TARGET OSX_SYSROOT OSX_ARCHITECTURES) + if(DEFINED VCPKG_${config_var}) + list(APPEND arg_OPTIONS "-DCMAKE_${config_var}=${VCPKG_${config_var}}") + endif() + endforeach() + + if(ninja_host AND CMAKE_HOST_WIN32 AND NOT arg_DISABLE_PARALLEL_CONFIGURE) + list(APPEND arg_OPTIONS "-DCMAKE_DISABLE_SOURCE_CHANGES=ON") + + vcpkg_find_acquire_program(NINJA) + + if(NOT DEFINED ninja_path) + # if ninja_path was defined above, we've already done this + get_filename_component(ninja_path "${NINJA}" DIRECTORY) + vcpkg_add_to_path("${ninja_path}") + endif() + + #parallelize the configure step + set(parallel_configure_contents + "rule CreateProcess\n command = $process\n\n" + ) + + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") + set(line "build ../CMakeCache.txt: CreateProcess\n ") + string(APPEND line "process = \"${CMAKE_COMMAND}\" -S \"${arg_SOURCE_PATH}\" -B .. ") + + if(DEFINED arg_OPTIONS AND NOT arg_OPTIONS STREQUAL "") + list(JOIN arg_OPTIONS "\" \"" options) + string(APPEND line "\"${options}\" ") + endif() + if(DEFINED arg_OPTIONS_RELEASE AND NOT arg_OPTIONS_RELEASE STREQUAL "") + list(JOIN arg_OPTIONS_RELEASE "\" \"" options_rel) + string(APPEND line "\"${options_rel}\" ") + endif() + string(APPEND line "-G \"${generator}\" ") + string(APPEND line "\"-DCMAKE_BUILD_TYPE=Release\" ") + string(APPEND line "\"-DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}\"") + string(APPEND parallel_configure_contents "${line}\n\n") + endif() + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + set(line "build ../../${TARGET_TRIPLET}-dbg/CMakeCache.txt: CreateProcess\n ") + string(APPEND line "process = \"${CMAKE_COMMAND}\" -S \"${arg_SOURCE_PATH}\" -B \"../../${TARGET_TRIPLET}-dbg\" ") + + if(DEFINED arg_OPTIONS AND NOT arg_OPTIONS STREQUAL "") + list(JOIN arg_OPTIONS "\" \"" options) + string(APPEND line "\"${options}\" ") + endif() + if(DEFINED arg_OPTIONS_DEBUG AND NOT arg_OPTIONS_DEBUG STREQUAL "") + list(JOIN arg_OPTIONS_DEBUG "\" \"" options_dbg) + string(APPEND line "\"${options_dbg}\" ") + endif() + string(APPEND line "-G \"${generator}\" ") + string(APPEND line "\"-DCMAKE_BUILD_TYPE=Debug\" ") + string(APPEND line "\"-DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}/debug\"") + string(APPEND parallel_configure_contents "${line}\n\n") + endif() + + file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vcpkg-parallel-configure") + file(WRITE "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vcpkg-parallel-configure/build.ninja" "${parallel_configure_contents}") + + message(STATUS "Configuring ${TARGET_TRIPLET}") + vcpkg_execute_required_process( + COMMAND ninja -v + WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vcpkg-parallel-configure" + LOGNAME "${arg_LOGFILE_BASE}-${TARGET_TRIPLET}" + ) + else() + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + message(STATUS "Configuring ${TARGET_TRIPLET}-dbg") + file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg") + vcpkg_execute_required_process( + COMMAND + "${CMAKE_COMMAND}" "${arg_SOURCE_PATH}" + ${arg_OPTIONS} + ${arg_OPTIONS_DEBUG} + -G "${generator}" + "-DCMAKE_BUILD_TYPE=Debug" + "-DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}/debug" + WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg" + LOGNAME "${arg_LOGFILE_BASE}-${TARGET_TRIPLET}-dbg" + ) + endif() + + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") + message(STATUS "Configuring ${TARGET_TRIPLET}-rel") + file(MAKE_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel") + vcpkg_execute_required_process( + COMMAND + "${CMAKE_COMMAND}" "${arg_SOURCE_PATH}" + ${arg_OPTIONS} + ${arg_OPTIONS_RELEASE} + -G "${generator}" + "-DCMAKE_BUILD_TYPE=Release" + "-DCMAKE_INSTALL_PREFIX=${CURRENT_PACKAGES_DIR}" + WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel" + LOGNAME "${arg_LOGFILE_BASE}-rel" + ) + endif() + endif() + + set(Z_VCPKG_CMAKE_GENERATOR "${generator}" CACHE INTERNAL "The generator which was used to configure CMake.") +endfunction() diff --git a/ports/vcpkg-cmake/vcpkg_cmake_install.cmake b/ports/vcpkg-cmake/vcpkg_cmake_install.cmake new file mode 100644 index 000000000..0a609aa8d --- /dev/null +++ b/ports/vcpkg-cmake/vcpkg_cmake_install.cmake @@ -0,0 +1,46 @@ +#[===[.md: +# vcpkg_cmake_install + +Build and install a cmake project. + +```cmake +vcpkg_cmake_install( + [DISABLE_PARALLEL] + [ADD_BIN_TO_PATH] +) +``` + +`vcpkg_cmake_install` transparently forwards to [`vcpkg_cmake_build()`], +with additional parameters to set the `TARGET` to `install`, +and to set the `LOGFILE_ROOT` to `install` as well. + +[`vcpkg_cmake_build()`]: vcpkg_cmake_build.cmake + +## Examples: + +* [zlib](https://github.com/Microsoft/vcpkg/blob/master/ports/zlib/portfile.cmake) +#]===] +if(Z_VCPKG_CMAKE_INSTALL_GUARD) + return() +endif() +set(Z_VCPKG_CMAKE_INSTALL_GUARD ON CACHE INTERNAL "guard variable") + +function(vcpkg_cmake_install) + cmake_parse_arguments(PARSE_ARGV 0 "arg" "DISABLE_PARALLEL;ADD_BIN_TO_PATH" "" "") + if(DEFINED arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "vcpkg_cmake_install was passed extra arguments: ${arg_UNPARSED_ARGUMENTS}") + endif() + + set(args) + foreach(arg IN ITEMS DISABLE_PARALLEL ADD_BIN_TO_PATH) + if(arg_${arg}) + list(APPEND args "${arg}") + endif() + endforeach() + + vcpkg_cmake_build( + ${args} + LOGFILE_BASE install + TARGET install + ) +endfunction() |
