Deps.cmake 3.0 KB

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