ENH: Add test for new find_* command HINTS option.

This commit is contained in:
Brad King 2008-06-09 15:09:14 -04:00
parent 5b406c9044
commit fdb17d604c
5 changed files with 25 additions and 0 deletions

View File

@ -0,0 +1 @@
/* empty header file */

View File

@ -6,6 +6,7 @@ get_filename_component(MY_SOURCE_DIR "${MY_SOURCE_DIR}" ABSOLUTE)
set(_HEADER cmake_i_do_not_exist_in_the_system.h) set(_HEADER cmake_i_do_not_exist_in_the_system.h)
set(_HEADER_FULL "${MY_SOURCE_DIR}/include/${_HEADER}") set(_HEADER_FULL "${MY_SOURCE_DIR}/include/${_HEADER}")
set(_HEADER_FULL_A "${MY_SOURCE_DIR}/A/include/${_HEADER}")
# at first check that the header isn't found without special measures # at first check that the header isn't found without special measures
find_file(FOO_H_1 ${_HEADER}) find_file(FOO_H_1 ${_HEADER})
@ -13,6 +14,19 @@ if(FOO_H_1)
message(FATAL_ERROR "${_HEADER} found: ${FOO_H_1}, it should not exist !") message(FATAL_ERROR "${_HEADER} found: ${FOO_H_1}, it should not exist !")
endif(FOO_H_1) endif(FOO_H_1)
# The HINTS option should override the system but the PATHS option
# should not.
set(CMAKE_SYSTEM_PREFIX_PATH ${MY_SOURCE_DIR})
find_file(TEST_H_1 ${_HEADER} HINTS ${MY_SOURCE_DIR}/A/include)
find_file(TEST_H_2 ${_HEADER} PATHS ${MY_SOURCE_DIR}/A/include)
if(NOT "${TEST_H_1}" STREQUAL "${_HEADER_FULL_A}")
message(FATAL_ERROR "Did not find \"${_HEADER_FULL_A}\"\ngot \"${TEST_H_1}\" instead!")
endif(NOT "${TEST_H_1}" STREQUAL "${_HEADER_FULL_A}")
if(NOT "${TEST_H_2}" STREQUAL "${_HEADER_FULL}")
message(FATAL_ERROR "Did not find \"${_HEADER_FULL}\"\ngot \"${TEST_H_2}\" instead!")
endif(NOT "${TEST_H_2}" STREQUAL "${_HEADER_FULL}")
set(CMAKE_SYSTEM_PREFIX_PATH)
# with this it still should not be found, since the include/ subdir is still missing # with this it still should not be found, since the include/ subdir is still missing
set(CMAKE_INCLUDE_PATH "${MY_SOURCE_DIR}") set(CMAKE_INCLUDE_PATH "${MY_SOURCE_DIR}")
find_file(FOO_H_2 ${_HEADER}) find_file(FOO_H_2 ${_HEADER})

View File

@ -0,0 +1 @@
# Test config file.

View File

@ -0,0 +1 @@
# Test config file.

View File

@ -36,6 +36,7 @@ FIND_PACKAGE(VersionTestC 1.2.3)
SET(PACKAGES SET(PACKAGES
foo Foo Bar TFramework Tframework TApp Tapp Special foo Foo Bar TFramework Tframework TApp Tapp Special
VersionedA VersionedB VersionedA VersionedB
wibbleA wibbleB
) )
FOREACH(p ${PACKAGES}) FOREACH(p ${PACKAGES})
SET(${p}_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE) SET(${p}_DIR "" CACHE FILEPATH "Wipe out find results for testing." FORCE)
@ -58,6 +59,11 @@ FIND_PACKAGE(Special NAMES Suffix SuffixTest PATH_SUFFIXES test)
FIND_PACKAGE(VersionedA 2 NAMES zot) FIND_PACKAGE(VersionedA 2 NAMES zot)
FIND_PACKAGE(VersionedB 3.1 EXACT NAMES zot) FIND_PACKAGE(VersionedB 3.1 EXACT NAMES zot)
# HINTS should override the system but PATHS should not
LIST(INSERT CMAKE_SYSTEM_PREFIX_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/A")
FIND_PACKAGE(wibbleA NAMES wibble PATHS B)
FIND_PACKAGE(wibbleB NAMES wibble HINTS B)
# Expected locations at which packages should be found. # 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/foo-config.cmake")
SET(Foo_EXPECTED "lib/foo-1.2/CMake/FooConfig.cmake") SET(Foo_EXPECTED "lib/foo-1.2/CMake/FooConfig.cmake")
@ -73,6 +79,8 @@ SET(Tapp_EXPECTED
"TApp.app/Contents/Resources/cmake/tapp-config.cmake") "TApp.app/Contents/Resources/cmake/tapp-config.cmake")
SET(VersionedA_EXPECTED "lib/zot-2.0/zot-config.cmake") SET(VersionedA_EXPECTED "lib/zot-2.0/zot-config.cmake")
SET(VersionedB_EXPECTED "lib/zot-3.1/zot-config.cmake") SET(VersionedB_EXPECTED "lib/zot-3.1/zot-config.cmake")
SET(wibbleA_EXPECTED "A/wibble-config.cmake")
SET(wibbleB_EXPECTED "B/wibble-config.cmake")
# Check the results. # Check the results.
FOREACH(p ${PACKAGES}) FOREACH(p ${PACKAGES})