RunCMakeTest.cmake 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. include(RunCMake)
  2. function(run_CleanByproducts case)
  3. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CleanByproducts-${case}-build)
  4. set(RunCMake_TEST_OPTIONS "${ARGN}")
  5. run_cmake(CleanByproducts)
  6. set(RunCMake_TEST_NO_CLEAN 1)
  7. run_cmake_command(CleanByProducts-build ${CMAKE_COMMAND} --build .)
  8. include("${RunCMake_TEST_BINARY_DIR}/files.cmake")
  9. message("Checking that all expected files are present")
  10. check_files(EXPECTED_PRESENT "${RunCMake_TEST_BINARY_DIR}" TRUE)
  11. check_files(EXPECTED_DELETED "${RunCMake_TEST_BINARY_DIR}" TRUE)
  12. run_cmake_command(CleanByProducts-clean ${CMAKE_COMMAND} --build . --target clean)
  13. message("Checking that only the expected files are present after cleaning")
  14. check_files(EXPECTED_PRESENT "${RunCMake_TEST_BINARY_DIR}" TRUE)
  15. check_files(EXPECTED_DELETED "${RunCMake_TEST_BINARY_DIR}" FALSE)
  16. endfunction()
  17. function(check_files list path has_to_exist)
  18. foreach(file IN LISTS ${list})
  19. message("Checking ${file}")
  20. set(file_exists FALSE)
  21. if(EXISTS "${path}/${file}")
  22. set(file_exists TRUE)
  23. endif()
  24. if(file_exists AND NOT has_to_exist)
  25. message(FATAL_ERROR "${file} should have been deleted")
  26. elseif(NOT file_exists AND has_to_exist)
  27. message(FATAL_ERROR "${file} does not exist")
  28. elseif(file_exists AND has_to_exist)
  29. message("${file} found as expected")
  30. elseif(NOT file_exists AND NOT has_to_exist)
  31. message("${file} deleted as expected")
  32. endif()
  33. endforeach()
  34. endfunction()
  35. # Iterate through all possible test values
  36. set(counter 0)
  37. foreach(test_clean_no_custom TRUE FALSE)
  38. foreach(test_build_events TRUE FALSE)
  39. foreach(test_custom_command TRUE FALSE)
  40. foreach(test_custom_target TRUE FALSE)
  41. math(EXPR counter "${counter} + 1")
  42. message("Test ${counter} - CLEAN_NO_CUSTOM: ${test_clean_no_custom}, Build events: ${test_build_events}, Custom command: ${test_custom_command}, Custom target: ${test_custom_target}")
  43. run_CleanByproducts("buildevents${counter}" -DCLEAN_NO_CUSTOM=${test_clean_no_custom} -DTEST_BUILD_EVENTS=${test_build_events} -DTEST_CUSTOM_COMMAND=${test_custom_command} -DTEST_CUSTOM_TARGET=${test_custom_target})
  44. endforeach()
  45. endforeach()
  46. endforeach()
  47. endforeach()