RunCMakeTest.cmake 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. include(RunCMake)
  2. function(run_TargetWithCommand)
  3. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/TargetWithCommand-build)
  4. run_cmake(TargetWithCommand)
  5. set(RunCMake_TEST_NO_CLEAN 1)
  6. run_cmake_command(TargetWithCommand-build ${CMAKE_COMMAND} --build . --config Debug)
  7. endfunction()
  8. run_TargetWithCommand()
  9. # Use a single build tree for a few tests without cleaning.
  10. set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CommandWithOutput-build)
  11. set(RunCMake_TEST_NO_CLEAN 1)
  12. file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
  13. file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
  14. set(RunCMake-check-file CommandWithOutput-check.cmake)
  15. set(srcName "test.cs")
  16. set(srcFileName "${CMAKE_CURRENT_LIST_DIR}/${srcName}.in")
  17. set(inputFileName "${RunCMake_TEST_BINARY_DIR}/${srcName}.in")
  18. set(generatedFileName "${RunCMake_TEST_BINARY_DIR}/${srcName}")
  19. set(commandComment "Generating ${srcName}")
  20. # copy the input file to build dir to avoid changing files in cmake
  21. # source tree.
  22. file(COPY "${srcFileName}" DESTINATION "${RunCMake_TEST_BINARY_DIR}")
  23. set(RunCMake_TEST_OPTIONS ${RunCMake_TEST_OPTIONS}
  24. "-DinputFileName=${inputFileName}"
  25. "-DgeneratedFileName=${generatedFileName}"
  26. "-DcommandComment=${commandComment}")
  27. set(checkLevel 0)
  28. run_cmake(CommandWithOutput)
  29. set(checkLevel 1)
  30. run_cmake_command(CommandWithOutput-build1 ${CMAKE_COMMAND} --build . --config Debug)
  31. set(checkLevel 2)
  32. run_cmake_command(CommandWithOutput-build2 ${CMAKE_COMMAND} --build . --config Debug)
  33. # change file content to trigger custom command with next build
  34. file(APPEND ${inputFileName} "\n")
  35. set(checkLevel 3)
  36. run_cmake_command(CommandWithOutput-build3 ${CMAKE_COMMAND} --build . --config Debug)