From 0bba365ff5423fc51d574d17b7934e3a0148ac2e Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Wed, 26 Feb 2014 21:30:18 +0100 Subject: [PATCH] Add test for find_dependency macro. --- Tests/CMakeLists.txt | 1 + Tests/Module/FindDependency/CMakeLists.txt | 10 ++++++++++ Tests/Module/FindDependency/main.cpp | 17 +++++++++++++++++ .../packages/Pack1/Pack1Config.cmake | 9 +++++++++ .../packages/Pack1/Pack1ConfigVersion.cmake | 11 +++++++++++ .../packages/Pack2/Pack2Config.cmake | 5 +++++ .../packages/Pack2/Pack2ConfigVersion.cmake | 11 +++++++++++ .../packages/Pack3/Pack3Config.cmake | 5 +++++ .../packages/Pack3/Pack3ConfigVersion.cmake | 11 +++++++++++ 9 files changed, 80 insertions(+) create mode 100644 Tests/Module/FindDependency/CMakeLists.txt create mode 100644 Tests/Module/FindDependency/main.cpp create mode 100644 Tests/Module/FindDependency/packages/Pack1/Pack1Config.cmake create mode 100644 Tests/Module/FindDependency/packages/Pack1/Pack1ConfigVersion.cmake create mode 100644 Tests/Module/FindDependency/packages/Pack2/Pack2Config.cmake create mode 100644 Tests/Module/FindDependency/packages/Pack2/Pack2ConfigVersion.cmake create mode 100644 Tests/Module/FindDependency/packages/Pack3/Pack3Config.cmake create mode 100644 Tests/Module/FindDependency/packages/Pack3/Pack3ConfigVersion.cmake diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index 8074a01d8..c414850f3 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -381,6 +381,7 @@ if(BUILD_TESTING) list(APPEND TEST_BUILD_DIRS "${CMake_BINARY_DIR}/Tests/Module/ExternalData") ADD_TEST_MACRO(Module.GenerateExportHeader GenerateExportHeader) + ADD_TEST_MACRO(Module.FindDependency FindDependency) if (APPLE OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") include(CheckCXXCompilerFlag) diff --git a/Tests/Module/FindDependency/CMakeLists.txt b/Tests/Module/FindDependency/CMakeLists.txt new file mode 100644 index 000000000..b13f48ac8 --- /dev/null +++ b/Tests/Module/FindDependency/CMakeLists.txt @@ -0,0 +1,10 @@ + +cmake_minimum_required(VERSION 3.0) +project(FindDependency) + +set(CMAKE_PREFIX_PATH "${CMAKE_CURRENT_SOURCE_DIR}/packages") + +find_package(Pack1 REQUIRED) + +add_executable(FindDependency main.cpp) +target_link_libraries(FindDependency Pack1::Lib) diff --git a/Tests/Module/FindDependency/main.cpp b/Tests/Module/FindDependency/main.cpp new file mode 100644 index 000000000..d635b3131 --- /dev/null +++ b/Tests/Module/FindDependency/main.cpp @@ -0,0 +1,17 @@ + +#ifndef HAVE_PACK1 +#error Expected HAVE_PACK1 +#endif + +#ifndef HAVE_PACK2 +#error Expected HAVE_PACK2 +#endif + +#ifndef HAVE_PACK3 +#error Expected HAVE_PACK3 +#endif + +int main(int argc, char** argv) +{ + return 0; +} diff --git a/Tests/Module/FindDependency/packages/Pack1/Pack1Config.cmake b/Tests/Module/FindDependency/packages/Pack1/Pack1Config.cmake new file mode 100644 index 000000000..ff533c2a0 --- /dev/null +++ b/Tests/Module/FindDependency/packages/Pack1/Pack1Config.cmake @@ -0,0 +1,9 @@ + +include(CMakeFindDependencyMacro) + +find_dependency(Pack2 2.3) +find_dependency(Pack3) + +add_library(Pack1::Lib INTERFACE IMPORTED) +set_property(TARGET Pack1::Lib PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_PACK1) +set_property(TARGET Pack1::Lib PROPERTY INTERFACE_LINK_LIBRARIES Pack2::Lib Pack3::Lib) diff --git a/Tests/Module/FindDependency/packages/Pack1/Pack1ConfigVersion.cmake b/Tests/Module/FindDependency/packages/Pack1/Pack1ConfigVersion.cmake new file mode 100644 index 000000000..dfb7b6c84 --- /dev/null +++ b/Tests/Module/FindDependency/packages/Pack1/Pack1ConfigVersion.cmake @@ -0,0 +1,11 @@ + +set(PACKAGE_VERSION "1.3") + +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" ) + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() diff --git a/Tests/Module/FindDependency/packages/Pack2/Pack2Config.cmake b/Tests/Module/FindDependency/packages/Pack2/Pack2Config.cmake new file mode 100644 index 000000000..672288ec8 --- /dev/null +++ b/Tests/Module/FindDependency/packages/Pack2/Pack2Config.cmake @@ -0,0 +1,5 @@ + +set(PACK2_VAR ON) + +add_library(Pack2::Lib INTERFACE IMPORTED) +set_property(TARGET Pack2::Lib PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_PACK2) diff --git a/Tests/Module/FindDependency/packages/Pack2/Pack2ConfigVersion.cmake b/Tests/Module/FindDependency/packages/Pack2/Pack2ConfigVersion.cmake new file mode 100644 index 000000000..42f58c05b --- /dev/null +++ b/Tests/Module/FindDependency/packages/Pack2/Pack2ConfigVersion.cmake @@ -0,0 +1,11 @@ + +set(PACKAGE_VERSION "2.4") + +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" ) + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif() diff --git a/Tests/Module/FindDependency/packages/Pack3/Pack3Config.cmake b/Tests/Module/FindDependency/packages/Pack3/Pack3Config.cmake new file mode 100644 index 000000000..25c32f326 --- /dev/null +++ b/Tests/Module/FindDependency/packages/Pack3/Pack3Config.cmake @@ -0,0 +1,5 @@ + +set(PACK3_VAR ON) + +add_library(Pack3::Lib INTERFACE IMPORTED) +set_property(TARGET Pack3::Lib PROPERTY INTERFACE_COMPILE_DEFINITIONS HAVE_PACK3) diff --git a/Tests/Module/FindDependency/packages/Pack3/Pack3ConfigVersion.cmake b/Tests/Module/FindDependency/packages/Pack3/Pack3ConfigVersion.cmake new file mode 100644 index 000000000..870f7478d --- /dev/null +++ b/Tests/Module/FindDependency/packages/Pack3/Pack3ConfigVersion.cmake @@ -0,0 +1,11 @@ + +set(PACKAGE_VERSION "1.4") + +if("${PACKAGE_VERSION}" VERSION_LESS "${PACKAGE_FIND_VERSION}" ) + set(PACKAGE_VERSION_COMPATIBLE FALSE) +else() + set(PACKAGE_VERSION_COMPATIBLE TRUE) + if( "${PACKAGE_FIND_VERSION}" STREQUAL "${PACKAGE_VERSION}") + set(PACKAGE_VERSION_EXACT TRUE) + endif() +endif()