1
0

CompileDepends.cmake 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. enable_language(C)
  2. add_executable(main CompileDepends.c)
  3. target_include_directories(main PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
  4. file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/check-$<LOWER_CASE:$<CONFIG>>.cmake CONTENT "
  5. cmake_minimum_required(VERSION ${CMAKE_VERSION})
  6. set(check_pairs
  7. \"$<TARGET_FILE:main>|${CMAKE_CURRENT_BINARY_DIR}/CompileDepends.h\"
  8. )
  9. set(check_exes
  10. \"$<TARGET_FILE:main>\"
  11. )
  12. if (RunCMake_GENERATOR MATCHES \"Make\" AND check_step EQUAL 2)
  13. include(\"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/Makefile.cmake\")
  14. if (NOT CMAKE_DEPEND_INFO_FILES)
  15. set(RunCMake_TEST_FAILED \"Variable CMAKE_DEPEND_INFO_FILES not found.\")
  16. else()
  17. foreach(DEPEND_INFO_FILE IN LISTS CMAKE_DEPEND_INFO_FILES)
  18. include(\"${CMAKE_CURRENT_BINARY_DIR}/\${DEPEND_INFO_FILE}\")
  19. if (NOT CMAKE_DEPENDS_DEPENDENCY_FILES)
  20. set(RunCMake_TEST_FAILED \"Variable CMAKE_DEPENDS_DEPENDENCY_FILES not found.\")
  21. else()
  22. list(GET CMAKE_DEPENDS_DEPENDENCY_FILES 1 OBJECT_FILE)
  23. list(GET CMAKE_DEPENDS_DEPENDENCY_FILES 3 DEP_FILE)
  24. if (NOT EXISTS \"${CMAKE_CURRENT_BINARY_DIR}/\${DEP_FILE}\")
  25. set(RunCMake_TEST_FAILED \"File \${DEP_FILE} not found.\")
  26. else()
  27. set (TARGET_DEP_FILE \"${CMAKE_CURRENT_BINARY_DIR}/\${DEP_FILE}\")
  28. cmake_path(REPLACE_FILENAME TARGET_DEP_FILE \"compiler_depend.make\")
  29. file(READ \"\${TARGET_DEP_FILE}\" DEPENDS_CONTENT)
  30. if (WIN32)
  31. string (REPLACE \"\\\\\" \"/\" DEPENDS_CONTENT \"\${DEPENDS_CONTENT}\")
  32. string (TOLOWER \"\${DEPENDS_CONTENT}\" DEPENDS_CONTENT)
  33. string (TOLOWER \"\${OBJECT_FILE}\" OBJECT_FILE)
  34. else()
  35. string(REPLACE \"\\\\ \" \" \" DEPENDS_CONTENT \"\${DEPENDS_CONTENT}\")
  36. endif()
  37. if(NOT DEPENDS_CONTENT MATCHES \"\${OBJECT_FILE} *:.+[Cc]ompile[Dd]epends.c\"
  38. OR NOT DEPENDS_CONTENT MATCHES \"[Cc]ompile[Dd]epends.h\")
  39. set(RunCMake_TEST_FAILED \"Dependency file badly generated:\n \${TARGET_DEP_FILE}\")
  40. endif()
  41. endif()
  42. endif()
  43. endforeach()
  44. endif()
  45. endif()
  46. if (RunCMake_GENERATOR STREQUAL \"Ninja\" AND check_step EQUAL 2)
  47. execute_process(
  48. COMMAND \${RunCMake_MAKE_PROGRAM} -t deps
  49. WORKING_DIRECTORY \${RunCMake_TEST_BINARY_DIR}
  50. OUTPUT_VARIABLE deps
  51. )
  52. if(NOT deps MATCHES \"CompileDepends.c\" OR NOT deps MATCHES \"CompileDepends.h\")
  53. string(REPLACE deps \"\\n\" \"\\n \" \" \${deps}\")
  54. set(RunCMake_TEST_FAILED \"Dependencies not detected correctly:\\n\${deps}\")
  55. endif()
  56. endif()
  57. ")