Updated formatting of documentation plus a little reorganization.
[cmake.git] / Tests / CMakeTests / FindBaseTest.cmake.in
blob02f70015243cb9648bd979b88ed49dc800608fdd
1 set(MY_SOURCE_DIR "@CMAKE_CURRENT_SOURCE_DIR@")
3 # The find_* commands do path normalization so we should do so too
4 # before comparing results.
5 get_filename_component(MY_SOURCE_DIR "${MY_SOURCE_DIR}" ABSOLUTE)
7 set(_HEADER cmake_i_do_not_exist_in_the_system.h)
8 set(_HEADER_FULL "${MY_SOURCE_DIR}/include/${_HEADER}")
9 set(_HEADER_FULL_A "${MY_SOURCE_DIR}/A/include/${_HEADER}")
11 # at first check that the header isn't found without special measures
12 find_file(FOO_H_1 ${_HEADER})
13 if(FOO_H_1)
14    message(FATAL_ERROR "${_HEADER} found: ${FOO_H_1}, it should not exist !")
15 endif(FOO_H_1)
17 # The HINTS option should override the system but the PATHS option
18 # should not.
19 set(CMAKE_SYSTEM_PREFIX_PATH ${MY_SOURCE_DIR})
20 find_file(TEST_H_1 ${_HEADER} HINTS ${MY_SOURCE_DIR}/A/include)
21 find_file(TEST_H_2 ${_HEADER} PATHS ${MY_SOURCE_DIR}/A/include)
22 if(NOT "${TEST_H_1}" STREQUAL "${_HEADER_FULL_A}")
23    message(FATAL_ERROR "Did not find \"${_HEADER_FULL_A}\"\ngot \"${TEST_H_1}\" instead!")
24 endif(NOT "${TEST_H_1}" STREQUAL "${_HEADER_FULL_A}")
25 if(NOT "${TEST_H_2}" STREQUAL "${_HEADER_FULL}")
26    message(FATAL_ERROR "Did not find \"${_HEADER_FULL}\"\ngot \"${TEST_H_2}\" instead!")
27 endif(NOT "${TEST_H_2}" STREQUAL "${_HEADER_FULL}")
28 set(CMAKE_SYSTEM_PREFIX_PATH)
30 # with this it still should not be found, since the include/ subdir is still missing
31 set(CMAKE_INCLUDE_PATH "${MY_SOURCE_DIR}")
32 find_file(FOO_H_2 ${_HEADER})
33 if(FOO_H_2)
34    message(FATAL_ERROR "${_HEADER} found: ${FOO_H_2}, it should not exist !")
35 endif(FOO_H_2)
37 # now with the PATH_SUFFIX it should be found
38 find_file(FOO_H_3 NAMES ${_HEADER} PATH_SUFFIXES include )
39 if(NOT "${FOO_H_3}" STREQUAL "${_HEADER_FULL}")
40    message(FATAL_ERROR "Did not find \"${_HEADER_FULL}\"\ngot ${FOO_H_3} instead !")
41 endif(NOT "${FOO_H_3}" STREQUAL "${_HEADER_FULL}")
43 # without PATH_SUFFIX, but with a CMAKE_INCLUDE_PATH it should not be found
44 set(CMAKE_INCLUDE_PATH /include)
45 find_file(FOO_H_4 ${_HEADER})
46 if(FOO_H_4)
47    message(FATAL_ERROR "${_HEADER} found: ${FOO_H_4}, it should not exist !")
48 endif(FOO_H_4)
50 # when setting CMAKE_FIND_ROOT_PATH to the current source dir,
51 # together with the CMAKE_INCLUDE_PATH it should be found
52 set(CMAKE_FIND_ROOT_PATH blub "${MY_SOURCE_DIR}")
53 find_file(FOO_H_5 ${_HEADER})
54 if(NOT "${FOO_H_5}" STREQUAL "${_HEADER_FULL}")
55    message(FATAL_ERROR "Did not find \"${_HEADER_FULL}\"\ngot ${FOO_H_5} instead !")
56 endif(NOT "${FOO_H_5}" STREQUAL "${_HEADER_FULL}")
58 # by explicitely disabling CMAKE_FIND_ROOT_PATH again it shouldn't be found
59 find_file(FOO_H_6 ${_HEADER} NO_CMAKE_FIND_ROOT_PATH)
60 if(FOO_H_6)
61    message(FATAL_ERROR "${_HEADER} found: ${FOO_H_6}, it should not exist !")
62 endif(FOO_H_6)