From e3007c92e04416d7fba2db5de757c27d22d4af6b Mon Sep 17 00:00:00 2001 From: "Daniele E. Domenichelli" Date: Tue, 15 Jul 2014 19:51:16 +0200 Subject: [PATCH] CMakePackageConfigHelpers: Add unit tests for INSTALL_PREFIX option --- Tests/FindPackageTest/CMakeLists.txt | 38 ++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt index 092bf20c5..f311fb9dd 100644 --- a/Tests/FindPackageTest/CMakeLists.txt +++ b/Tests/FindPackageTest/CMakeLists.txt @@ -374,6 +374,7 @@ endif() include(CMakePackageConfigHelpers) +# Generate a config file ready to be installed. set(INCLUDE_INSTALL_DIR include ) set(SHARE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/" ) set(CURRENT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}" ) @@ -407,6 +408,43 @@ if(Relocatable_FOUND) message(SEND_ERROR "Relocatable_FOUND set to TRUE !") endif() +# Generate a config file for the build tree. +set(INCLUDE_INSTALL_DIR include ) +set(SHARE_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/share/" ) +set(CURRENT_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}" ) + +configure_package_config_file(RelocatableConfig.cmake.in "${CMAKE_CURRENT_BINARY_DIR}/RelocatableConfig.cmake" + INSTALL_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" + PATH_VARS INCLUDE_INSTALL_DIR SHARE_INSTALL_DIR CURRENT_BUILD_DIR + INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}" + ) + +set(Relocatable_FIND_COMPONENTS AComp BComp CComp) +set(Relocatable_FIND_REQUIRED_BComp 1) +include("${CMAKE_CURRENT_BINARY_DIR}/RelocatableConfig.cmake") + +if(NOT "${RELOC_INCLUDE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/include") + message(SEND_ERROR "RELOC_INCLUDE_DIR set by configure_package_config_file() is set to \"${RELOC_INCLUDE_DIR}\" (expected \"${CMAKE_CURRENT_BINARY_DIR}/include\")") +endif() + +if(NOT "${RELOC_SHARE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}/share/") + message(SEND_ERROR "RELOC_SHARE_DIR set by configure_package_config_file() is set to \"${RELOC_SHARE_DIR}\" (expected \"${CMAKE_CURRENT_BINARY_DIR}/share/\")") +endif() + +if(NOT "${RELOC_BUILD_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}") + message(SEND_ERROR "RELOC_BUILD_DIR set by configure_package_config_file() is set to \"${RELOC_BUILD_DIR}\" (expected \"${CMAKE_CURRENT_BINARY_DIR}\")") +endif() + +if(NOT DEFINED Relocatable_FOUND) + message(SEND_ERROR "Relocatable_FOUND not defined !") +endif() + +if(Relocatable_FOUND) + message(SEND_ERROR "Relocatable_FOUND set to TRUE !") +endif() + + + #----------------------------------------------------------------------------- # Test write_basic_config_version_file().