diff --git a/Tests/FindPackageTest/CMakeLists.txt b/Tests/FindPackageTest/CMakeLists.txt index a77713f27..fc82a1e1b 100644 --- a/Tests/FindPackageTest/CMakeLists.txt +++ b/Tests/FindPackageTest/CMakeLists.txt @@ -320,16 +320,23 @@ endif() #----------------------------------------------------------------------------- # Test export(PACKAGE) with find_package. + +# Choose a unique version. +string(REGEX REPLACE "-.*$" "" version ${CMAKE_VERSION}) +string(RANDOM LENGTH 4 ALPHABET "0123456789" v) +set(version "${version}.${v}") + message(STATUS "Preparing export(PACKAGE) test project") try_compile(EXPORTER_COMPILED ${FindPackageTest_BINARY_DIR}/Exporter ${FindPackageTest_SOURCE_DIR}/Exporter CMakeTestExportPackage dummy + CMAKE_FLAGS + -Dversion=${version} OUTPUT_VARIABLE output) message(STATUS "Searching for export(PACKAGE) test project") set(CMakeTestExportPackage_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE) -string(REGEX REPLACE "-.*$" "" version ${CMAKE_VERSION}) find_package(CMakeTestExportPackage 1.${version} EXACT REQUIRED) #----------------------------------------------------------------------------- diff --git a/Tests/FindPackageTest/Exporter/CMakeTestExportPackageConfigVersion.cmake.in b/Tests/FindPackageTest/Exporter/CMakeTestExportPackageConfigVersion.cmake.in index 42bd84ea8..6eac6e672 100644 --- a/Tests/FindPackageTest/Exporter/CMakeTestExportPackageConfigVersion.cmake.in +++ b/Tests/FindPackageTest/Exporter/CMakeTestExportPackageConfigVersion.cmake.in @@ -1,5 +1,5 @@ # Test config file. -set(PACKAGE_VERSION "1.@CMAKE_VERSION@") +set(PACKAGE_VERSION "1.@version@") if("${PACKAGE_FIND_VERSION}" VERSION_EQUAL "${PACKAGE_VERSION}") set(PACKAGE_VERSION_COMPATIBLE 1) set(PACKAGE_VERSION_EXACT 1)