LinkBinariesBuildPhase_Funcs.cmake 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. cmake_minimum_required(VERSION 3.18...3.19)
  2. macro(returnOnError errorMsg)
  3. if(NOT "${errorMsg}" STREQUAL "")
  4. set(RunCMake_TEST_FAILED "${RunCMake_TEST_FAILED}\n${errorMsg}" PARENT_SCOPE)
  5. return()
  6. endif()
  7. endmacro()
  8. function(getTargetFlags mainTarget projFlagsVar flagsVar errorVar)
  9. # The flags variables in the project file might span over multiple lines
  10. # so we can't easily read the flags directly from there. Instead, we use
  11. # the xcodebuild -showBuildSettings option to report it on a single line.
  12. execute_process(
  13. COMMAND ${CMAKE_COMMAND}
  14. --build ${RunCMake_TEST_BINARY_DIR}
  15. --target ${mainTarget}
  16. --config Debug
  17. --
  18. -showBuildSettings
  19. COMMAND grep ${projFlagsVar}
  20. OUTPUT_VARIABLE flagsContents
  21. RESULT_VARIABLE result
  22. )
  23. if(result)
  24. set(${errorVar} "Failed to get flags for ${mainTarget}: ${result}" PARENT_SCOPE)
  25. else()
  26. unset(${errorVar} PARENT_SCOPE)
  27. endif()
  28. set(${flagsVar} "${flagsContents}" PARENT_SCOPE)
  29. endfunction()
  30. function(checkFlags projFlagsVar mainTarget present absent)
  31. getTargetFlags(${mainTarget} ${projFlagsVar} flags errorMsg)
  32. returnOnError("${errorMsg}")
  33. foreach(linkTo IN LISTS present)
  34. string(REGEX MATCH "${linkTo}" result "${flags}")
  35. if("${result}" STREQUAL "")
  36. string(APPEND RunCMake_TEST_FAILED
  37. "\n${mainTarget} ${projFlagsVar} is missing ${linkTo}"
  38. )
  39. endif()
  40. endforeach()
  41. foreach(linkTo IN LISTS absent)
  42. string(REGEX MATCH "${linkTo}" result "${flags}")
  43. if(NOT "${result}" STREQUAL "")
  44. string(APPEND RunCMake_TEST_FAILED
  45. "\n${mainTarget} ${projFlagsVar} unexpectedly contains ${linkTo}"
  46. )
  47. endif()
  48. endforeach()
  49. set(RunCMake_TEST_FAILED ${RunCMake_TEST_FAILED} PARENT_SCOPE)
  50. endfunction()