Deps.cmake 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. find_program(CACHE_PRG NAMES ccache sccache)
  19. mark_as_advanced(CACHE_PRG)
  20. if(CACHE_PRG)
  21. set(CMAKE_C_COMPILER_LAUNCHER ${CMAKE_COMMAND} -E env CCACHE_SLOPPINESS=pch_defines,time_macros ${CACHE_PRG})
  22. list(APPEND DEPS_CMAKE_CACHE_ARGS -DCMAKE_C_COMPILER_LAUNCHER:STRING=${CMAKE_C_COMPILER_LAUNCHER})
  23. endif()
  24. # MAKE_PRG
  25. if(UNIX)
  26. find_program(MAKE_PRG NAMES gmake make)
  27. mark_as_advanced(MAKE_PRG)
  28. if(NOT MAKE_PRG)
  29. message(FATAL_ERROR "GNU Make is required to build the dependencies.")
  30. else()
  31. message(STATUS "Found GNU Make at ${MAKE_PRG}")
  32. endif()
  33. endif()
  34. # When using make, use the $(MAKE) variable to avoid warning about the job
  35. # server.
  36. if(CMAKE_GENERATOR MATCHES "Makefiles")
  37. set(MAKE_PRG "$(MAKE)")
  38. endif()
  39. if(MINGW AND CMAKE_GENERATOR MATCHES "Ninja")
  40. find_program(MAKE_PRG NAMES mingw32-make)
  41. if(NOT MAKE_PRG)
  42. message(FATAL_ERROR "GNU Make for mingw32 is required to build the dependencies.")
  43. else()
  44. message(STATUS "Found GNU Make for mingw32: ${MAKE_PRG}")
  45. endif()
  46. endif()
  47. # DEPS_C_COMPILER
  48. set(DEPS_C_COMPILER "${CMAKE_C_COMPILER}")
  49. if(CMAKE_OSX_SYSROOT)
  50. set(DEPS_C_COMPILER "${DEPS_C_COMPILER} -isysroot${CMAKE_OSX_SYSROOT}")
  51. endif()
  52. get_filename_component(rootdir ${PROJECT_SOURCE_DIR} NAME)
  53. if(${rootdir} MATCHES "cmake.deps")
  54. set(depsfile ${PROJECT_SOURCE_DIR}/deps.txt)
  55. else()
  56. set(depsfile ${PROJECT_SOURCE_DIR}/cmake.deps/deps.txt)
  57. endif()
  58. set_directory_properties(PROPERTIES
  59. EP_PREFIX "${DEPS_BUILD_DIR}"
  60. CMAKE_CONFIGURE_DEPENDS ${depsfile})
  61. file(READ ${depsfile} DEPENDENCIES)
  62. STRING(REGEX REPLACE "\n" ";" DEPENDENCIES "${DEPENDENCIES}")
  63. foreach(dep ${DEPENDENCIES})
  64. STRING(REGEX REPLACE " " ";" dep "${dep}")
  65. list(GET dep 0 name)
  66. list(GET dep 1 value)
  67. if(NOT ${name})
  68. # _URL variables must NOT be set when USE_EXISTING_SRC_DIR is set,
  69. # otherwise ExternalProject will try to re-download the sources.
  70. if(NOT USE_EXISTING_SRC_DIR)
  71. set(${name} ${value})
  72. endif()
  73. endif()
  74. endforeach()
  75. function(get_externalproject_options name DEPS_IGNORE_SHA)
  76. string(TOUPPER ${name} name_allcaps)
  77. set(url ${${name_allcaps}_URL})
  78. set(EXTERNALPROJECT_OPTIONS
  79. DOWNLOAD_NO_PROGRESS TRUE
  80. EXTERNALPROJECT_OPTIONS URL ${${name_allcaps}_URL}
  81. CMAKE_CACHE_ARGS ${DEPS_CMAKE_CACHE_ARGS})
  82. if(NOT ${DEPS_IGNORE_SHA})
  83. list(APPEND EXTERNALPROJECT_OPTIONS URL_HASH SHA256=${${name_allcaps}_SHA256})
  84. endif()
  85. set(EXTERNALPROJECT_OPTIONS ${EXTERNALPROJECT_OPTIONS} PARENT_SCOPE)
  86. endfunction()