CompileDepends.cmake 3.0 KB

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