GLOBAL.cmake 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. include(FetchContent)
  2. set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/PackageFindModules)
  3. set(FETCHCONTENT_TRY_FIND_PACKAGE_MODE ALWAYS)
  4. set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL TRUE)
  5. FetchContent_Declare(
  6. GlobalWithArgsKeyword
  7. SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
  8. FIND_PACKAGE_ARGS
  9. )
  10. FetchContent_Declare(
  11. GlobalWithoutArgsKeyword
  12. SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
  13. )
  14. set(CMAKE_FIND_PACKAGE_TARGETS_GLOBAL FALSE)
  15. FetchContent_Declare(
  16. LocalWithArgsKeyword
  17. SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
  18. FIND_PACKAGE_ARGS
  19. )
  20. FetchContent_Declare(
  21. LocalWithoutArgsKeyword
  22. SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
  23. )
  24. FetchContent_Declare(
  25. EventuallyGlobal
  26. SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/FatalIfAdded
  27. )
  28. add_subdirectory(ChildScope)
  29. if(NOT TARGET GlobalWithArgsKeywordExe)
  30. message(SEND_ERROR "GlobalWithArgsKeywordExe is not a global target")
  31. endif()
  32. if(NOT TARGET GlobalWithoutArgsKeywordExe)
  33. message(SEND_ERROR "GlobalWithoutArgsKeywordExe is not a global target")
  34. endif()
  35. if(TARGET LocalWithArgsKeywordExe)
  36. message(SEND_ERROR "LocalWithArgsKeywordExe is unexpectedly a global target")
  37. endif()
  38. if(TARGET LocalWithoutArgsKeywordExe)
  39. message(SEND_ERROR "LocalWithoutArgsKeywordExe is unexpectedly a global target")
  40. endif()
  41. if(NOT TARGET EventuallyGlobalExe)
  42. message(SEND_ERROR "EventuallyGlobalExe is not a global target")
  43. endif()