CMakeLists.txt 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. cmake_minimum_required(VERSION 3.17)
  2. project(RerunUicOnFileChange)
  3. include("../AutogenGuiTest.cmake")
  4. # Utility variables
  5. set(testProjectTemplateDir "${CMAKE_CURRENT_SOURCE_DIR}/UicOnFileChange")
  6. set(testProjectSrc "${CMAKE_CURRENT_BINARY_DIR}/UicOnFileChange")
  7. set(testProjectBinDir "${CMAKE_CURRENT_BINARY_DIR}/UicOnFileChange-build")
  8. set(TEST_CONFIG "Release")
  9. macro(sleep)
  10. message(STATUS "Sleeping for a few seconds.")
  11. execute_process(COMMAND "${CMAKE_COMMAND}" -E sleep 1)
  12. endmacro()
  13. macro(rebuild buildName)
  14. message(STATUS "Starting build ${buildName}.")
  15. execute_process(COMMAND "${CMAKE_COMMAND}" --build . --config "${TEST_CONFIG}"
  16. WORKING_DIRECTORY "${testProjectBinDir}" RESULT_VARIABLE result
  17. )
  18. if (result)
  19. message(FATAL_ERROR "Build ${buildName} failed.")
  20. else()
  21. message(STATUS "Build ${buildName} finished.")
  22. endif()
  23. endmacro()
  24. configure_file("${testProjectTemplateDir}/mocwidget.h" "${testProjectSrc}/mocwidget.h" COPYONLY)
  25. configure_file("${testProjectTemplateDir}/main.cpp" "${testProjectSrc}/main.cpp" COPYONLY)
  26. configure_file("${testProjectTemplateDir}/subdir/subdircheck.cpp" "${testProjectSrc}/subdir/subdircheck.cpp" COPYONLY)
  27. configure_file("${testProjectTemplateDir}/CMakeLists.txt.in" "${testProjectSrc}/CMakeLists.txt" @ONLY)
  28. set(Num 1)
  29. configure_file("${testProjectTemplateDir}/mainwindow.ui.in" "${testProjectSrc}/mainwindow.ui" @ONLY)
  30. configure_file("${testProjectTemplateDir}/subdir/mainwindowsubdir.ui.in" "${testProjectSrc}/subdir/mainwindowsubdir.ui" @ONLY)
  31. if(CMAKE_GENERATOR_INSTANCE)
  32. set(_D_CMAKE_GENERATOR_INSTANCE "-DCMAKE_GENERATOR_INSTANCE=${CMAKE_GENERATOR_INSTANCE}")
  33. else()
  34. set(_D_CMAKE_GENERATOR_INSTANCE "")
  35. endif()
  36. get_property(is_multi GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
  37. if(is_multi)
  38. set(build_type_extra "-DCMAKE_CONFIGURATION_TYPES=${TEST_CONFIG}")
  39. set(extra_bin_path "${TEST_CONFIG}/")
  40. else()
  41. set(build_type_extra "-DCMAKE_BUILD_TYPE=${TEST_CONFIG}")
  42. endif()
  43. # Set the environment PATH/LD_LIBRARY_PATH variables to run the resulting executable
  44. if(WIN32 AND TARGET ${QT_QTCORE_TARGET})
  45. get_target_property(qtcore_path ${QT_QTCORE_TARGET} LOCATION)
  46. if(NOT qtcore_path)
  47. get_target_property(qtcore_path ${QT_QTCORE_TARGET} IMPORTED_LOCATION)
  48. endif()
  49. get_filename_component(qtcore_path "${qtcore_path}" DIRECTORY)
  50. set(ENV{PATH} "${qtcore_path};$ENV{PATH}")
  51. endif()
  52. execute_process(
  53. COMMAND "${CMAKE_COMMAND}" -B "${testProjectBinDir}" -S "${testProjectSrc}"
  54. -G "${CMAKE_GENERATOR}"
  55. -A "${CMAKE_GENERATOR_PLATFORM}"
  56. -T "${CMAKE_GENERATOR_TOOLSET}"
  57. ${_D_CMAKE_GENERATOR_INSTANCE}
  58. "${build_type_extra}"
  59. "-DQT_TEST_VERSION=${QT_TEST_VERSION}"
  60. "-DCMAKE_AUTOGEN_VERBOSE=${CMAKE_AUTOGEN_VERBOSE}"
  61. "-DQT_QMAKE_EXECUTABLE:FILEPATH=${QT_QMAKE_EXECUTABLE}"
  62. RESULT_VARIABLE exit_code
  63. OUTPUT_VARIABLE output
  64. ERROR_VARIABLE output
  65. )
  66. if(NOT exit_code EQUAL 0)
  67. message(FATAL_ERROR "Initial configuration of UicOnFileChange failed. Output: ${output}")
  68. endif()
  69. # Initial build
  70. execute_process(
  71. COMMAND "${CMAKE_COMMAND}" --build "${testProjectBinDir}" --config "${TEST_CONFIG}"
  72. RESULT_VARIABLE exit_code
  73. OUTPUT_VARIABLE output
  74. ERROR_VARIABLE output
  75. )
  76. if(NOT exit_code EQUAL 0)
  77. message(FATAL_ERROR "Initial build of UicOnFileChange failed. Output: ${output}")
  78. endif()
  79. execute_process(COMMAND "${testProjectBinDir}/${extra_bin_path}UicOnFileChange" RESULT_VARIABLE result)
  80. if(NOT result EQUAL "1")
  81. message(FATAL_ERROR "Initial build of UicOnFileChange test result is: ${result}")
  82. endif()
  83. sleep()
  84. set(Num 2)
  85. configure_file("${testProjectTemplateDir}/mainwindow.ui.in" "${testProjectSrc}/mainwindow.ui" @ONLY)
  86. configure_file("${testProjectTemplateDir}/subdir/mainwindowsubdir.ui.in" "${testProjectSrc}/subdir/mainwindowsubdir.ui" @ONLY)
  87. rebuild(2)
  88. execute_process(COMMAND "${testProjectBinDir}/${extra_bin_path}UicOnFileChange" RESULT_VARIABLE result)
  89. if(NOT result EQUAL "0")
  90. message(FATAL_ERROR "Rebuild of UicOnFileChange test result is: ${result}")
  91. endif()