BuildMsgpack.cmake 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. include(CMakeParseArguments)
  2. # BuildMsgpack(CONFIGURE_COMMAND ... BUILD_COMMAND ... INSTALL_COMMAND ...)
  3. # Reusable function to build msgpack, wraps ExternalProject_Add.
  4. # Failing to pass a command argument will result in no command being run
  5. function(BuildMsgpack)
  6. cmake_parse_arguments(_msgpack
  7. ""
  8. ""
  9. "CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND"
  10. ${ARGN})
  11. if(NOT _msgpack_CONFIGURE_COMMAND AND NOT _msgpack_BUILD_COMMAND
  12. AND NOT _msgpack_INSTALL_COMMAND)
  13. message(FATAL_ERROR "Must pass at least one of CONFIGURE_COMMAND, BUILD_COMMAND, INSTALL_COMMAND")
  14. endif()
  15. ExternalProject_Add(msgpack
  16. PREFIX ${DEPS_BUILD_DIR}
  17. URL ${MSGPACK_URL}
  18. DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/msgpack
  19. DOWNLOAD_COMMAND ${CMAKE_COMMAND}
  20. -DPREFIX=${DEPS_BUILD_DIR}
  21. -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/msgpack
  22. -DURL=${MSGPACK_URL}
  23. -DEXPECTED_SHA256=${MSGPACK_SHA256}
  24. -DTARGET=msgpack
  25. -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
  26. -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
  27. CONFIGURE_COMMAND "${_msgpack_CONFIGURE_COMMAND}"
  28. BUILD_COMMAND "${_msgpack_BUILD_COMMAND}"
  29. INSTALL_COMMAND "${_msgpack_INSTALL_COMMAND}")
  30. endfunction()
  31. set(MSGPACK_CONFIGURE_COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/msgpack
  32. -DMSGPACK_ENABLE_CXX=OFF
  33. -DMSGPACK_BUILD_TESTS=OFF
  34. -DMSGPACK_BUILD_EXAMPLES=OFF
  35. -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
  36. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  37. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  38. "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1} -fPIC"
  39. -DCMAKE_GENERATOR=${CMAKE_GENERATOR})
  40. set(MSGPACK_BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE})
  41. set(MSGPACK_INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE})
  42. if(MINGW AND CMAKE_CROSSCOMPILING)
  43. get_filename_component(TOOLCHAIN ${CMAKE_TOOLCHAIN_FILE} REALPATH)
  44. set(MSGPACK_CONFIGURE_COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/msgpack
  45. -DMSGPACK_ENABLE_CXX=OFF
  46. -DMSGPACK_BUILD_TESTS=OFF
  47. -DMSGPACK_BUILD_EXAMPLES=OFF
  48. -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
  49. # Pass toolchain
  50. -DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN}
  51. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  52. # Hack to avoid -rdynamic in Mingw
  53. -DCMAKE_SHARED_LIBRARY_LINK_C_FLAGS="")
  54. elseif(MSVC)
  55. # Same as Unix without fPIC
  56. set(MSGPACK_CONFIGURE_COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/msgpack
  57. -DMSGPACK_ENABLE_CXX=OFF
  58. -DMSGPACK_BUILD_TESTS=OFF
  59. -DMSGPACK_BUILD_EXAMPLES=OFF
  60. -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
  61. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  62. "-DCMAKE_C_FLAGS:STRING=${CMAKE_C_COMPILER_ARG1}"
  63. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  64. # Make sure we use the same generator, otherwise we may
  65. # accidentaly end up using different MSVC runtimes
  66. -DCMAKE_GENERATOR=${CMAKE_GENERATOR})
  67. endif()
  68. BuildMsgpack(CONFIGURE_COMMAND ${MSGPACK_CONFIGURE_COMMAND}
  69. BUILD_COMMAND ${MSGPACK_BUILD_COMMAND}
  70. INSTALL_COMMAND ${MSGPACK_INSTALL_COMMAND})
  71. list(APPEND THIRD_PARTY_DEPS msgpack)