diff options
Diffstat (limited to 'scripts/cmake')
25 files changed, 1024 insertions, 154 deletions
diff --git a/scripts/cmake/vcpkg_acquire_msys.cmake b/scripts/cmake/vcpkg_acquire_msys.cmake index eec08e3f1..ed4f7ac29 100644 --- a/scripts/cmake/vcpkg_acquire_msys.cmake +++ b/scripts/cmake/vcpkg_acquire_msys.cmake @@ -39,6 +39,10 @@ function(vcpkg_acquire_msys PATH_TO_ROOT_OUT) set(TOOLPATH ${DOWNLOADS}/tools/msys2) cmake_parse_arguments(_am "" "" "PACKAGES" ${ARGN}) + if(NOT CMAKE_HOST_WIN32) + message(FATAL_ERROR "vcpkg_acquire_msys() can only be used on Windows hosts") + endif() + # detect host architecture if(DEFINED ENV{PROCESSOR_ARCHITEW6432}) set(_vam_HOST_ARCHITECTURE $ENV{PROCESSOR_ARCHITEW6432}) diff --git a/scripts/cmake/vcpkg_add_to_path.cmake b/scripts/cmake/vcpkg_add_to_path.cmake new file mode 100644 index 000000000..6890dfe31 --- /dev/null +++ b/scripts/cmake/vcpkg_add_to_path.cmake @@ -0,0 +1,41 @@ +## # vcpkg_add_to_path
+##
+## Add a directory to the PATH environment variable
+##
+## ## Usage
+## ```cmake
+## vcpkg_add_to_path([PREPEND] <${PYTHON3_DIR}>)
+## ```
+##
+## ## Parameters
+## ### <positional>
+## The directory to add
+##
+## ### PREPEND
+## Prepends the directory.
+##
+## The default is to append.
+function(vcpkg_add_to_path)
+ if(NOT "${ARGC}" STREQUAL "1" AND NOT "${ARGC}" STREQUAL "2")
+ message(FATAL_ERROR "vcpkg_add_to_path() only accepts 1 or 2 arguments.")
+ endif()
+ if("${ARGV0}" STREQUAL "PREPEND")
+ if(NOT "${ARGC}" STREQUAL "2")
+ message(FATAL_ERROR "Expected second argument.")
+ endif()
+ if(CMAKE_HOST_WIN32)
+ set(ENV{PATH} "${ARGV1};$ENV{PATH}")
+ else()
+ set(ENV{PATH} "${ARGV1}:$ENV{PATH}")
+ endif()
+ else()
+ if(NOT "${ARGC}" STREQUAL "1")
+ message(FATAL_ERROR "Unexpected second argument: ${ARGV1}")
+ endif()
+ if(CMAKE_HOST_WIN32)
+ set(ENV{PATH} "$ENV{PATH};${ARGV0}")
+ else()
+ set(ENV{PATH} "$ENV{PATH}:${ARGV0}")
+ endif()
+ endif()
+endfunction()
\ No newline at end of file diff --git a/scripts/cmake/vcpkg_apply_patches.cmake b/scripts/cmake/vcpkg_apply_patches.cmake index 1894d6e9a..ac0b78e20 100644 --- a/scripts/cmake/vcpkg_apply_patches.cmake +++ b/scripts/cmake/vcpkg_apply_patches.cmake @@ -37,10 +37,11 @@ function(vcpkg_apply_patches) find_program(GIT NAMES git git.cmd) set(PATCHNUM 0) foreach(PATCH ${_ap_PATCHES}) + get_filename_component(ABSOLUTE_PATCH "${PATCH}" ABSOLUTE BASE_DIR "${CURRENT_PORT_DIR}") message(STATUS "Applying patch ${PATCH}") set(LOGNAME patch-${TARGET_TRIPLET}-${PATCHNUM}) execute_process( - COMMAND ${GIT} --work-tree=. --git-dir=.git apply "${PATCH}" --ignore-whitespace --whitespace=nowarn --verbose + COMMAND ${GIT} --work-tree=. --git-dir=.git apply "${ABSOLUTE_PATCH}" --ignore-whitespace --whitespace=nowarn --verbose OUTPUT_FILE ${CURRENT_BUILDTREES_DIR}/${LOGNAME}-out.log ERROR_FILE ${CURRENT_BUILDTREES_DIR}/${LOGNAME}-err.log WORKING_DIRECTORY ${_ap_SOURCE_PATH} @@ -51,7 +52,6 @@ function(vcpkg_apply_patches) message(STATUS "Applying patch failed. This is expected if this patch was previously applied.") endif() - message(STATUS "Applying patch ${PATCH} done") math(EXPR PATCHNUM "${PATCHNUM}+1") endforeach() endfunction() diff --git a/scripts/cmake/vcpkg_build_cmake.cmake b/scripts/cmake/vcpkg_build_cmake.cmake index 983ac9221..2f0da07f9 100644 --- a/scripts/cmake/vcpkg_build_cmake.cmake +++ b/scripts/cmake/vcpkg_build_cmake.cmake @@ -74,16 +74,21 @@ function(vcpkg_build_cmake) set(CONFIG "Release") endif() - message(STATUS "Build ${TARGET_TRIPLET}-${SHORT_BUILDTYPE}") + message(STATUS "Building ${TARGET_TRIPLET}-${SHORT_BUILDTYPE}") set(LOGPREFIX "${CURRENT_BUILDTREES_DIR}/${_bc_LOGFILE_ROOT}-${TARGET_TRIPLET}-${SHORT_BUILDTYPE}") set(LOGS) if(_bc_ADD_BIN_TO_PATH) set(_BACKUP_ENV_PATH "$ENV{PATH}") + if(CMAKE_HOST_WIN32) + set(_PATHSEP ";") + else() + set(_PATHSEP ":") + endif() if(BUILDTYPE STREQUAL "debug") - set(ENV{PATH} "${CURRENT_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/bin;$ENV{PATH}") + set(ENV{PATH} "${CURRENT_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/debug/bin${_PATHSEP}$ENV{PATH}") else() - set(ENV{PATH} "${CURRENT_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin;$ENV{PATH}") + set(ENV{PATH} "${CURRENT_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin${_PATHSEP}$ENV{PATH}") endif() endif() execute_process( @@ -174,7 +179,6 @@ function(vcpkg_build_cmake) ${STRINGIFIED_LOGS}) endif() endif() - message(STATUS "Build ${TARGET_TRIPLET}-${SHORT_BUILDTYPE} done") if(_bc_ADD_BIN_TO_PATH) set(ENV{PATH} "${_BACKUP_ENV_PATH}") endif() diff --git a/scripts/cmake/vcpkg_build_msbuild.cmake b/scripts/cmake/vcpkg_build_msbuild.cmake index db04530ef..7a65127f0 100644 --- a/scripts/cmake/vcpkg_build_msbuild.cmake +++ b/scripts/cmake/vcpkg_build_msbuild.cmake @@ -1,6 +1,6 @@ ## # vcpkg_build_msbuild ## -## Build an msbuild-based project. +## Build an msbuild-based project. Deprecated in favor of `vcpkg_install_msbuild()`. ## ## ## Usage ## ```cmake @@ -15,6 +15,7 @@ ## [OPTIONS </p:ZLIB_INCLUDE_PATH=X>...] ## [OPTIONS_RELEASE </p:ZLIB_LIB=X>...] ## [OPTIONS_DEBUG </p:ZLIB_LIB=X>...] +## [USE_VCPKG_INTEGRATION] ## ) ## ``` ## @@ -105,7 +106,11 @@ function(vcpkg_build_msbuild) endif() if(_csc_USE_VCPKG_INTEGRATION) - list(APPEND _csc_OPTIONS /p:ForceImportBeforeCppTargets=${VCPKG_ROOT_DIR}/scripts/buildsystems/msbuild/vcpkg.targets) + list( + APPEND _csc_OPTIONS + /p:ForceImportBeforeCppTargets=${VCPKG_ROOT_DIR}/scripts/buildsystems/msbuild/vcpkg.targets + "/p:VcpkgTriplet=${TARGET_TRIPLET}" + ) endif() if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") diff --git a/scripts/cmake/vcpkg_build_qmake.cmake b/scripts/cmake/vcpkg_build_qmake.cmake index 194ab8206..189a1113b 100644 --- a/scripts/cmake/vcpkg_build_qmake.cmake +++ b/scripts/cmake/vcpkg_build_qmake.cmake @@ -33,7 +33,6 @@ function(vcpkg_build_qmake) WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-${LOG_SUFFIX} LOGNAME package-${LOG_PREFIX}-${TARGET_TRIPLET}-${LOG_SUFFIX} ) - message(STATUS "Package ${LOG_PREFIX}-${TARGET_TRIPLET}-${LOG_SUFFIX} done") endfunction() # This fixes issues on machines with default codepages that are not ASCII compatible, such as some CJK encodings @@ -53,6 +52,11 @@ function(vcpkg_build_qmake) string(REPLACE "zlib.lib" "zlibd.lib" _contents "${_contents}") string(REPLACE "installed\\${TARGET_TRIPLET}\\lib" "installed\\${TARGET_TRIPLET}\\debug\\lib" _contents "${_contents}") string(REPLACE "/LIBPATH:${NATIVE_INSTALLED_DIR}\\debug\\lib qtmaind.lib" "shell32.lib /LIBPATH:${NATIVE_INSTALLED_DIR}\\debug\\lib\\manual-link qtmaind.lib /LIBPATH:${NATIVE_INSTALLED_DIR}\\debug\\lib" _contents "${_contents}") + string(REPLACE "tools\\qt5\\qmlcachegen.exe" "tools\\qt5-declarative\\qmlcachegen.exe" _contents "${_contents}") + string(REPLACE "tools/qt5/qmlcachegen" "tools/qt5-declarative/qmlcachegen" _contents "${_contents}") + string(REPLACE "debug\\lib\\Qt5Bootstrap.lib" "tools\\qt5\\Qt5Bootstrap.lib" _contents "${_contents}") + string(REPLACE "lib\\Qt5Bootstrap.lib" "tools\\qt5\\Qt5Bootstrap.lib" _contents "${_contents}") + string(REPLACE " Qt5Bootstrap.lib " " ${NATIVE_INSTALLED_DIR}\\tools\\qt5\\Qt5Bootstrap.lib Ole32.lib Netapi32.lib Advapi32.lib ${NATIVE_INSTALLED_DIR}\\lib\\zlib.lib Shell32.lib " _contents "${_contents}") file(WRITE "${DEBUG_MAKEFILE}" "${_contents}") endforeach() endif() @@ -69,6 +73,11 @@ function(vcpkg_build_qmake) foreach(RELEASE_MAKEFILE ${RELEASE_MAKEFILES}) file(READ "${RELEASE_MAKEFILE}" _contents) string(REPLACE "/LIBPATH:${NATIVE_INSTALLED_DIR}\\lib qtmain.lib" "shell32.lib /LIBPATH:${NATIVE_INSTALLED_DIR}\\lib\\manual-link qtmain.lib /LIBPATH:${NATIVE_INSTALLED_DIR}\\lib" _contents "${_contents}") + string(REPLACE "tools\\qt5\\qmlcachegen.exe" "tools\\qt5-declarative\\qmlcachegen.exe" _contents "${_contents}") + string(REPLACE "tools/qt5/qmlcachegen" "tools/qt5-declarative/qmlcachegen" _contents "${_contents}") + string(REPLACE "debug\\lib\\Qt5Bootstrap.lib" "tools\\qt5\\Qt5Bootstrap.lib" _contents "${_contents}") + string(REPLACE "lib\\Qt5Bootstrap.lib" "tools\\qt5\\Qt5Bootstrap.lib" _contents "${_contents}") + string(REPLACE " Qt5Bootstrap.lib " " ${NATIVE_INSTALLED_DIR}\\tools\\qt5\\Qt5Bootstrap.lib Ole32.lib Netapi32.lib Advapi32.lib ${NATIVE_INSTALLED_DIR}\\lib\\zlib.lib Shell32.lib " _contents "${_contents}") file(WRITE "${RELEASE_MAKEFILE}" "${_contents}") endforeach() endif() diff --git a/scripts/cmake/vcpkg_check_linkage.cmake b/scripts/cmake/vcpkg_check_linkage.cmake new file mode 100644 index 000000000..101adc4fd --- /dev/null +++ b/scripts/cmake/vcpkg_check_linkage.cmake @@ -0,0 +1,53 @@ +## # vcpkg_check_linkage
+##
+## Asserts the available library and CRT linkage options for the port.
+##
+## ## Usage
+## ```cmake
+## vcpkg_check_linkage(
+## [ONLY_STATIC_LIBRARY | ONLY_DYNAMIC_LIBRARY]
+## [ONLY_STATIC_CRT | ONLY_DYNAMIC_CRT]
+## )
+## ```
+##
+## ## Parameters
+## ### ONLY_STATIC_LIBRARY
+## Indicates that this port can only be built with static library linkage.
+##
+## ### ONLY_DYNAMIC_LIBRARY
+## Indicates that this port can only be built with dynamic/shared library linkage.
+##
+## ### ONLY_STATIC_CRT
+## Indicates that this port can only be built with static CRT linkage.
+##
+## ### ONLY_DYNAMIC_CRT
+## Indicates that this port can only be built with dynamic/shared CRT linkage.
+##
+## ## Notes
+## This command will either alter the settings for `VCPKG_LIBRARY_LINKAGE` or fail, depending on what was requested by the user versus what the library supports.
+##
+## ## Examples
+##
+## * [libimobiledevice](https://github.com/Microsoft/vcpkg/blob/master/ports/libimobiledevice/portfile.cmake)
+function(vcpkg_check_linkage)
+ cmake_parse_arguments(_csc "ONLY_STATIC_LIBRARY;ONLY_DYNAMIC_LIBRARY;ONLY_DYNAMIC_CRT;ONLY_STATIC_CRT" "" "" ${ARGN})
+
+ if(_csc_ONLY_STATIC_LIBRARY AND VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
+ message(STATUS "Note: ${PORT} only supports static library linkage. Building static library.")
+ set(VCPKG_LIBRARY_LINKAGE static PARENT_SCOPE)
+ endif()
+ if(_csc_ONLY_DYNAMIC_LIBRARY AND VCPKG_LIBRARY_LINKAGE STREQUAL "static")
+ message(STATUS "Note: ${PORT} only supports dynamic library linkage. Building dynamic library.")
+ if(VCPKG_CRT_LINKAGE STREQUAL "static")
+ message(FATAL_ERROR "Refusing to build unexpected dynamic library against the static CRT. If this is desired, please configure your triplet to directly request this configuration.")
+ endif()
+ set(VCPKG_LIBRARY_LINKAGE dynamic PARENT_SCOPE)
+ endif()
+
+ if(_csc_ONLY_DYNAMIC_CRT AND VCPKG_CRT_LINKAGE STREQUAL "static")
+ message(FATAL_ERROR "${PORT} only supports dynamic crt linkage")
+ endif()
+ if(_csc_ONLY_STATIC_CRT AND VCPKG_CRT_LINKAGE STREQUAL "dynamic")
+ message(FATAL_ERROR "${PORT} only supports static crt linkage")
+ endif()
+endfunction()
diff --git a/scripts/cmake/vcpkg_clean_msbuild.cmake b/scripts/cmake/vcpkg_clean_msbuild.cmake new file mode 100644 index 000000000..b0d77dfd2 --- /dev/null +++ b/scripts/cmake/vcpkg_clean_msbuild.cmake @@ -0,0 +1,19 @@ +## # vcpkg_clean_msbuild +## +## Clean intermediate files generated by `vcpkg_install_msbuild()`. +## +## ## Usage +## ```cmake +## vcpkg_clean_msbuild() +## ``` +## +## ## Examples +## +## * [xalan-c](https://github.com/Microsoft/vcpkg/blob/master/ports/xalan-c/portfile.cmake) + +function(vcpkg_clean_msbuild) + file(REMOVE_RECURSE + ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg + ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel + ) +endfunction() diff --git a/scripts/cmake/vcpkg_common_functions.cmake b/scripts/cmake/vcpkg_common_functions.cmake index 27dd0732d..d66fc5eff 100644 --- a/scripts/cmake/vcpkg_common_functions.cmake +++ b/scripts/cmake/vcpkg_common_functions.cmake @@ -1,17 +1,23 @@ include(vcpkg_acquire_msys) +include(vcpkg_add_to_path) +include(vcpkg_check_linkage) +include(vcpkg_clean_msbuild) include(vcpkg_download_distfile) include(vcpkg_extract_source_archive) +include(vcpkg_extract_source_archive_ex) include(vcpkg_execute_required_process) include(vcpkg_execute_required_process_repeat) include(vcpkg_find_acquire_program) include(vcpkg_fixup_cmake_targets) include(vcpkg_from_github) +include(vcpkg_from_gitlab) include(vcpkg_from_bitbucket) include(vcpkg_build_cmake) include(vcpkg_build_msbuild) include(vcpkg_build_qmake) include(vcpkg_install_cmake) include(vcpkg_install_meson) +include(vcpkg_install_msbuild) include(vcpkg_configure_cmake) include(vcpkg_configure_meson) include(vcpkg_configure_qmake) @@ -21,4 +27,6 @@ include(vcpkg_copy_tool_dependencies) include(vcpkg_get_program_files_32_bit) include(vcpkg_get_program_files_platform_bitness) include(vcpkg_get_windows_sdk) -include(vcpkg_replace_string)
\ No newline at end of file +include(vcpkg_replace_string) +include(vcpkg_from_git) +include(vcpkg_test_cmake) diff --git a/scripts/cmake/vcpkg_configure_cmake.cmake b/scripts/cmake/vcpkg_configure_cmake.cmake index 3e0922428..617fe1a0f 100644 --- a/scripts/cmake/vcpkg_configure_cmake.cmake +++ b/scripts/cmake/vcpkg_configure_cmake.cmake @@ -62,6 +62,12 @@ function(vcpkg_configure_cmake) set(_csc_HOST_ARCHITECTURE $ENV{PROCESSOR_ARCHITECTURE}) endif() + if(CMAKE_HOST_WIN32) + set(_PATHSEP ";") + else() + set(_PATHSEP ":") + endif() + set(NINJA_CAN_BE_USED ON) # Ninja as generator set(NINJA_HOST ON) # Ninja as parallel configurator if(_csc_HOST_ARCHITECTURE STREQUAL "x86") @@ -114,7 +120,7 @@ function(vcpkg_configure_cmake) if(GENERATOR STREQUAL "Ninja") vcpkg_find_acquire_program(NINJA) get_filename_component(NINJA_PATH ${NINJA} DIRECTORY) - set(ENV{PATH} "$ENV{PATH};${NINJA_PATH}") + set(ENV{PATH} "$ENV{PATH}${_PATHSEP}${NINJA_PATH}") list(APPEND _csc_OPTIONS "-DCMAKE_MAKE_PROGRAM=${NINJA}") endif() @@ -122,6 +128,9 @@ function(vcpkg_configure_cmake) if(DEFINED VCPKG_CMAKE_SYSTEM_NAME) list(APPEND _csc_OPTIONS "-DCMAKE_SYSTEM_NAME=${VCPKG_CMAKE_SYSTEM_NAME}") + if(VCPKG_CMAKE_SYSTEM_NAME STREQUAL "WindowsStore" AND NOT DEFINED VCPKG_CMAKE_SYSTEM_VERSION) + set(VCPKG_CMAKE_SYSTEM_VERSION 10.0) + endif() endif() if(DEFINED VCPKG_CMAKE_SYSTEM_VERSION) list(APPEND _csc_OPTIONS "-DCMAKE_SYSTEM_VERSION=${VCPKG_CMAKE_SYSTEM_VERSION}") @@ -192,6 +201,17 @@ function(vcpkg_configure_cmake) ) endif() + # Sets configuration variables for macOS builds + if(DEFINED VCPKG_INSTALL_NAME_DIR) + list(APPEND _csc_OPTIONS "-DCMAKE_INSTALL_NAME_DIR=${VCPKG_INSTALL_NAME_DIR}") + endif() + if(DEFINED VCPKG_OSX_DEPLOYMENT_TARGET) + list(APPEND _csc_OPTIONS "-DCMAKE_OSX_DEPLOYMENT_TARGET=${VCPKG_OSX_DEPLOYMENT_TARGET}") + endif() + if(DEFINED VCPKG_OSX_SYSROOT) + list(APPEND _csc_OPTIONS "-DCMAKE_OSX_SYSROOT=${VCPKG_OSX_SYSROOT}") + endif() + set(rel_command ${CMAKE_COMMAND} ${_csc_SOURCE_PATH} "${_csc_OPTIONS}" "${_csc_OPTIONS_RELEASE}" -G ${GENERATOR} @@ -207,7 +227,7 @@ function(vcpkg_configure_cmake) vcpkg_find_acquire_program(NINJA) get_filename_component(NINJA_PATH ${NINJA} DIRECTORY) - set(ENV{PATH} "$ENV{PATH};${NINJA_PATH}") + set(ENV{PATH} "$ENV{PATH}${_PATHSEP}${NINJA_PATH}") #parallelize the configure step set(_contents @@ -239,7 +259,6 @@ function(vcpkg_configure_cmake) WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/vcpkg-parallel-configure LOGNAME config-${TARGET_TRIPLET} ) - message(STATUS "Configuring ${TARGET_TRIPLET} done") else() if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") message(STATUS "Configuring ${TARGET_TRIPLET}-dbg") @@ -249,7 +268,6 @@ function(vcpkg_configure_cmake) WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg LOGNAME config-${TARGET_TRIPLET}-dbg ) - message(STATUS "Configuring ${TARGET_TRIPLET}-dbg done") endif() if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") @@ -260,7 +278,6 @@ function(vcpkg_configure_cmake) WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel LOGNAME config-${TARGET_TRIPLET}-rel ) - message(STATUS "Configuring ${TARGET_TRIPLET}-rel done") endif() endif() diff --git a/scripts/cmake/vcpkg_configure_meson.cmake b/scripts/cmake/vcpkg_configure_meson.cmake index 9b87261d5..3c6903c9d 100644 --- a/scripts/cmake/vcpkg_configure_meson.cmake +++ b/scripts/cmake/vcpkg_configure_meson.cmake @@ -39,7 +39,12 @@ function(vcpkg_configure_meson) vcpkg_find_acquire_program(MESON) vcpkg_find_acquire_program(NINJA) get_filename_component(NINJA_PATH ${NINJA} DIRECTORY) - set(ENV{PATH} "$ENV{PATH};${NINJA_PATH}") + if(CMAKE_HOST_WIN32) + set(_PATHSEP ";") + else() + set(_PATHSEP ":") + endif() + set(ENV{PATH} "$ENV{PATH}${_PATHSEP}${NINJA_PATH}") # configure release if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") diff --git a/scripts/cmake/vcpkg_copy_pdbs.cmake b/scripts/cmake/vcpkg_copy_pdbs.cmake index ca55eb015..4e9f642b5 100644 --- a/scripts/cmake/vcpkg_copy_pdbs.cmake +++ b/scripts/cmake/vcpkg_copy_pdbs.cmake @@ -4,17 +4,32 @@ ## ## ## Usage ## ```cmake -## vcpkg_copy_pdbs() +## vcpkg_copy_pdbs([BUILD_PATHS <${CURRENT_PACKAGES_DIR}/bin/*.dll> ...]) ## ``` ## ## ## Notes ## This command should always be called by portfiles after they have finished rearranging the binary output. ## +## ## Parameters +## ### BUILD_PATHS +## Path patterns passed to `file(GLOB_RECURSE)` for locating dlls. +## +## Defaults to `${CURRENT_PACKAGES_DIR}/bin/*.dll` and `${CURRENT_PACKAGES_DIR}/debug/bin/*.dll`. +## ## ## 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) function(vcpkg_copy_pdbs) + cmake_parse_arguments(_vcp "" "" "BUILD_PATHS" ${ARGN}) + + if(NOT _vcp_BUILD_PATHS) + set( + _vcp_BUILD_PATHS + ${CURRENT_PACKAGES_DIR}/bin/*.dll + ${CURRENT_PACKAGES_DIR}/debug/bin/*.dll + ) + endif() function(merge_filelist OUTVAR INVAR) set(MSG "") @@ -25,7 +40,7 @@ function(vcpkg_copy_pdbs) endfunction() if(VCPKG_LIBRARY_LINKAGE STREQUAL dynamic) - file(GLOB_RECURSE DLLS ${CURRENT_PACKAGES_DIR}/bin/*.dll ${CURRENT_PACKAGES_DIR}/debug/bin/*.dll) + file(GLOB_RECURSE DLLS ${_vcp_BUILD_PATHS}) set(DLLS_WITHOUT_MATCHING_PDBS) diff --git a/scripts/cmake/vcpkg_download_distfile.cmake b/scripts/cmake/vcpkg_download_distfile.cmake index 9fc0a0c9a..949036c88 100644 --- a/scripts/cmake/vcpkg_download_distfile.cmake +++ b/scripts/cmake/vcpkg_download_distfile.cmake @@ -68,7 +68,12 @@ function(vcpkg_download_distfile VAR) set(downloaded_file_path ${DOWNLOADS}/${vcpkg_download_distfile_FILENAME}) set(download_file_path_part "${DOWNLOADS}/temp/${vcpkg_download_distfile_FILENAME}") - file(REMOVE_RECURSE "${DOWNLOADS}/temp") + # Works around issue #3399 + if(IS_DIRECTORY "${DOWNLOADS}/temp") + file(REMOVE_RECURSE "${DOWNLOADS}/temp0") + file(RENAME "${DOWNLOADS}/temp" "${DOWNLOADS}/temp0") + file(REMOVE_RECURSE "${DOWNLOADS}/temp0") + endif() file(MAKE_DIRECTORY "${DOWNLOADS}/temp") function(test_hash FILE_PATH FILE_KIND CUSTOM_ERROR_ADVICE) @@ -81,9 +86,8 @@ function(vcpkg_download_distfile VAR) return() endif() - message(STATUS "Testing integrity of ${FILE_KIND}...") file(SHA512 ${FILE_PATH} FILE_HASH) - if(NOT "${FILE_HASH}" STREQUAL "${vcpkg_download_distfile_SHA512}") + if(NOT FILE_HASH STREQUAL vcpkg_download_distfile_SHA512) message(FATAL_ERROR "\nFile does not have expected hash:\n" " File path: [ ${FILE_PATH} ]\n" @@ -91,10 +95,9 @@ function(vcpkg_download_distfile VAR) " Actual hash: [ ${FILE_HASH} ]\n" "${CUSTOM_ERROR_ADVICE}\n") endif() - message(STATUS "Testing integrity of ${FILE_KIND}... OK") endfunction() - if(EXISTS ${downloaded_file_path}) + if(EXISTS "${downloaded_file_path}") message(STATUS "Using cached ${downloaded_file_path}") test_hash("${downloaded_file_path}" "cached file" "Please delete the file and retry if this file should be downloaded again.") else() @@ -104,7 +107,7 @@ function(vcpkg_download_distfile VAR) # Tries to download the file. list(GET vcpkg_download_distfile_URLS 0 SAMPLE_URL) - if(${_VCPKG_DOWNLOAD_TOOL} MATCHES "ARIA2" AND NOT ${SAMPLE_URL} MATCHES "aria2") + if(_VCPKG_DOWNLOAD_TOOL STREQUAL "ARIA2" AND NOT SAMPLE_URL MATCHES "aria2") vcpkg_find_acquire_program("ARIA2") message(STATUS "Downloading ${vcpkg_download_distfile_FILENAME}...") execute_process( @@ -127,7 +130,6 @@ function(vcpkg_download_distfile VAR) ) set(download_success 0) else() - message(STATUS "Downloading ${vcpkg_download_distfile_FILENAME}... OK") file(REMOVE ${DOWNLOADS}/download-${vcpkg_download_distfile_FILENAME}-out.log ${DOWNLOADS}/download-${vcpkg_download_distfile_FILENAME}-err.log @@ -144,7 +146,6 @@ function(vcpkg_download_distfile VAR) message(STATUS "Downloading ${url}... Failed. Status: ${download_status}") set(download_success 0) else() - message(STATUS "Downloading ${url}... OK") set(download_success 1) break() endif() diff --git a/scripts/cmake/vcpkg_extract_source_archive.cmake b/scripts/cmake/vcpkg_extract_source_archive.cmake index 5c16616c6..a55419b19 100644 --- a/scripts/cmake/vcpkg_extract_source_archive.cmake +++ b/scripts/cmake/vcpkg_extract_source_archive.cmake @@ -1,6 +1,6 @@ ## # vcpkg_extract_source_archive ## -## Extract an archive into the source directory. +## Extract an archive into the source directory. Deprecated in favor of [`vcpkg_extract_source_archive_ex`](vcpkg_extract_source_archive_ex.md). ## ## ## Usage ## ```cmake @@ -29,40 +29,22 @@ ## * [msgpack](https://github.com/Microsoft/vcpkg/blob/master/ports/msgpack/portfile.cmake) include(vcpkg_execute_required_process) -function(vcpkg_extract_source_archive_ex) - cmake_parse_arguments(_vesae "" "ARCHIVE;WORKING_DIRECTORY" "" ${ARGN}) - - if(NOT _vesae_ARCHIVE) - message(FATAL_ERROR "Must specify ARCHIVE parameter to vcpkg_extract_source_archive_ex()") - endif() - - if(DEFINED _vesae_WORKING_DIRECTORY) - set(WORKING_DIRECTORY ${_vesae_WORKING_DIRECTORY}) +function(vcpkg_extract_source_archive ARCHIVE) + if(NOT ARGC EQUAL 2) + set(WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/src") else() - set(WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/src) + set(WORKING_DIRECTORY ${ARGV1}) endif() - get_filename_component(ARCHIVE_FILENAME ${_vesae_ARCHIVE} NAME) + get_filename_component(ARCHIVE_FILENAME "${ARCHIVE}" NAME) if(NOT EXISTS ${WORKING_DIRECTORY}/${ARCHIVE_FILENAME}.extracted) - message(STATUS "Extracting source ${_vesae_ARCHIVE}") + message(STATUS "Extracting source ${ARCHIVE}") file(MAKE_DIRECTORY ${WORKING_DIRECTORY}) vcpkg_execute_required_process( - COMMAND ${CMAKE_COMMAND} -E tar xjf ${_vesae_ARCHIVE} + COMMAND ${CMAKE_COMMAND} -E tar xjf ${ARCHIVE} WORKING_DIRECTORY ${WORKING_DIRECTORY} LOGNAME extract ) file(WRITE ${WORKING_DIRECTORY}/${ARCHIVE_FILENAME}.extracted) endif() - message(STATUS "Extracting done") endfunction() - -function(vcpkg_extract_source_archive ARCHIVE) - if(NOT ARGC EQUAL 2) - vcpkg_extract_source_archive_ex(ARCHIVE ${ARCHIVE}) - else() - vcpkg_extract_source_archive_ex( - ARCHIVE ${ARCHIVE} - WORKING_DIRECTORY ${ARGV1} - ) - endif() -endfunction()
\ No newline at end of file diff --git a/scripts/cmake/vcpkg_extract_source_archive_ex.cmake b/scripts/cmake/vcpkg_extract_source_archive_ex.cmake new file mode 100644 index 000000000..a70a5e4a3 --- /dev/null +++ b/scripts/cmake/vcpkg_extract_source_archive_ex.cmake @@ -0,0 +1,130 @@ +## # vcpkg_extract_source_archive_ex
+##
+## Extract an archive into the source directory. Replaces [`vcpkg_extract_source_archive`](vcpkg_extract_source_archive.md).
+##
+## ## Usage
+## ```cmake
+## vcpkg_extract_source_archive_ex(
+## OUT_SOURCE_PATH <SOURCE_PATH>
+## ARCHIVE <${ARCHIVE}>
+## [REF <1.0.0>]
+## [NO_REMOVE_ONE_LEVEL]
+## [WORKING_DIRECTORY <${CURRENT_BUILDTREES_DIR}/src>]
+## [PATCHES <a.patch>...]
+## )
+## ```
+## ## Parameters
+## ### OUT_SOURCE_PATH
+## Specifies the out-variable that will contain the extracted location.
+##
+## This should be set to `SOURCE_PATH` by convention.
+##
+## ### ARCHIVE
+## The full path to the archive to be extracted.
+##
+## This is usually obtained from calling [`vcpkg_download_distfile`](vcpkg_download_distfile.md).
+##
+## ### REF
+## A friendly name that will be used instead of the filename of the archive.
+##
+## By convention, this is set to the version number or tag fetched
+##
+## ### WORKING_DIRECTORY
+## If specified, the archive will be extracted into the working directory instead of `${CURRENT_BUILDTREES_DIR}/src/`.
+##
+## Note that the archive will still be extracted into a subfolder underneath that directory (`${WORKING_DIRECTORY}/${REF}-${HASH}/`).
+##
+## ### PATCHES
+## A list of patches to be applied to the extracted sources.
+##
+## Relative paths are based on the port directory.
+##
+## ### NO_REMOVE_ONE_LEVEL
+## Specifies that the default removal of the top level folder should not occur.
+##
+## ## Examples
+##
+## * [bzip2](https://github.com/Microsoft/vcpkg/blob/master/ports/bzip2/portfile.cmake)
+## * [sqlite3](https://github.com/Microsoft/vcpkg/blob/master/ports/sqlite3/portfile.cmake)
+## * [cairo](https://github.com/Microsoft/vcpkg/blob/master/ports/cairo/portfile.cmake)
+include(vcpkg_apply_patches)
+include(vcpkg_extract_source_archive)
+
+function(vcpkg_extract_source_archive_ex)
+ cmake_parse_arguments(_vesae "NO_REMOVE_ONE_LEVEL" "OUT_SOURCE_PATH;ARCHIVE;REF;WORKING_DIRECTORY" "PATCHES" ${ARGN})
+
+ if(NOT _vesae_ARCHIVE)
+ message(FATAL_ERROR "Must specify ARCHIVE parameter to vcpkg_extract_source_archive_ex()")
+ endif()
+
+ if(NOT DEFINED _vesae_OUT_SOURCE_PATH)
+ message(FATAL_ERROR "Must specify OUT_SOURCE_PATH parameter to vcpkg_extract_source_archive_ex()")
+ endif()
+
+ if(NOT DEFINED _vesae_WORKING_DIRECTORY)
+ set(_vesae_WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/src)
+ endif()
+
+ if(NOT DEFINED _vesae_REF)
+ get_filename_component(_vesae_REF ${_vesae_ARCHIVE} NAME_WE)
+ endif()
+
+ string(REPLACE "/" "-" SANITIZED_REF "${_vesae_REF}")
+
+ # Take the last 10 chars of the REF
+ set(REF_MAX_LENGTH 10)
+ string(LENGTH ${SANITIZED_REF} REF_LENGTH)
+ math(EXPR FROM_REF ${REF_LENGTH}-${REF_MAX_LENGTH})
+ if(FROM_REF LESS 0)
+ set(FROM_REF 0)
+ endif()
+ string(SUBSTRING ${SANITIZED_REF} ${FROM_REF} ${REF_LENGTH} SHORTENED_SANITIZED_REF)
+
+ # Hash the archive hash along with the patches. Take the first 10 chars of the hash
+ file(SHA512 ${_vesae_ARCHIVE} PATCHSET_HASH)
+ foreach(PATCH IN LISTS _vesae_PATCHES)
+ get_filename_component(ABSOLUTE_PATCH "${PATCH}" ABSOLUTE BASE_DIR "${CURRENT_PORT_DIR}")
+ file(SHA512 ${ABSOLUTE_PATCH} CURRENT_HASH)
+ string(APPEND PATCHSET_HASH ${CURRENT_HASH})
+ endforeach()
+
+ string(SHA512 PATCHSET_HASH ${PATCHSET_HASH})
+ string(SUBSTRING ${PATCHSET_HASH} 0 10 PATCHSET_HASH)
+ set(SOURCE_PATH "${_vesae_WORKING_DIRECTORY}/${SHORTENED_SANITIZED_REF}-${PATCHSET_HASH}")
+
+ if(NOT EXISTS ${SOURCE_PATH})
+ set(TEMP_DIR "${_vesae_WORKING_DIRECTORY}/TEMP")
+ file(REMOVE_RECURSE ${TEMP_DIR})
+ vcpkg_extract_source_archive("${_vesae_ARCHIVE}" "${TEMP_DIR}")
+
+ if(_vesae_NO_REMOVE_ONE_LEVEL)
+ set(TEMP_SOURCE_PATH ${TEMP_DIR})
+ else()
+ file(GLOB _ARCHIVE_FILES "${TEMP_DIR}/*")
+ list(LENGTH _ARCHIVE_FILES _NUM_ARCHIVE_FILES)
+ set(TEMP_SOURCE_PATH)
+ foreach(dir IN LISTS _ARCHIVE_FILES)
+ if (IS_DIRECTORY ${dir})
+ set(TEMP_SOURCE_PATH "${dir}")
+ break()
+ endif()
+ endforeach()
+
+ if(NOT _NUM_ARCHIVE_FILES EQUAL 2 OR NOT TEMP_SOURCE_PATH)
+ message(FATAL_ERROR "Could not unwrap top level directory from archive. Pass NO_REMOVE_ONE_LEVEL to disable this.")
+ endif()
+ endif()
+
+ vcpkg_apply_patches(
+ SOURCE_PATH ${TEMP_SOURCE_PATH}
+ PATCHES ${_vesae_PATCHES}
+ )
+
+ file(RENAME ${TEMP_SOURCE_PATH} ${SOURCE_PATH})
+ file(REMOVE_RECURSE ${TEMP_DIR})
+ endif()
+
+ set(${_vesae_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE)
+ message(STATUS "Using source at ${SOURCE_PATH}")
+ return()
+endfunction()
diff --git a/scripts/cmake/vcpkg_find_acquire_program.cmake b/scripts/cmake/vcpkg_find_acquire_program.cmake index 39a722d93..ebe46b335 100644 --- a/scripts/cmake/vcpkg_find_acquire_program.cmake +++ b/scripts/cmake/vcpkg_find_acquire_program.cmake @@ -77,12 +77,18 @@ function(vcpkg_find_acquire_program VAR) set(NOEXTRACT ON) set(HASH c1945669d983b632a10c5ff31e86d6ecbff143c3d8b2c433c0d3d18f84356d2b351f71ac05fd44e5403651b00c31db0d14615d7f9a6ecce5750438d37105c55b) elseif(VAR MATCHES "PYTHON3") - set(PROGNAME python) - set(SUBDIR "python3") - set(PATHS ${DOWNLOADS}/tools/python/${SUBDIR}) - set(URL "https://www.python.org/ftp/python/3.5.4/python-3.5.4-embed-win32.zip") - set(ARCHIVE "python-3.5.4-embed-win32.zip") - set(HASH b5240fdc95088c2d7f65d2dd598650f8dd106b49589d94156bd4a078b108c6cabbe7a38ef73e2b2cf00e8312a93d2e587eac2c54ce85540d3c7a26cc60013156) + if(CMAKE_HOST_WIN32) + set(PROGNAME python) + set(SUBDIR "python3") + set(PATHS ${DOWNLOADS}/tools/python/${SUBDIR}) + set(URL "https://www.python.org/ftp/python/3.5.4/python-3.5.4-embed-win32.zip") + set(ARCHIVE "python-3.5.4-embed-win32.zip") + set(HASH b5240fdc95088c2d7f65d2dd598650f8dd106b49589d94156bd4a078b108c6cabbe7a38ef73e2b2cf00e8312a93d2e587eac2c54ce85540d3c7a26cc60013156) + else() + set(PROGNAME python3) + set(BREW_PACKAGE_NAME "python") + set(APT_PACKAGE_NAME "python3") + endif() elseif(VAR MATCHES "PYTHON2") set(PROGNAME python) set(SUBDIR "python2") @@ -128,23 +134,43 @@ function(vcpkg_find_acquire_program VAR) elseif(VAR MATCHES "MESON") set(PROGNAME meson) set(REQUIRED_INTERPRETER PYTHON3) - set(SCRIPTNAME meson.py) - set(PATHS ${DOWNLOADS}/tools/meson/meson-0.43.0) - set(URL "https://github.com/mesonbuild/meson/archive/0.43.0.zip") - set(ARCHIVE "meson-0.43.0.zip") - set(HASH dde4de72eff37046731224f32aa5f4618d45bdf148cec2d1af6e25e7522ebc2b04aedc9eceed483dfa93823a0ea7ea472d0c0c9380061bf3ee2f16b87dd1425e) + set(BREW_PACKAGE_NAME "meson") + set(APT_PACKAGE_NAME "meson") + if(CMAKE_HOST_WIN32) + set(SCRIPTNAME meson.py) + else() + set(SCRIPTNAME meson) + endif() + set(PATHS ${DOWNLOADS}/tools/meson/meson-0.47.1) + set(URL "https://github.com/mesonbuild/meson/archive/0.47.1.zip") + set(ARCHIVE "meson-0.47.1.zip") + set(HASH 0f6462835583a51707bee82d852018cfcb7444c0dad95b2ba08814e500a5cfe3f731dc6c1fb73c765d1120ee2a2d6600e15d8d393bab1993e84bd4354b2e6855) elseif(VAR MATCHES "FLEX") - set(PROGNAME win_flex) - set(PATHS ${DOWNLOADS}/tools/win_flex) - set(URL "https://sourceforge.net/projects/winflexbison/files/win_flex_bison-2.5.9.zip/download") - set(ARCHIVE "win_flex_bison-2.5.9.zip") - set(HASH 9580f0e46893670a011645947c1becda69909a41a38bb4197fe33bd1ab7719da6b80e1be316f269e1a4759286870d49a9b07ef83afc4bac33232bd348e0bc814) + if(CMAKE_HOST_WIN32) + set(PROGNAME win_flex) + set(SUBDIR win_flex-2.5.16) + set(PATHS ${DOWNLOADS}/tools/win_flex/${SUBDIR}) + set(URL "https://sourceforge.net/projects/winflexbison/files/winflexbison-2.5.16.zip/download") + set(ARCHIVE "win_flex_bison-2.5.16.zip") + set(HASH 0a14154bff5d998feb23903c46961528f8ccb4464375d5384db8c4a7d230c0c599da9b68e7a32f3217a0a0735742242eaf3769cb4f03e00931af8640250e9123) + else() + set(PROGNAME flex) + set(APT_PACKAGE_NAME flex) + set(BREW_PACKAGE_NAME flex) + endif() elseif(VAR MATCHES "BISON") - set(PROGNAME win_bison) - set(PATHS ${DOWNLOADS}/tools/win_bison) - set(URL "https://sourceforge.net/projects/winflexbison/files/win_flex_bison-2.5.9.zip/download") - set(ARCHIVE "win_flex_bison-2.5.9.zip") - set(HASH 9580f0e46893670a011645947c1becda69909a41a38bb4197fe33bd1ab7719da6b80e1be316f269e1a4759286870d49a9b07ef83afc4bac33232bd348e0bc814) + if(CMAKE_HOST_WIN32) + set(PROGNAME win_bison) + set(SUBDIR win_bison-2.5.16) + set(PATHS ${DOWNLOADS}/tools/win_bison/${SUBDIR}) + set(URL "https://sourceforge.net/projects/winflexbison/files/winflexbison-2.5.16.zip/download") + set(ARCHIVE "win_flex_bison-2.5.16.zip") + set(HASH 0a14154bff5d998feb23903c46961528f8ccb4464375d5384db8c4a7d230c0c599da9b68e7a32f3217a0a0735742242eaf3769cb4f03e00931af8640250e9123) + else() + set(PROGNAME bison) + set(APT_PACKAGE_NAME bison) + set(BREW_PACKAGE_NAME bison) + endif() elseif(VAR MATCHES "GPERF") set(PROGNAME gperf) set(PATHS ${DOWNLOADS}/tools/gperf/bin) diff --git a/scripts/cmake/vcpkg_fixup_cmake_targets.cmake b/scripts/cmake/vcpkg_fixup_cmake_targets.cmake index 47c91f83c..ea9923df3 100644 --- a/scripts/cmake/vcpkg_fixup_cmake_targets.cmake +++ b/scripts/cmake/vcpkg_fixup_cmake_targets.cmake @@ -117,7 +117,7 @@ function(vcpkg_fixup_cmake_targets) file(READ ${DEBUG_TARGET} _contents) string(REPLACE "${CURRENT_INSTALLED_DIR}" "\${_IMPORT_PREFIX}" _contents "${_contents}") - string(REGEX REPLACE "\\\${_IMPORT_PREFIX}/bin/([^ \"]+\\.exe)" "\${_IMPORT_PREFIX}/tools/${PORT}/\\1" _contents "${_contents}") + string(REGEX REPLACE "\\\${_IMPORT_PREFIX}/bin/([^ \";]+\\.exe)" "\${_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}") @@ -134,9 +134,9 @@ function(vcpkg_fixup_cmake_targets) "get_filename_component(_IMPORT_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)\nget_filename_component(_IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH)\nget_filename_component(_IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH)" _contents "${_contents}") string(REPLACE "${CURRENT_INSTALLED_DIR}" "_INVALID_ROOT_" _contents "${_contents}") - string(REGEX REPLACE ";_INVALID_ROOT_/[^\";]*" "" _contents "${_contents}") - string(REGEX REPLACE "_INVALID_ROOT_/[^\";]*;" "" _contents "${_contents}") - string(REGEX REPLACE "\"_INVALID_ROOT_/[^\";]*\"" "\"\"" _contents "${_contents}") + string(REGEX REPLACE "_INVALID_ROOT_/[^\";>]*" "" _contents "${_contents}") + string(REGEX REPLACE ";;+" ";" _contents "${_contents}") + string(REGEX REPLACE "\";\"" "\"\"" _contents "${_contents}") file(WRITE ${MAIN_TARGET} "${_contents}") endforeach() diff --git a/scripts/cmake/vcpkg_from_bitbucket.cmake b/scripts/cmake/vcpkg_from_bitbucket.cmake index a12d86b43..5f23714ea 100644 --- a/scripts/cmake/vcpkg_from_bitbucket.cmake +++ b/scripts/cmake/vcpkg_from_bitbucket.cmake @@ -11,6 +11,7 @@ ## [REF <v2.0.0>] ## [SHA512 <45d0d7f8cc350...>] ## [HEAD_REF <master>] +## [PATCHES <patch1.patch> <patch2.patch>...] ## ) ## ``` ## @@ -40,6 +41,11 @@ ## ## For most projects, this should be `master`. The chosen branch should be one that is expected to be always buildable on all supported platforms. ## +## ### PATCHES +## A list of patches to be applied to the extracted sources. +## +## Relative paths are based on the port directory. +## ## ## Notes: ## At least one of `REF` and `HEAD_REF` must be specified, however it is preferable for both to be present. ## @@ -50,7 +56,7 @@ ## * [blaze](https://github.com/Microsoft/vcpkg/blob/master/ports/blaze/portfile.cmake) function(vcpkg_from_bitbucket) set(oneValueArgs OUT_SOURCE_PATH REPO REF SHA512 HEAD_REF) - set(multipleValuesArgs) + set(multipleValuesArgs PATCHES) cmake_parse_arguments(_vdud "" "${oneValueArgs}" "${multipleValuesArgs}" ${ARGN}) if(NOT _vdud_OUT_SOURCE_PATH) @@ -115,7 +121,7 @@ function(vcpkg_from_bitbucket) string(REGEX REPLACE "\"hash\": \"([a-f0-9]+)\"" "\\1" _version ${x}) string(SUBSTRING ${_version} 0 12 _version) # Get the 12 first numbers from commit hash else() - set(_version ${_vdud_REF}) + string(SUBSTRING ${_vdud_REF} 0 12 _version) # Get the 12 first numbers from commit hash endif() vcpkg_download_distfile(ARCHIVE @@ -123,8 +129,14 @@ function(vcpkg_from_bitbucket) SHA512 "${_vdud_SHA512}" FILENAME "${ORG_NAME}-${REPO_NAME}-${_vdud_REF}.tar.gz" ) - vcpkg_extract_source_archive_ex(ARCHIVE "${ARCHIVE}") - set_SOURCE_PATH(${CURRENT_BUILDTREES_DIR}/src ${_version}) + + vcpkg_extract_source_archive_ex( + OUT_SOURCE_PATH SOURCE_PATH + ARCHIVE "${ARCHIVE}" + REF "${_vdud_REF}" + PATCHES ${_vdud_PATCHES} + ) + set(${_vdud_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE) return() endif() @@ -164,11 +176,6 @@ function(vcpkg_from_bitbucket) ) endif() - vcpkg_extract_source_archive_ex( - ARCHIVE "${ARCHIVE}" - WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/src/head" - ) - # Parse the github refs response with regex. # TODO: use some JSON swiss-army-knife utility instead. file(READ "${ARCHIVE_VERSION}" _contents) @@ -179,5 +186,12 @@ function(vcpkg_from_bitbucket) # exports VCPKG_HEAD_VERSION to the caller. This will get picked up by ports.cmake after the build. set(VCPKG_HEAD_VERSION ${_version} PARENT_SCOPE) - set_SOURCE_PATH(${CURRENT_BUILDTREES_DIR}/src/head ${_vdud_HEAD_REF}) + vcpkg_extract_source_archive_ex( + OUT_SOURCE_PATH SOURCE_PATH + ARCHIVE "${downloaded_file_path}" + REF "${_vdud_HEAD_REF}" + WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/src/head" + PATCHES ${_vdud_PATCHES} + ) + set(${_vdud_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE) endfunction() diff --git a/scripts/cmake/vcpkg_from_git.cmake b/scripts/cmake/vcpkg_from_git.cmake new file mode 100644 index 000000000..2fc66b279 --- /dev/null +++ b/scripts/cmake/vcpkg_from_git.cmake @@ -0,0 +1,127 @@ +## # vcpkg_from_git +## +## Download and extract a project from git +## +## ## Usage: +## ```cmake +## vcpkg_from_git( +## OUT_SOURCE_PATH <SOURCE_PATH> +## URL <https://android.googlesource.com/platform/external/fdlibm> +## REF <59f7335e4d...> +## SHA512 <abcdef123...> +## [PATCHES <patch1.patch> <patch2.patch>...] +## ) +## ``` +## +## ## Parameters: +## ### OUT_SOURCE_PATH +## Specifies the out-variable that will contain the extracted location. +## +## This should be set to `SOURCE_PATH` by convention. +## +## ### URL +## The url of the git repository. +## +## ### SHA512 +## The SHA512 hash that should match the archive form of the commit. +## +## This is most easily determined by first setting it to `0`, then trying to build the port. The error message will contain the full hash, which can be copied back into the portfile. +## +## ### REF +## A stable git commit-ish (ideally a tag or commit) that will not change contents. **This should not be a branch.** +## +## For repositories without official releases, this can be set to the full commit id of the current latest master. +## +## ### PATCHES +## A list of patches to be applied to the extracted sources. +## +## Relative paths are based on the port directory. +## +## ## Notes: +## `OUT_SOURCE_PATH`, `REF`, `SHA512`, and `URL` must be specified. +## +## ## Examples: +## +## * [fdlibm](https://github.com/Microsoft/vcpkg/blob/master/ports/fdlibm/portfile.cmake) + +function(vcpkg_from_git) + set(oneValueArgs OUT_SOURCE_PATH URL REF SHA512) + set(multipleValuesArgs PATCHES) + cmake_parse_arguments(_vdud "" "${oneValueArgs}" "${multipleValuesArgs}" ${ARGN}) + + if(NOT DEFINED _vdud_OUT_SOURCE_PATH) + message(FATAL_ERROR "OUT_SOURCE_PATH must be specified.") + endif() + + if(NOT DEFINED _vdud_URL) + message(FATAL_ERROR "The git url must be specified") + endif() + + if(NOT DEFINED _vdud_REF) + message(FATAL_ERROR "The git ref must be specified.") + endif() + + if(NOT DEFINED _vdud_SHA512) + message(FATAL_ERROR "vcpkg_from_git requires a SHA512 argument. If you do not know the SHA512, add it as 'SHA512 0' and re-run this command.") + endif() + + # using .tar.gz instead of .zip because the hash of the latter is affected by timezone. + string(REPLACE "/" "-" SANITIZED_REF "${_vdud_REF}") + set(TEMP_ARCHIVE "${DOWNLOADS}/temp/${PORT}-${SANITIZED_REF}.tar.gz") + set(ARCHIVE "${DOWNLOADS}/${PORT}-${SANITIZED_REF}.tar.gz") + set(TEMP_SOURCE_PATH "${CURRENT_BUILDTREES_DIR}/src/${SANITIZED_REF}") + + function(test_hash FILE_PATH FILE_KIND CUSTOM_ERROR_ADVICE) + file(SHA512 ${FILE_PATH} FILE_HASH) + if(NOT FILE_HASH STREQUAL _vdud_SHA512) + message(FATAL_ERROR + "\nFile does not have expected hash:\n" + " File path: [ ${FILE_PATH} ]\n" + " Expected hash: [ ${_vdud_SHA512} ]\n" + " Actual hash: [ ${FILE_HASH} ]\n" + "${CUSTOM_ERROR_ADVICE}\n") + endif() + endfunction() + + if(NOT EXISTS "${ARCHIVE}") + if(_VCPKG_NO_DOWNLOADS) + message(FATAL_ERROR "Downloads are disabled, but '${ARCHIVE}' does not exist.") + endif() + message(STATUS "Fetching ${_vdud_URL}...") + find_program(GIT NAMES git git.cmd) + # Note: git init is safe to run multiple times + vcpkg_execute_required_process( + COMMAND ${GIT} init git-tmp + WORKING_DIRECTORY ${DOWNLOADS} + LOGNAME git-init + ) + vcpkg_execute_required_process( + COMMAND ${GIT} fetch ${_vdud_URL} ${_vdud_REF} --depth 1 -n + WORKING_DIRECTORY ${DOWNLOADS}/git-tmp + LOGNAME git-fetch + ) + file(MAKE_DIRECTORY "${DOWNLOADS}/temp") + vcpkg_execute_required_process( + COMMAND ${GIT} archive FETCH_HEAD -o "${TEMP_ARCHIVE}" + WORKING_DIRECTORY ${DOWNLOADS}/git-tmp + LOGNAME git-archive + ) + test_hash("${TEMP_ARCHIVE}" "downloaded repo" "") + get_filename_component(downloaded_file_dir "${ARCHIVE}" DIRECTORY) + file(MAKE_DIRECTORY "${downloaded_file_dir}") + file(RENAME "${TEMP_ARCHIVE}" "${ARCHIVE}") + else() + message(STATUS "Using cached ${ARCHIVE}") + test_hash("${ARCHIVE}" "cached file" "Please delete the file and retry if this file should be downloaded again.") + endif() + + vcpkg_extract_source_archive_ex( + OUT_SOURCE_PATH SOURCE_PATH + ARCHIVE "${ARCHIVE}" + REF "${SANITIZED_REF}" + PATCHES ${_vdud_PATCHES} + NO_REMOVE_ONE_LEVEL + ) + + set(${_vdud_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE) +endfunction() diff --git a/scripts/cmake/vcpkg_from_github.cmake b/scripts/cmake/vcpkg_from_github.cmake index 28ada0631..48bfd828a 100644 --- a/scripts/cmake/vcpkg_from_github.cmake +++ b/scripts/cmake/vcpkg_from_github.cmake @@ -10,6 +10,7 @@ ## [REF <v2.0.0>] ## [SHA512 <45d0d7f8cc350...>] ## [HEAD_REF <master>] +## [PATCHES <patch1.patch> <patch2.patch>...] ## ) ## ``` ## @@ -23,7 +24,7 @@ ## The organization or user and repository on GitHub. ## ## ### REF -## A stable git commit-ish (ideally a tag) that will not change contents. **This should not be a branch.** +## A stable git commit-ish (ideally a tag or commit) that will not change contents. **This should not be a branch.** ## ## For repositories without official releases, this can be set to the full commit id of the current latest master. ## @@ -39,6 +40,11 @@ ## ## For most projects, this should be `master`. The chosen branch should be one that is expected to be always buildable on all supported platforms. ## +## ### PATCHES +## A list of patches to be applied to the extracted sources. +## +## Relative paths are based on the port directory. +## ## ## Notes: ## At least one of `REF` and `HEAD_REF` must be specified, however it is preferable for both to be present. ## @@ -74,16 +80,16 @@ function(vcpkg_from_github) string(REGEX REPLACE "/.*" "" ORG_NAME ${_vdud_REPO}) macro(set_TEMP_SOURCE_PATH BASE BASEREF) - set(TEMP_SOURCE_PATH "${BASE}/${REPO_NAME}-${BASEREF}") - if(NOT EXISTS ${TEMP_SOURCE_PATH}) - # Sometimes GitHub strips a leading 'v' off the REF. - string(REGEX REPLACE "^v" "" REF ${BASEREF}) - string(REPLACE "/" "-" REF ${REF}) - set(TEMP_SOURCE_PATH "${BASE}/${REPO_NAME}-${REF}") + set(TEMP_SOURCE_PATH "${BASE}/${REPO_NAME}-${BASEREF}") if(NOT EXISTS ${TEMP_SOURCE_PATH}) - message(FATAL_ERROR "Could not determine source path: '${BASE}/${REPO_NAME}-${BASEREF}' does not exist") + # Sometimes GitHub strips a leading 'v' off the REF. + string(REGEX REPLACE "^v" "" REF ${BASEREF}) + string(REPLACE "/" "-" REF ${REF}) + set(TEMP_SOURCE_PATH "${BASE}/${REPO_NAME}-${REF}") + if(NOT EXISTS ${TEMP_SOURCE_PATH}) + message(FATAL_ERROR "Could not determine source path: '${BASE}/${REPO_NAME}-${BASEREF}' does not exist") + endif() endif() - endif() endmacro() if(VCPKG_USE_HEAD_VERSION AND NOT DEFINED _vdud_HEAD_REF) @@ -105,43 +111,14 @@ function(vcpkg_from_github) FILENAME "${ORG_NAME}-${REPO_NAME}-${SANITIZED_REF}.tar.gz" ) - # Take the last 10 chars of the REF - set(REF_MAX_LENGTH 10) - string(LENGTH ${SANITIZED_REF} REF_LENGTH) - math(EXPR FROM_REF ${REF_LENGTH}-${REF_MAX_LENGTH}) - if(FROM_REF LESS 0) - set(FROM_REF 0) - endif() - string(SUBSTRING ${SANITIZED_REF} ${FROM_REF} ${REF_LENGTH} SHORTENED_SANITIZED_REF) - - # Hash the archive hash along with the patches. Take the first 10 chars of the hash - set(PATCHSET_HASH "${_vdud_SHA512}") - foreach(PATCH IN LISTS _vdud_PATCHES) - file(SHA512 ${PATCH} CURRENT_HASH) - string(APPEND PATCHSET_HASH ${CURRENT_HASH}) - endforeach() - - string(SHA512 PATCHSET_HASH ${PATCHSET_HASH}) - string(SUBSTRING ${PATCHSET_HASH} 0 10 PATCHSET_HASH) - set(SOURCE_PATH "${CURRENT_BUILDTREES_DIR}/src/${SHORTENED_SANITIZED_REF}-${PATCHSET_HASH}") - - if(NOT EXISTS ${SOURCE_PATH}) - set(TEMP_DIR "${CURRENT_BUILDTREES_DIR}/src/TEMP") - file(REMOVE_RECURSE ${TEMP_DIR}) - vcpkg_extract_source_archive_ex(ARCHIVE "${ARCHIVE}" WORKING_DIRECTORY ${TEMP_DIR}) - set_TEMP_SOURCE_PATH(${CURRENT_BUILDTREES_DIR}/src/TEMP ${SANITIZED_REF}) - - vcpkg_apply_patches( - SOURCE_PATH ${TEMP_SOURCE_PATH} - PATCHES ${_vdud_PATCHES} - ) - - file(RENAME ${TEMP_SOURCE_PATH} ${SOURCE_PATH}) - file(REMOVE_RECURSE ${TEMP_DIR}) - endif() + vcpkg_extract_source_archive_ex( + OUT_SOURCE_PATH SOURCE_PATH + ARCHIVE "${ARCHIVE}" + REF "${SANITIZED_REF}" + PATCHES ${_vdud_PATCHES} + ) set(${_vdud_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE) - return() endif() @@ -182,11 +159,6 @@ function(vcpkg_from_github) ) endif() - vcpkg_extract_source_archive_ex( - ARCHIVE "${ARCHIVE}" - WORKING_DIRECTORY "${CURRENT_BUILDTREES_DIR}/src/head" - ) - # Parse the github refs response with regex. # TODO: use some JSON swiss-army-knife utility instead. file(READ "${ARCHIVE_VERSION}" _contents) @@ -199,10 +171,12 @@ function(vcpkg_from_github) set(VCPKG_HEAD_VERSION ${_version} PARENT_SCOPE) endif() - set_TEMP_SOURCE_PATH(${CURRENT_BUILDTREES_DIR}/src/head ${SANITIZED_HEAD_REF}) - vcpkg_apply_patches( - SOURCE_PATH ${TEMP_SOURCE_PATH} + vcpkg_extract_source_archive_ex( + OUT_SOURCE_PATH SOURCE_PATH + ARCHIVE "${downloaded_file_path}" + REF "${SANITIZED_HEAD_REF}" + WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/src/head PATCHES ${_vdud_PATCHES} ) - set(${_vdud_OUT_SOURCE_PATH} "${TEMP_SOURCE_PATH}" PARENT_SCOPE) + set(${_vdud_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE) endfunction() diff --git a/scripts/cmake/vcpkg_from_gitlab.cmake b/scripts/cmake/vcpkg_from_gitlab.cmake new file mode 100644 index 000000000..f13bc054c --- /dev/null +++ b/scripts/cmake/vcpkg_from_gitlab.cmake @@ -0,0 +1,169 @@ +## # vcpkg_from_gitlab +## +## Download and extract a project from Gitlab instances. Enables support for `install --head`. +## +## ## Usage: +## ```cmake +## vcpkg_from_gitlab( +## GITLAB_URL <https://gitlab.com> +## OUT_SOURCE_PATH <SOURCE_PATH> +## REPO <gitlab-org/gitlab-ce> +## [REF <v10.7.3>] +## [SHA512 <45d0d7f8cc350...>] +## [HEAD_REF <master>] +## [PATCHES <patch1.patch> <patch2.patch>...] +## ) +## ``` +## +## ## Parameters: +## +## ### GITLAB_URL +## The URL of the Gitlab instance to use. +## +## ### OUT_SOURCE_PATH +## Specifies the out-variable that will contain the extracted location. +## +## This should be set to `SOURCE_PATH` by convention. +## +## ### REPO +## The organization or user plus the repository name on the Gitlab instance. +## +## ### REF +## A stable git commit-ish (ideally a tag) that will not change contents. **This should not be a branch.** +## +## For repositories without official releases, this can be set to the full commit id of the current latest master. +## +## If `REF` is specified, `SHA512` must also be specified. +## +## ### SHA512 +## The SHA512 hash that should match the archive (${GITLAB_URL}/${REPO}/-/archive/${REF}/${REPO_NAME}-${REF}.tar.gz). +## The REPO_NAME variable is parsed from the value of REPO. +## +## This is most easily determined by first setting it to `1`, then trying to build the port. The error message will contain the full hash, which can be copied back into the portfile. +## +## ### HEAD_REF +## The unstable git commit-ish (ideally a branch) to pull for `--head` builds. +## +## For most projects, this should be `master`. The chosen branch should be one that is expected to be always buildable on all supported platforms. +## +## ### PATCHES +## A list of patches to be applied to the extracted sources. +## +## Relative paths are based on the port directory. +## +## ## Notes: +## At least one of `REF` and `HEAD_REF` must be specified, however it is preferable for both to be present. +## +## This exports the `VCPKG_HEAD_VERSION` variable during head builds. +## + +function(vcpkg_from_gitlab) + set(oneValueArgs OUT_SOURCE_PATH GITLAB_URL USER REPO REF SHA512 HEAD_REF) + set(multipleValuesArgs PATCHES) + cmake_parse_arguments(_vdud "" "${oneValueArgs}" "${multipleValuesArgs}" ${ARGN}) + + if(NOT DEFINED _vdud_GITLAB_URL) + message(FATAL_ERROR "GITLAB_URL must be specified.") + endif() + + if(NOT DEFINED _vdud_OUT_SOURCE_PATH) + message(FATAL_ERROR "OUT_SOURCE_PATH must be specified.") + endif() + + if((DEFINED _vdud_REF AND NOT DEFINED _vdud_SHA512) OR (NOT DEFINED _vdud_REF AND DEFINED _vdud_SHA512)) + message(FATAL_ERROR "SHA512 must be specified if REF is specified.") + endif() + + if(NOT DEFINED _vdud_REPO) + message(FATAL_ERROR "REPO must be specified.") + endif() + + if(NOT DEFINED _vdud_REF AND NOT DEFINED _vdud_HEAD_REF) + message(FATAL_ERROR "At least one of REF and HEAD_REF must be specified.") + endif() + + if(VCPKG_USE_HEAD_VERSION AND NOT DEFINED _vdud_HEAD_REF) + message(STATUS "Package does not specify HEAD_REF. Falling back to non-HEAD version.") + set(VCPKG_USE_HEAD_VERSION OFF) + endif() + + string(REGEX REPLACE ".*/" "" REPO_NAME ${_vdud_REPO}) + string(REGEX REPLACE "/.*" "" ORG_NAME ${_vdud_REPO}) + + # Handle --no-head scenarios + if(NOT VCPKG_USE_HEAD_VERSION) + if(NOT _vdud_REF) + message(FATAL_ERROR "Package does not specify REF. It must built using --head.") + endif() + + string(REPLACE "/" "-" SANITIZED_REF "${_vdud_REF}") + + vcpkg_download_distfile(ARCHIVE + URLS "${_vdud_GITLAB_URL}/${ORG_NAME}/${REPO_NAME}/-/archive/${_vdud_REF}/${REPO_NAME}-${_vdud_REF}.tar.gz" + SHA512 "${_vdud_SHA512}" + FILENAME "${ORG_NAME}-${REPO_NAME}-${SANITIZED_REF}.tar.gz" + ) + + vcpkg_extract_source_archive_ex( + OUT_SOURCE_PATH SOURCE_PATH + ARCHIVE "${ARCHIVE}" + REF "${SANITIZED_REF}" + PATCHES ${_vdud_PATCHES} + ) + + set(${_vdud_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE) + return() + endif() + + # The following is for --head scenarios + set(URL "${_vdud_GITLAB_URL}/${ORG_NAME}/${REPO_NAME}/-/archive/${_vdud_HEAD_REF}/${_vdud_HEAD_REF}.tar.gz") + string(REPLACE "/" "-" SANITIZED_HEAD_REF "${_vdud_HEAD_REF}") + set(downloaded_file_name "${ORG_NAME}-${REPO_NAME}-${SANITIZED_HEAD_REF}.tar.gz") + set(downloaded_file_path "${DOWNLOADS}/${downloaded_file_name}") + + if(_VCPKG_NO_DOWNLOADS) + if(NOT EXISTS ${downloaded_file_path} OR NOT EXISTS ${downloaded_file_path}.version) + message(FATAL_ERROR "Downloads are disabled, but '${downloaded_file_path}' does not exist.") + endif() + message(STATUS "Using cached ${downloaded_file_path}") + else() + if(EXISTS ${downloaded_file_path}) + message(STATUS "Purging cached ${downloaded_file_path} to fetch latest (use --no-downloads to suppress)") + file(REMOVE ${downloaded_file_path}) + endif() + if(EXISTS ${downloaded_file_path}.version) + file(REMOVE ${downloaded_file_path}.version) + endif() + if(EXISTS ${CURRENT_BUILDTREES_DIR}/src/head) + file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/src/head) + endif() + + vcpkg_download_distfile(ARCHIVE + URLS ${URL} + FILENAME ${downloaded_file_name} + SKIP_SHA512 + ) + endif() + + # There are issues with the Gitlab API project paths being URL-escaped, so we use git here to get the head revision + execute_process(COMMAND ${GIT} ls-remote + "${_vdud_GITLAB_URL}/${ORG_NAME}/${REPO_NAME}.git" "${_vdud_HEAD_REF}" + RESULT_VARIABLE _git_result + OUTPUT_VARIABLE _git_output + ) + string(REGEX MATCH "[a-f0-9]+" _version "${_git_output}") + # exports VCPKG_HEAD_VERSION to the caller. This will get picked up by ports.cmake after the build. + # When multiple vcpkg_from_gitlab's are used after each other, only use the version from the first (hopefully the primary one). + if(NOT DEFINED VCPKG_HEAD_VERSION) + set(VCPKG_HEAD_VERSION ${_version} PARENT_SCOPE) + endif() + + vcpkg_extract_source_archive_ex( + OUT_SOURCE_PATH SOURCE_PATH + ARCHIVE "${downloaded_file_path}" + REF "${SANITIZED_HEAD_REF}" + WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/src/head + PATCHES ${_vdud_PATCHES} + ) + set(${_vdud_OUT_SOURCE_PATH} "${SOURCE_PATH}" PARENT_SCOPE) +endfunction() diff --git a/scripts/cmake/vcpkg_get_windows_sdk.cmake b/scripts/cmake/vcpkg_get_windows_sdk.cmake index a8aad64a9..e7d72a125 100644 --- a/scripts/cmake/vcpkg_get_windows_sdk.cmake +++ b/scripts/cmake/vcpkg_get_windows_sdk.cmake @@ -1,16 +1,6 @@ # Returns Windows SDK number via out variable "ret" function(vcpkg_get_windows_sdk ret) - execute_process( - COMMAND powershell.exe -NoProfile -ExecutionPolicy Bypass -Command "& {& '${VCPKG_ROOT_DIR}/scripts/getWindowsSDK.ps1'}" 2>&1 - INPUT_FILE NUL - OUTPUT_VARIABLE WINDOWS_SDK - RESULT_VARIABLE error_code) - - if (error_code) - message(FATAL_ERROR "Could not find Windows SDK") - endif() - - # Remove trailing newline and non-numeric characters - string(REGEX REPLACE "[^0-9.]" "" WINDOWS_SDK "${WINDOWS_SDK}") + set(WINDOWS_SDK $ENV{WindowsSDKVersion}) + string(REPLACE "\\" "" WINDOWS_SDK "${WINDOWS_SDK}") set(${ret} ${WINDOWS_SDK} PARENT_SCOPE) endfunction()
\ No newline at end of file diff --git a/scripts/cmake/vcpkg_install_meson.cmake b/scripts/cmake/vcpkg_install_meson.cmake index f6d49288c..7ab9d55b3 100644 --- a/scripts/cmake/vcpkg_install_meson.cmake +++ b/scripts/cmake/vcpkg_install_meson.cmake @@ -10,7 +10,6 @@ function(vcpkg_install_meson) WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel LOGNAME package-${TARGET_TRIPLET}-rel ) - message(STATUS "Package ${TARGET_TRIPLET}-rel done") message(STATUS "Package ${TARGET_TRIPLET}-dbg") vcpkg_execute_required_process( @@ -18,6 +17,5 @@ function(vcpkg_install_meson) WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg LOGNAME package-${TARGET_TRIPLET}-dbg ) - message(STATUS "Package ${TARGET_TRIPLET}-dbg done") endfunction() diff --git a/scripts/cmake/vcpkg_install_msbuild.cmake b/scripts/cmake/vcpkg_install_msbuild.cmake new file mode 100644 index 000000000..11bcdf189 --- /dev/null +++ b/scripts/cmake/vcpkg_install_msbuild.cmake @@ -0,0 +1,226 @@ +## # vcpkg_install_msbuild +## +## Build and install an msbuild-based project. This replaces `vcpkg_build_msbuild()`. +## +## ## Usage +## ```cmake +## vcpkg_install_msbuild( +## SOURCE_PATH <${SOURCE_PATH}> +## PROJECT_SUBPATH <port.sln> +## [INCLUDES_SUBPATH <include>] +## [LICENSE_SUBPATH <LICENSE>] +## [RELEASE_CONFIGURATION <Release>] +## [DEBUG_CONFIGURATION <Debug>] +## [TARGET <Build>] +## [TARGET_PLATFORM_VERSION <10.0.15063.0>] +## [PLATFORM <${TRIPLET_SYSTEM_ARCH}>] +## [PLATFORM_TOOLSET <${VCPKG_PLATFORM_TOOLSET}>] +## [OPTIONS </p:ZLIB_INCLUDE_PATH=X>...] +## [OPTIONS_RELEASE </p:ZLIB_LIB=X>...] +## [OPTIONS_DEBUG </p:ZLIB_LIB=X>...] +## [USE_VCPKG_INTEGRATION] +## [ALLOW_ROOT_INCLUDES | REMOVE_ROOT_INCLUDES] +## ) +## ``` +## +## ## Parameters +## ### SOURCE_PATH +## The path to the root of the source tree. +## +## Because MSBuild uses in-source builds, the source tree will be copied into a temporary location for the build. This +## parameter is the base for that copy and forms the base for all XYZ_SUBPATH options. +## +## ### USE_VCPKG_INTEGRATION +## Apply the normal `integrate install` integration for building the project. +## +## By default, projects built with this command will not automatically link libraries or have header paths set. +## +## ### PROJECT_SUBPATH +## The subpath to the solution (`.sln`) or project (`.vcxproj`) file relative to `SOURCE_PATH`. +## +## ### LICENSE_SUBPATH +## The subpath to the license file relative to `SOURCE_PATH`. +## +## ### INCLUDES_SUBPATH +## The subpath to the includes directory relative to `SOURCE_PATH`. +## +## This parameter should be a directory and should not end in a trailing slash. +## +## ### ALLOW_ROOT_INCLUDES +## Indicates that top-level include files (e.g. `include/zlib.h`) should be allowed. +## +## ### REMOVE_ROOT_INCLUDES +## Indicates that top-level include files (e.g. `include/Makefile.am`) should be removed. +## +## ### SKIP_CLEAN +## Indicates that the intermediate files should not be removed. +## +## Ports using this option should later call [`vcpkg_clean_msbuild()`](vcpkg_clean_msbuild.md) to manually clean up. +## +## ### RELEASE_CONFIGURATION +## The configuration (``/p:Configuration`` msbuild parameter) used for Release builds. +## +## ### DEBUG_CONFIGURATION +## The configuration (``/p:Configuration`` msbuild parameter) used for Debug builds. +## +## ### TARGET_PLATFORM_VERSION +## The WindowsTargetPlatformVersion (``/p:WindowsTargetPlatformVersion`` msbuild parameter) +## +## ### TARGET +## The MSBuild target to build. (``/t:<TARGET>``) +## +## ### PLATFORM +## The platform (``/p:Platform`` msbuild parameter) used for the build. +## +## ### PLATFORM_TOOLSET +## The platform toolset (``/p:PlatformToolset`` msbuild parameter) used for the build. +## +## ### OPTIONS +## Additional options passed to msbuild for all builds. +## +## ### OPTIONS_RELEASE +## Additional options passed to msbuild for Release builds. These are in addition to `OPTIONS`. +## +## ### OPTIONS_DEBUG +## Additional options passed to msbuild for Debug builds. These are in addition to `OPTIONS`. +## +## ## Examples +## +## * [xalan-c](https://github.com/Microsoft/vcpkg/blob/master/ports/xalan-c/portfile.cmake) +## * [libimobiledevice](https://github.com/Microsoft/vcpkg/blob/master/ports/libimobiledevice/portfile.cmake) + +include(vcpkg_clean_msbuild) + +function(vcpkg_install_msbuild) + cmake_parse_arguments( + _csc + "USE_VCPKG_INTEGRATION;ALLOW_ROOT_INCLUDES;REMOVE_ROOT_INCLUDES;SKIP_CLEAN" + "SOURCE_PATH;PROJECT_SUBPATH;INCLUDES_SUBPATH;LICENSE_SUBPATH;RELEASE_CONFIGURATION;DEBUG_CONFIGURATION;PLATFORM;PLATFORM_TOOLSET;TARGET_PLATFORM_VERSION;TARGET" + "OPTIONS;OPTIONS_RELEASE;OPTIONS_DEBUG" + ${ARGN} + ) + + if(NOT DEFINED _csc_RELEASE_CONFIGURATION) + set(_csc_RELEASE_CONFIGURATION Release) + endif() + if(NOT DEFINED _csc_DEBUG_CONFIGURATION) + set(_csc_DEBUG_CONFIGURATION Debug) + endif() + if(NOT DEFINED _csc_PLATFORM) + if(VCPKG_TARGET_ARCHITECTURE STREQUAL x64) + set(_csc_PLATFORM x64) + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL x86) + set(_csc_PLATFORM Win32) + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL ARM) + set(_csc_PLATFORM ARM) + else() + message(FATAL_ERROR "Unsupported target architecture") + endif() + endif() + if(NOT DEFINED _csc_PLATFORM_TOOLSET) + set(_csc_PLATFORM_TOOLSET ${VCPKG_PLATFORM_TOOLSET}) + endif() + if(NOT DEFINED _csc_TARGET_PLATFORM_VERSION) + vcpkg_get_windows_sdk(_csc_TARGET_PLATFORM_VERSION) + endif() + if(NOT DEFINED _csc_TARGET) + set(_csc_TARGET Rebuild) + endif() + + list(APPEND _csc_OPTIONS + /t:${_csc_TARGET} + /p:Platform=${_csc_PLATFORM} + /p:PlatformToolset=${_csc_PLATFORM_TOOLSET} + /p:VCPkgLocalAppDataDisabled=true + /p:UseIntelMKL=No + /p:WindowsTargetPlatformVersion=${_csc_TARGET_PLATFORM_VERSION} + /m + ) + + if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + # Disable LTCG for static libraries because this setting introduces ABI incompatibility between minor compiler versions + # TODO: Add a way for the user to override this if they want to opt-in to incompatibility + list(APPEND _csc_OPTIONS /p:WholeProgramOptimization=false) + endif() + + if(_csc_USE_VCPKG_INTEGRATION) + list(APPEND _csc_OPTIONS /p:ForceImportBeforeCppTargets=${VCPKG_ROOT_DIR}/scripts/buildsystems/msbuild/vcpkg.targets /p:VcpkgApplocalDeps=false) + endif() + + get_filename_component(SOURCE_PATH_SUFFIX "${_csc_SOURCE_PATH}" NAME) + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") + message(STATUS "Building ${_csc_PROJECT_SUBPATH} for Release") + file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel) + file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel) + file(COPY ${_csc_SOURCE_PATH} DESTINATION ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel) + set(SOURCE_COPY_PATH ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-rel/${SOURCE_PATH_SUFFIX}) + vcpkg_execute_required_process( + COMMAND msbuild ${SOURCE_COPY_PATH}/${_csc_PROJECT_SUBPATH} + /p:Configuration=${_csc_RELEASE_CONFIGURATION} + ${_csc_OPTIONS} + ${_csc_OPTIONS_RELEASE} + WORKING_DIRECTORY ${SOURCE_COPY_PATH} + LOGNAME build-${TARGET_TRIPLET}-rel + ) + file(GLOB_RECURSE LIBS ${SOURCE_COPY_PATH}/*.lib) + file(GLOB_RECURSE DLLS ${SOURCE_COPY_PATH}/*.dll) + file(GLOB_RECURSE EXES ${SOURCE_COPY_PATH}/*.exe) + if(LIBS) + file(COPY ${LIBS} DESTINATION ${CURRENT_PACKAGES_DIR}/lib) + endif() + if(DLLS) + file(COPY ${DLLS} DESTINATION ${CURRENT_PACKAGES_DIR}/bin) + endif() + if(EXES) + file(COPY ${EXES} DESTINATION ${CURRENT_PACKAGES_DIR}/tools/${PORT}) + vcpkg_copy_tool_dependencies(${CURRENT_PACKAGES_DIR}/tools/${PORT}) + endif() + endif() + + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + message(STATUS "Building ${_csc_PROJECT_SUBPATH} for Debug") + file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg) + file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg) + file(COPY ${_csc_SOURCE_PATH} DESTINATION ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg) + set(SOURCE_COPY_PATH ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-dbg/${SOURCE_PATH_SUFFIX}) + vcpkg_execute_required_process( + COMMAND msbuild ${SOURCE_COPY_PATH}/${_csc_PROJECT_SUBPATH} + /p:Configuration=${_csc_DEBUG_CONFIGURATION} + ${_csc_OPTIONS} + ${_csc_OPTIONS_DEBUG} + WORKING_DIRECTORY ${SOURCE_COPY_PATH} + LOGNAME build-${TARGET_TRIPLET}-dbg + ) + file(GLOB_RECURSE LIBS ${SOURCE_COPY_PATH}/*.lib) + file(GLOB_RECURSE DLLS ${SOURCE_COPY_PATH}/*.dll) + if(LIBS) + file(COPY ${LIBS} DESTINATION ${CURRENT_PACKAGES_DIR}/debug/lib) + endif() + if(DLLS) + file(COPY ${DLLS} DESTINATION ${CURRENT_PACKAGES_DIR}/debug/bin) + endif() + endif() + + vcpkg_copy_pdbs() + + if(NOT _csc_SKIP_CLEAN) + vcpkg_clean_msbuild() + endif() + + if(DEFINED _csc_INCLUDES_SUBPATH) + file(COPY ${_csc_SOURCE_PATH}/${_csc_INCLUDES_SUBPATH}/ DESTINATION ${CURRENT_PACKAGES_DIR}/include/) + file(GLOB ROOT_INCLUDES LIST_DIRECTORIES false ${CURRENT_PACKAGES_DIR}/include/*) + if(ROOT_INCLUDES) + if(_csc_REMOVE_ROOT_INCLUDES) + file(REMOVE ${ROOT_INCLUDES}) + elseif(_csc_ALLOW_ROOT_INCLUDES) + else() + message(FATAL_ERROR "Top-level files were found in ${CURRENT_PACKAGES_DIR}/include; this may indicate a problem with the call to `vcpkg_install_msbuild()`.\nTo avoid conflicts with other libraries, it is recommended to not put includes into the root `include/` directory.\nPass either ALLOW_ROOT_INCLUDES or REMOVE_ROOT_INCLUDES to handle these files.\n") + endif() + endif() + endif() + + if(DEFINED _csc_LICENSE_SUBPATH) + file(INSTALL ${_csc_SOURCE_PATH}/${_csc_LICENSE_SUBPATH} DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright) + endif() +endfunction() diff --git a/scripts/cmake/vcpkg_test_cmake.cmake b/scripts/cmake/vcpkg_test_cmake.cmake new file mode 100644 index 000000000..718b2f69c --- /dev/null +++ b/scripts/cmake/vcpkg_test_cmake.cmake @@ -0,0 +1,53 @@ +## # vcpkg_test_cmake +## +## Tests a built package for CMake `find_package()` integration. +## +## ## Usage: +## ```cmake +## vcpkg_test_cmake(PACKAGE_NAME <name> [MODULE]) +## ``` +## +## ## Parameters: +## +## ### PACKAGE_NAME +## The expected name to find with `find_package()`. +## +## ### MODULE +## Indicates that the library expects to be found via built-in CMake targets. +## +function(vcpkg_test_cmake) + cmake_parse_arguments(_tc "MODULE" "PACKAGE_NAME" "" ${ARGN}) + + if(NOT DEFINED _tc_PACKAGE_NAME) + message(FATAL_ERROR "PACKAGE_NAME must be specified") + endif() + if(_tc_MODULE) + set(PACKAGE_TYPE MODULE) + else() + set(PACKAGE_TYPE CONFIG) + endif() + + message(STATUS "Performing CMake integration test") + file(REMOVE_RECURSE ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-test) + file(MAKE_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-test) + + # Generate test source CMakeLists.txt + set(VCPKG_TEST_CMAKELIST ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-test/CMakeLists.txt) + file(WRITE ${VCPKG_TEST_CMAKELIST} "cmake_minimum_required(VERSION 3.10)\n") + file(APPEND ${VCPKG_TEST_CMAKELIST} "set(CMAKE_PREFIX_PATH \"${CURRENT_PACKAGES_DIR};${CURRENT_INSTALLED_DIR}\")\n") + file(APPEND ${VCPKG_TEST_CMAKELIST} "\n") + file(APPEND ${VCPKG_TEST_CMAKELIST} "find_package(${_tc_PACKAGE_NAME} ${PACKAGE_TYPE} REQUIRED)\n") + + # Run cmake config with a generated CMakeLists.txt + set(LOGPREFIX "${CURRENT_BUILDTREES_DIR}/test-cmake-${TARGET_TRIPLET}") + execute_process( + COMMAND ${CMAKE_COMMAND} . + OUTPUT_FILE "${LOGPREFIX}-out.log" + ERROR_FILE "${LOGPREFIX}-err.log" + RESULT_VARIABLE error_code + WORKING_DIRECTORY ${CURRENT_BUILDTREES_DIR}/${TARGET_TRIPLET}-test + ) + if(error_code) + message(FATAL_ERROR "CMake integration test failed; unable to find_package(${_tc_PACKAGE_NAME} ${PACKAGE_TYPE} REQUIRED)") + endif() +endfunction() |
