Deps.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. set(DEPS_INSTALL_DIR "${CMAKE_BINARY_DIR}/usr")
  2. set(DEPS_BIN_DIR "${DEPS_INSTALL_DIR}/bin")
  3. set(DEPS_LIB_DIR "${DEPS_INSTALL_DIR}/lib")
  4. set(DEPS_SHARE_DIR "${DEPS_INSTALL_DIR}/share/lua/5.1")
  5. set(DEPS_BUILD_DIR "${CMAKE_BINARY_DIR}/build")
  6. set(DEPS_DOWNLOAD_DIR "${DEPS_BUILD_DIR}/downloads")
  7. set(DEPS_CMAKE_ARGS
  8. -D CMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  9. -D CMAKE_C_STANDARD=99
  10. -D CMAKE_GENERATOR=${CMAKE_GENERATOR}
  11. -D CMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM}
  12. -D BUILD_SHARED_LIBS=OFF
  13. -D CMAKE_POSITION_INDEPENDENT_CODE=ON
  14. -D CMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR})
  15. if(APPLE)
  16. list(APPEND DEPS_CMAKE_ARGS -D CMAKE_FIND_FRAMEWORK=${CMAKE_FIND_FRAMEWORK})
  17. endif()
  18. # Can be removed once minimum version is at least 3.15
  19. if(POLICY CMP0092)
  20. list(APPEND DEPS_CMAKE_ARGS -D CMAKE_POLICY_DEFAULT_CMP0092=NEW)
  21. endif()
  22. find_program(CACHE_PRG NAMES ccache sccache)
  23. if(CACHE_PRG)
  24. set(CMAKE_C_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E env CCACHE_SLOPPINESS=pch_defines,time_macros ${CACHE_PRG})
  25. list(APPEND DEPS_CMAKE_CACHE_ARGS -DCMAKE_C_COMPILER_LAUNCHER:STRING=${CMAKE_C_COMPILER_LAUNCHER})
  26. endif()
  27. # MAKE_PRG
  28. if(UNIX)
  29. find_program(MAKE_PRG NAMES gmake make)
  30. if(NOT MAKE_PRG)
  31. message(FATAL_ERROR "GNU Make is required to build the dependencies.")
  32. else()
  33. message(STATUS "Found GNU Make at ${MAKE_PRG}")
  34. endif()
  35. endif()
  36. # When using make, use the $(MAKE) variable to avoid warning about the job
  37. # server.
  38. if(CMAKE_GENERATOR MATCHES "Makefiles")
  39. set(MAKE_PRG "$(MAKE)")
  40. endif()
  41. if(MINGW AND CMAKE_GENERATOR MATCHES "Ninja")
  42. find_program(MAKE_PRG NAMES mingw32-make)
  43. if(NOT MAKE_PRG)
  44. message(FATAL_ERROR "GNU Make for mingw32 is required to build the dependencies.")
  45. else()
  46. message(STATUS "Found GNU Make for mingw32: ${MAKE_PRG}")
  47. endif()
  48. endif()
  49. # DEPS_C_COMPILER
  50. set(DEPS_C_COMPILER "${CMAKE_C_COMPILER}")
  51. if(CMAKE_OSX_SYSROOT)
  52. set(DEPS_C_COMPILER "${DEPS_C_COMPILER} -isysroot${CMAKE_OSX_SYSROOT}")
  53. endif()
  54. get_filename_component(rootdir ${PROJECT_SOURCE_DIR} NAME)
  55. if(${rootdir} MATCHES "cmake.deps")
  56. set(depsfile ${PROJECT_SOURCE_DIR}/deps.txt)
  57. else()
  58. set(depsfile ${PROJECT_SOURCE_DIR}/cmake.deps/deps.txt)
  59. endif()
  60. set_directory_properties(PROPERTIES
  61. EP_PREFIX "${DEPS_BUILD_DIR}"
  62. CMAKE_CONFIGURE_DEPENDS ${depsfile})
  63. file(READ ${depsfile} DEPENDENCIES)
  64. STRING(REGEX REPLACE "\n" ";" DEPENDENCIES "${DEPENDENCIES}")
  65. foreach(dep ${DEPENDENCIES})
  66. STRING(REGEX REPLACE " " ";" dep "${dep}")
  67. list(GET dep 0 name)
  68. list(GET dep 1 value)
  69. if(NOT ${name})
  70. # _URL variables must NOT be set when USE_EXISTING_SRC_DIR is set,
  71. # otherwise ExternalProject will try to re-download the sources.
  72. if(NOT USE_EXISTING_SRC_DIR)
  73. set(${name} ${value})
  74. endif()
  75. endif()
  76. endforeach()
  77. function(get_externalproject_options name DEPS_IGNORE_SHA)
  78. string(TOUPPER ${name} name_allcaps)
  79. set(url ${${name_allcaps}_URL})
  80. set(EXTERNALPROJECT_OPTIONS
  81. DOWNLOAD_NO_PROGRESS TRUE
  82. EXTERNALPROJECT_OPTIONS URL ${${name_allcaps}_URL}
  83. CMAKE_CACHE_ARGS ${DEPS_CMAKE_CACHE_ARGS})
  84. if(NOT ${DEPS_IGNORE_SHA})
  85. list(APPEND EXTERNALPROJECT_OPTIONS URL_HASH SHA256=${${name_allcaps}_SHA256})
  86. endif()
  87. set(EXTERNALPROJECT_OPTIONS ${EXTERNALPROJECT_OPTIONS} PARENT_SCOPE)
  88. endfunction()