BuildGperf.cmake 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # Gperf recipe. Gperf is only required when building Neovim, when
  2. # cross compiling we still want to build for the HOST system, whenever
  3. # writing a recipe that is meant for cross-compile, use the HOSTDEPS_* variables
  4. # instead of DEPS_* - check the main CMakeLists.txt for a list.
  5. # BuildGperf(CONFIGURE_COMMAND ... BUILD_COMMAND ... INSTALL_COMMAND ...)
  6. # Reusable function to build Gperf, wraps ExternalProject_Add.
  7. # Failing to pass a command argument will result in no command being run
  8. function(BuildGperf)
  9. cmake_parse_arguments(_gperf
  10. ""
  11. ""
  12. "CONFIGURE_COMMAND;BUILD_COMMAND;INSTALL_COMMAND"
  13. ${ARGN})
  14. if(NOT _gperf_CONFIGURE_COMMAND AND NOT _gperf_BUILD_COMMAND
  15. AND NOT _gperf_INSTALL_COMMAND)
  16. message(FATAL_ERROR "Must pass at least one of CONFIGURE_COMMAND, BUILD_COMMAND, INSTALL_COMMAND")
  17. endif()
  18. ExternalProject_Add(gperf
  19. PREFIX ${DEPS_BUILD_DIR}
  20. URL ${GPERF_URL}
  21. DOWNLOAD_DIR ${DEPS_DOWNLOAD_DIR}/gperf
  22. DOWNLOAD_COMMAND ${CMAKE_COMMAND}
  23. -DPREFIX=${DEPS_BUILD_DIR}
  24. -DDOWNLOAD_DIR=${DEPS_DOWNLOAD_DIR}/gperf
  25. -DURL=${GPERF_URL}
  26. -DEXPECTED_SHA256=${GPERF_SHA256}
  27. -DTARGET=gperf
  28. -DUSE_EXISTING_SRC_DIR=${USE_EXISTING_SRC_DIR}
  29. -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/DownloadAndExtractFile.cmake
  30. BUILD_IN_SOURCE 1
  31. CONFIGURE_COMMAND "${_gperf_CONFIGURE_COMMAND}"
  32. BUILD_COMMAND "${_gperf_BUILD_COMMAND}"
  33. INSTALL_COMMAND "${_gperf_INSTALL_COMMAND}")
  34. endfunction()
  35. set(GPERF_BUILDARGS CC=${HOSTDEPS_C_COMPILER} CXX=${HOSTDEPS_CXX_COMPILER}
  36. LD=${HOSTDEPS_C_COMPILER})
  37. if(UNIX OR (MINGW AND CMAKE_CROSSCOMPILING))
  38. BuildGperf(
  39. CONFIGURE_COMMAND ${DEPS_BUILD_DIR}/src/gperf/configure
  40. --prefix=${HOSTDEPS_INSTALL_DIR}
  41. MAKE=${MAKE_PRG} ${GPERF_BUILDARGS}
  42. INSTALL_COMMAND ${MAKE_PRG} install)
  43. elseif(MSVC OR MINGW)
  44. BuildGperf(
  45. CONFIGURE_COMMAND ${CMAKE_COMMAND} -E copy
  46. ${CMAKE_CURRENT_SOURCE_DIR}/cmake/GperfCMakeLists.txt
  47. ${DEPS_BUILD_DIR}/src/gperf/CMakeLists.txt
  48. COMMAND ${CMAKE_COMMAND} ${DEPS_BUILD_DIR}/src/gperf/CMakeLists.txt
  49. -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
  50. -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
  51. -DCMAKE_GENERATOR=${CMAKE_GENERATOR}
  52. -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
  53. -DCMAKE_INSTALL_PREFIX=${DEPS_INSTALL_DIR}
  54. BUILD_COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE}
  55. INSTALL_COMMAND ${CMAKE_COMMAND} --build . --target install --config ${CMAKE_BUILD_TYPE})
  56. else()
  57. message(FATAL_ERROR "Trying to build gperf in an unsupported system ${CMAKE_SYSTEM_NAME}/${CMAKE_C_COMPILER_ID}")
  58. endif()