RunCMakeTest.cmake 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. cmake_minimum_required(VERSION 3.16)
  2. include(RunCMake)
  3. # Function to build and install a project.
  4. function(run_install_test case)
  5. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${case}-build)
  6. set(RunCMake_TEST_NO_CLEAN 1)
  7. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  8. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  9. run_cmake(${case})
  10. run_cmake_command(${case}-build ${CMAKE_COMMAND} --build . --config Debug)
  11. # Check "all" components.
  12. set(CMAKE_INSTALL_PREFIX ${RunCMake_TEST_BINARY_DIR}/root-all)
  13. run_cmake_command(${case}-all ${CMAKE_COMMAND} --install . --prefix ${CMAKE_INSTALL_PREFIX} --config Debug)
  14. endfunction()
  15. # Function to check the contents of the output files.
  16. function(check_contents filename contents_regex)
  17. if(EXISTS "${CMAKE_INSTALL_PREFIX}/${filename}")
  18. file(READ "${CMAKE_INSTALL_PREFIX}/${filename}" contents)
  19. if(NOT contents MATCHES "${contents_regex}")
  20. string(APPEND RunCMake_TEST_FAILED "File contents:
  21. ${contents}
  22. do not match what we expected:
  23. ${contents_regex}
  24. in file:
  25. ${CMAKE_INSTALL_PREFIX}/${filename}\n")
  26. set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
  27. endif()
  28. else()
  29. string(APPEND RunCMake_TEST_FAILED "File ${CMAKE_INSTALL_PREFIX}/${filename} does not exist")
  30. set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}" PARENT_SCOPE)
  31. endif()
  32. endfunction()
  33. if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
  34. if(NOT CMake_INSTALL_NAME_TOOL_BUG)
  35. run_install_test(macos)
  36. run_install_test(macos-rpath)
  37. run_install_test(macos-unresolved)
  38. run_install_test(macos-conflict)
  39. run_install_test(macos-notfile)
  40. run_install_test(file-filter)
  41. endif()
  42. run_cmake(project)
  43. run_cmake(badargs1)
  44. run_cmake(badargs2)
  45. elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
  46. run_install_test(windows)
  47. run_install_test(windows-unresolved)
  48. run_install_test(windows-conflict)
  49. run_install_test(windows-notfile)
  50. run_install_test(file-filter)
  51. run_cmake(project)
  52. run_cmake(badargs1)
  53. run_cmake(badargs2)
  54. elseif(CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
  55. if(DEFINED ENV{LDFLAGS})
  56. # Some setups prebake disable-new-dtags into LDFLAGS
  57. string(REPLACE "-Wl,--disable-new-dtags" "" new_ldflags "$ENV{LDFLAGS}")
  58. set(ENV{LDFLAGS} "${new_ldflags}")
  59. endif()
  60. if(NOT CMAKE_C_COMPILER_ID MATCHES "^XL")
  61. run_install_test(linux)
  62. run_install_test(file-filter)
  63. endif()
  64. run_install_test(linux-unresolved)
  65. run_install_test(linux-conflict)
  66. run_install_test(linux-notfile)
  67. run_cmake(project)
  68. run_cmake(badargs1)
  69. run_cmake(badargs2)
  70. else()
  71. run_cmake(unsupported)
  72. endif()
  73. run_install_test(variable-propagation)