FindBaseTest.cmake.in 2.4 KB

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