1 cmake_minimum_required (VERSION 2.6)
2 PROJECT(FindPackageTest)
4 # Look for a package that has a find module and may be found.
5 FIND_PACKAGE(OpenGL QUIET)
7 # Look for a package that has no find module and will not be found.
8 FIND_PACKAGE(NotAPackage QUIET)
10 # Look for a package that has an advanced find module.
11 FIND_PACKAGE(VTK QUIET)
13 ADD_EXECUTABLE(FindPackageTest FindPackageTest.cxx)
15 # test behaviour of cmFindBase wrt. the CMAKE_PREFIX_PATH variable
16 # foo.h should be found in ${CMAKE_CURRENT_SOURCE_DIR}/include:
18 SET(CMAKE_PREFIX_PATH /blub /blah "${CMAKE_CURRENT_SOURCE_DIR}")
19 FIND_PATH(FOO_DIR foo.h)
22 MESSAGE(FATAL_ERROR "Did not find foo.h which is in ${CMAKE_CURRENT_SOURCE_DIR}/include
23 CMAKE_PREFIX_PATH = ${CMAKE_PREFIX_PATH}")
26 LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
27 FIND_PACKAGE(VersionTestA 1)
28 FIND_PACKAGE(VersionTestB 1.2)
29 FIND_PACKAGE(VersionTestC 1.2.3)
30 FIND_PACKAGE(VersionTestD 1.2.3.4)
32 #-----------------------------------------------------------------------------
34 #SET(CMAKE_FIND_DEBUG_MODE 1)
36 # For purposes of the test wipe out previous find results.
38 foo Foo Bar TFramework Tframework TApp Tapp Special
39 VersionedA VersionedB VersionedC VersionedD VersionedE
41 RecursiveA RecursiveB RecursiveC
43 FOREACH(p ${PACKAGES})
44 SET(${p}_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
47 # Enable framework and bundle searching. Make sure bundles are found
48 # before unix-syle packages.
49 SET(CMAKE_FIND_FRAMEWORK LAST)
50 SET(CMAKE_FIND_APPBUNDLE FIRST)
52 # Set the wrong answer for a find to make sure it re-finds.
53 set(VersionedA_DIR ${CMAKE_CURRENT_SOURCE_DIR}/lib/cmake/zot-4.0)
55 # Look for packages with new-style signatures.
56 FIND_PACKAGE(foo NO_MODULE)
57 FIND_PACKAGE(Foo CONFIGS FooConfig.cmake)
59 FIND_PACKAGE(TFramework CONFIGS TFrameworkConfig.cmake)
60 FIND_PACKAGE(Tframework)
62 FIND_PACKAGE(Tapp CONFIGS tapp-config.cmake)
63 FIND_PACKAGE(Special NAMES Suffix SuffixTest PATH_SUFFIXES test)
64 FIND_PACKAGE(VersionedA 2 NAMES zot)
65 FIND_PACKAGE(VersionedB 3.1 EXACT NAMES zot)
66 FIND_PACKAGE(VersionedC 4.0 EXACT NAMES zot)
67 FIND_PACKAGE(VersionedD 1.1 EXACT NAMES Baz)
68 FIND_PACKAGE(VersionedE 1.2 EXACT NAMES Baz)
70 # HINTS should override the system but PATHS should not
71 LIST(INSERT CMAKE_SYSTEM_PREFIX_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/A")
72 FIND_PACKAGE(wibbleA NAMES wibble PATHS B)
73 FIND_PACKAGE(wibbleB NAMES wibble HINTS B)
75 # Look for package with recursive find-modules.
76 FIND_PACKAGE(RecursiveA)
77 FIND_PACKAGE(RecursiveB 2)
78 FIND_PACKAGE(RecursiveC 3.1 EXACT)
80 # Expected locations at which packages should be found.
81 SET(foo_EXPECTED "lib/foo-1.2/foo-config.cmake")
82 SET(Foo_EXPECTED "lib/foo-1.2/CMake/FooConfig.cmake")
83 SET(Bar_EXPECTED "lib/Bar/BarConfig.cmake")
84 SET(Special_EXPECTED "lib/suffix/test/SuffixTestConfig.cmake")
85 SET(TFramework_EXPECTED
86 "TFramework.framework/Versions/A/Resources/CMake/TFrameworkConfig.cmake")
87 SET(Tframework_EXPECTED
88 "TFramework.framework/Versions/A/Resources/tframework-config.cmake")
90 "TApp.app/Contents/Resources/TAppConfig.cmake")
92 "TApp.app/Contents/Resources/cmake/tapp-config.cmake")
93 SET(VersionedA_EXPECTED "lib/zot-2.0/zot-config.cmake")
94 SET(VersionedB_EXPECTED "lib/zot-3.1/zot-config.cmake")
95 SET(VersionedC_EXPECTED "lib/cmake/zot-4.0/zot-config.cmake")
96 SET(VersionedD_EXPECTED "Baz 1.1/BazConfig.cmake")
97 SET(VersionedE_EXPECTED "Baz 1.2/CMake/BazConfig.cmake")
98 SET(wibbleA_EXPECTED "A/wibble-config.cmake")
99 SET(wibbleB_EXPECTED "B/wibble-config.cmake")
100 SET(RecursiveA_EXPECTED "lib/RecursiveA/recursivea-config.cmake")
101 SET(RecursiveB_EXPECTED "lib/zot-2.0/zot-config.cmake")
102 SET(RecursiveC_EXPECTED "lib/zot-3.1/zot-config.cmake")
105 FOREACH(p ${PACKAGES})
107 # Convert to relative path for comparison to expected location.
108 FILE(RELATIVE_PATH REL_${p}_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}"
112 IF(CMAKE_FIND_DEBUG_MODE)
113 MESSAGE("Package ${p} found [${REL_${p}_CONFIG}]")
114 ENDIF(CMAKE_FIND_DEBUG_MODE)
116 # Check and report failure.
117 IF(NOT "${REL_${p}_CONFIG}" STREQUAL "${${p}_EXPECTED}")
119 "Package ${p} should have been [${${p}_EXPECTED}] but "
120 "was [${REL_${p}_CONFIG}]")
121 ENDIF(NOT "${REL_${p}_CONFIG}" STREQUAL "${${p}_EXPECTED}")
123 MESSAGE(SEND_ERROR "Package ${p} not found!")
127 # Check that version information was extracted.
128 IF(NOT "${VersionedA_VERSION}" STREQUAL "2.0")
130 "Package VersionedA is version [${VersionedA_VERSION}], not [2.0]")
131 ENDIF(NOT "${VersionedA_VERSION}" STREQUAL "2.0")
132 IF(NOT "${VersionedA_VERSION_MAJOR}" STREQUAL "2")
134 "Package VersionedA is major version [${VersionedA_VERSION_MAJOR}], not [2]")
135 ENDIF(NOT "${VersionedA_VERSION_MAJOR}" STREQUAL "2")
136 IF(NOT "${VersionedA_VERSION_MINOR}" STREQUAL "0")
138 "Package VersionedA is minor version [${VersionedA_VERSION_MINOR}], not [0]")
139 ENDIF(NOT "${VersionedA_VERSION_MINOR}" STREQUAL "0")
141 IF(NOT "${VersionedB_VERSION}" STREQUAL "3.1")
143 "Package VersionedB is version [${VersionedB_VERSION}], not [3.1]")
144 ENDIF(NOT "${VersionedB_VERSION}" STREQUAL "3.1")
145 IF(NOT "${VersionedB_VERSION_MAJOR}" STREQUAL "3")
147 "Package VersionedB is major version [${VersionedB_VERSION_MAJOR}], not [3]")
148 ENDIF(NOT "${VersionedB_VERSION_MAJOR}" STREQUAL "3")
149 IF(NOT "${VersionedB_VERSION_MINOR}" STREQUAL "1")
151 "Package VersionedB is minor version [${VersionedB_VERSION_MINOR}], not [1]")
152 ENDIF(NOT "${VersionedB_VERSION_MINOR}" STREQUAL "1")
154 IF(NOT "${Special_VERSION}" STREQUAL "1.2")
156 "Package Special is version [${Special_VERSION}], not [1.2]")
157 ENDIF(NOT "${Special_VERSION}" STREQUAL "1.2")
158 IF(NOT "${Special_VERSION_MAJOR}" STREQUAL "1")
160 "Package Special is major version [${Special_VERSION_MAJOR}], not [1]")
161 ENDIF(NOT "${Special_VERSION_MAJOR}" STREQUAL "1")
162 IF(NOT "${Special_VERSION_MINOR}" STREQUAL "2")
164 "Package Special is minor version [${Special_VERSION_MINOR}], not [2]")
165 ENDIF(NOT "${Special_VERSION_MINOR}" STREQUAL "2")
167 # Test version number comparison.
168 IF(NOT "1.2.3.4" VERSION_LESS "1.2.3.5")
169 MESSAGE(SEND_ERROR "1.2.3.4 VERSION_LESS 1.2.3.5 is not true!")
171 IF(NOT "1.2" VERSION_LESS "1.10")
172 MESSAGE(SEND_ERROR "1.2 VERSION_LESS 1.10 is not true!")
174 IF(NOT "1.02" VERSION_GREATER "1.1")
175 MESSAGE(SEND_ERROR "1.02 VERSION_GREATER 1.1 is not true!")
177 IF("1.2.3" VERSION_GREATER "1.2.3.4")
178 MESSAGE(SEND_ERROR "1.2.3 VERSION_GREATER 1.2.3.4 is not false!")
180 IF(NOT "1.2" VERSION_EQUAL "1.2.0.0")
181 MESSAGE(SEND_ERROR "1.2 VERSION_EQUAL 1.2.0.0 is not true!")
184 #-----------------------------------------------------------------------------
185 # Test export(PACKAGE) with find_package.
186 MESSAGE(STATUS "Preparing export(PACKAGE) test project")
187 TRY_COMPILE(EXPORTER_COMPILED
188 ${FindPackageTest_BINARY_DIR}/Exporter
189 ${FindPackageTest_SOURCE_DIR}/Exporter
190 CMakeTestExportPackage dummy
191 OUTPUT_VARIABLE output)
192 MESSAGE(STATUS "Searching for export(PACKAGE) test project")
193 SET(CMakeTestExportPackage_DIR "" CACHE FILEPATH
194 "Wipe out find results for testing." FORCE)
195 FIND_PACKAGE(CMakeTestExportPackage 1.${CMAKE_VERSION} EXACT REQUIRED)