aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorHiroshi Miura <miurahr@linux.com>2018-08-31 09:07:14 +0900
committerRobert Schumacher <roschuma@microsoft.com>2018-08-30 17:07:14 -0700
commitab54bfa0cc98b96a6cffe75e4045ccbd366dbe46 (patch)
treea25b3f8c74c876cea9d101eaa65bc256d8057514 /scripts
parentcf1df56e0df7b5a97c30b6a75f910c20d0fb3692 (diff)
downloadvcpkg-ab54bfa0cc98b96a6cffe75e4045ccbd366dbe46.tar.gz
vcpkg-ab54bfa0cc98b96a6cffe75e4045ccbd366dbe46.zip
[vcpkg] post-build cmake test (#3431)
* [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
Diffstat (limited to 'scripts')
-rw-r--r--scripts/cmake/vcpkg_common_functions.cmake1
-rw-r--r--scripts/cmake/vcpkg_test_cmake.cmake53
-rw-r--r--scripts/templates/portfile.in.cmake3
3 files changed, 57 insertions, 0 deletions
diff --git a/scripts/cmake/vcpkg_common_functions.cmake b/scripts/cmake/vcpkg_common_functions.cmake
index f4f149794..90a3e2814 100644
--- a/scripts/cmake/vcpkg_common_functions.cmake
+++ b/scripts/cmake/vcpkg_common_functions.cmake
@@ -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)
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()
diff --git a/scripts/templates/portfile.in.cmake b/scripts/templates/portfile.in.cmake
index e89ad4640..e44f53aa8 100644
--- a/scripts/templates/portfile.in.cmake
+++ b/scripts/templates/portfile.in.cmake
@@ -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@)