summaryrefslogtreecommitdiffstats
path: root/Tests/FindPackageTest/CMakeLists.txt
blob: 8b3225e7590509d5c7608d74096c93022cb0af70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
PROJECT(FindPackageTest)

# Look for a package that has a find module and may be found.
FIND_PACKAGE(OpenGL QUIET)

# Look for a package that has no find module and will not be found.
FIND_PACKAGE(NotAPackage QUIET)

# Look for a package that has an advanced find module.
FIND_PACKAGE(VTK QUIET)

ADD_EXECUTABLE(FindPackageTest FindPackageTest.cxx)

# test behaviour of cmFindBase wrt. the CMAKE_PREFIX_PATH variable
# foo.h should be found in ${CMAKE_CURRENT_SOURCE_DIR}/include:

SET(CMAKE_PREFIX_PATH /blub /blah "${CMAKE_CURRENT_SOURCE_DIR}")
FIND_PATH(FOO_DIR foo.h)

IF(NOT FOO_DIR)
  MESSAGE(FATAL_ERROR "Did not find foo.h which is in ${CMAKE_CURRENT_SOURCE_DIR}/include
  CMAKE_PREFIX_PATH = ${CMAKE_PREFIX_PATH}")
ENDIF(NOT FOO_DIR)

LIST(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
FIND_PACKAGE(VersionTestA 1)
FIND_PACKAGE(VersionTestB 1.2)
FIND_PACKAGE(VersionTestC 1.2.3)

#-----------------------------------------------------------------------------

#SET(CMAKE_FIND_DEBUG_MODE 1)

# For purposes of the test wipe out previous find results.
SET(PACKAGES foo Foo Bar TFramework Tframework TApp Tapp Special)
FOREACH(p ${PACKAGES})
  SET(${p}_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
ENDFOREACH(p)

# Enable framework and bundle searching.  Make sure bundles are found
# before unix-syle packages.
SET(CMAKE_FIND_FRAMEWORK LAST)
SET(CMAKE_FIND_APPBUNDLE FIRST)

# Look for packages with new-style signatures.
FIND_PACKAGE(foo NO_MODULE)
FIND_PACKAGE(Foo CONFIGS FooConfig.cmake)
FIND_PACKAGE(Bar)
FIND_PACKAGE(TFramework CONFIGS TFrameworkConfig.cmake)
FIND_PACKAGE(Tframework)
FIND_PACKAGE(TApp)
FIND_PACKAGE(Tapp CONFIGS tapp-config.cmake)
FIND_PACKAGE(Special NAMES Suffix SuffixTest PATH_SUFFIXES test)

# Expected locations at which packages should be found.
SET(foo_EXPECTED "lib/foo-1.2/foo-config.cmake")
SET(Foo_EXPECTED "lib/foo-1.2/CMake/FooConfig.cmake")
SET(Bar_EXPECTED "lib/Bar/BarConfig.cmake")
SET(Special_EXPECTED "lib/suffix/test/SuffixTestConfig.cmake")
SET(TFramework_EXPECTED
  "TFramework.framework/Versions/A/Resources/CMake/TFrameworkConfig.cmake")
SET(Tframework_EXPECTED
  "TFramework.framework/Versions/A/Resources/tframework-config.cmake")
SET(TApp_EXPECTED
  "TApp.app/Contents/Resources/TAppConfig.cmake")
SET(Tapp_EXPECTED
  "TApp.app/Contents/Resources/cmake/tapp-config.cmake")

# Check the results.
FOREACH(p ${PACKAGES})
  IF(${p}_FOUND)
    # Convert to relative path for comparison to expected location.
    FILE(RELATIVE_PATH REL_${p}_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}"
      "${${p}_CONFIG}")

    # Debugging output.
    IF(CMAKE_FIND_DEBUG_MODE)
      MESSAGE("Package ${p} found [${REL_${p}_CONFIG}]")
    ENDIF(CMAKE_FIND_DEBUG_MODE)

    # Check and report failure.
    IF(NOT "${REL_${p}_CONFIG}" STREQUAL "${${p}_EXPECTED}")
      MESSAGE(SEND_ERROR
        "Package ${p} should have been [${${p}_EXPECTED}] but "
        "was [${REL_${p}_CONFIG}]")
    ENDIF(NOT "${REL_${p}_CONFIG}" STREQUAL "${${p}_EXPECTED}")
  ELSE(${p}_FOUND)
    MESSAGE(SEND_ERROR "Package ${p} not found!")
  ENDIF(${p}_FOUND)
ENDFOREACH(p)