Skip to content

Commit

Permalink
[vcpkg] post-build cmake test (#3431)
Browse files Browse the repository at this point in the history
* [vcpkg]  post-build cmake test

- test for applications with cmake build system
- Add a test feature to vcpkg core, make progress for #72
- Tests for zlib, bzip2, libiconv and openssl for example
- Test for curl will be failed, because of a bug #3053
  It can detect a this type of problems

* [vcpkg_test_cmake] Add MODULE parameter to explicitly specify which type of integration to test.

* [bzip2] Fix casing of cmake module name
  • Loading branch information
miurahr authored and ras0219-msft committed Aug 31, 2018
1 parent cf1df56 commit ab54bfa
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 4 deletions.
2 changes: 2 additions & 0 deletions ports/bzip2/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ file(COPY ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/bzip2
file(RENAME ${CURRENT_PACKAGES_DIR}/share/bzip2/LICENSE ${CURRENT_PACKAGES_DIR}/share/bzip2/copyright)

file(COPY ${CMAKE_CURRENT_LIST_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})

vcpkg_test_cmake(PACKAGE_NAME BZip2 MODULE)
7 changes: 3 additions & 4 deletions ports/curl/portfile.cmake
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
include(vcpkg_common_functions)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO curl/curl
REF curl-7_61_0
SHA512 b6d2f57059e72139540cb93b945703857cb447920ed9b283993611453fed623432290adc5a3558181e3decc15c7cf54fff475010d922957807a37d1a1449be6c
HEAD_REF master
)

vcpkg_apply_patches(
SOURCE_PATH ${SOURCE_PATH}
PATCHES
${CMAKE_CURRENT_LIST_DIR}/0001_cmake.patch
${CMAKE_CURRENT_LIST_DIR}/0002_fix_uwp.patch
Expand Down Expand Up @@ -135,3 +132,5 @@ file(WRITE ${CURRENT_PACKAGES_DIR}/include/curl/curl.h "${CURL_H}")
vcpkg_copy_pdbs()

file(COPY ${CMAKE_CURRENT_LIST_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})

vcpkg_test_cmake(PACKAGE_NAME CURL MODULE)
2 changes: 2 additions & 0 deletions ports/libiconv/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ vcpkg_copy_pdbs()
# Handle copyright
file(COPY ${SOURCE_PATH}/COPYING.LIB DESTINATION ${CURRENT_PACKAGES_DIR}/share/libiconv)
file(RENAME ${CURRENT_PACKAGES_DIR}/share/libiconv/COPYING.LIB ${CURRENT_PACKAGES_DIR}/share/libiconv/copyright)

vcpkg_test_cmake(PACKAGE_NAME unofficial-iconv)
2 changes: 2 additions & 0 deletions ports/openssl-unix/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@ file(INSTALL ${MASTER_COPY_SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_D
if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
file(COPY ${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake DESTINATION ${CURRENT_PACKAGES_DIR}/share/openssl)
endif()

vcpkg_test_cmake(PACKAGE_NAME OpenSSL MODULE)
2 changes: 2 additions & 0 deletions ports/openssl-uwp/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,5 @@ file(INSTALL

file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)
file(COPY ${CMAKE_CURRENT_LIST_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})

vcpkg_test_cmake(PACKAGE_NAME OpenSSL MODULE)
2 changes: 2 additions & 0 deletions ports/openssl-windows/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,5 @@ vcpkg_copy_pdbs()

file(COPY ${CMAKE_CURRENT_LIST_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})
file(INSTALL ${MASTER_COPY_SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT} RENAME copyright)

vcpkg_test_cmake(PACKAGE_NAME OpenSSL MODULE)
2 changes: 2 additions & 0 deletions ports/zlib/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ file(INSTALL ${CMAKE_CURRENT_LIST_DIR}/LICENSE DESTINATION ${CURRENT_PACKAGES_DI
vcpkg_copy_pdbs()

file(COPY ${CMAKE_CURRENT_LIST_DIR}/usage DESTINATION ${CURRENT_PACKAGES_DIR}/share/${PORT})

vcpkg_test_cmake(PACKAGE_NAME ZLIB MODULE)
1 change: 1 addition & 0 deletions scripts/cmake/vcpkg_common_functions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ include(vcpkg_get_program_files_32_bit)
include(vcpkg_get_program_files_platform_bitness)
include(vcpkg_get_windows_sdk)
include(vcpkg_replace_string)
include(vcpkg_test_cmake)
53 changes: 53 additions & 0 deletions scripts/cmake/vcpkg_test_cmake.cmake
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 3 additions & 0 deletions scripts/templates/portfile.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@ vcpkg_install_cmake()

# Handle copyright
# file(INSTALL ${SOURCE_PATH}/LICENSE DESTINATION ${CURRENT_PACKAGES_DIR}/share/@PORT@ RENAME copyright)

# Post-build test for cmake libraries
# vcpkg_test_cmake(PACKAGE_NAME @PORT@)

0 comments on commit ab54bfa

Please sign in to comment.