GMP.cmake 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. set(_srcdir ${CMAKE_CURRENT_LIST_DIR}/gmp)
  2. set(_dstdir ${DESTDIR}/usr/local)
  3. if (MSVC)
  4. set(_output ${_dstdir}/include/gmp.h
  5. ${_dstdir}/lib/libgmp-10.lib
  6. ${_dstdir}/bin/libgmp-10.dll)
  7. add_custom_command(
  8. OUTPUT ${_output}
  9. COMMAND ${CMAKE_COMMAND} -E copy ${_srcdir}/include/gmp.h ${_dstdir}/include/
  10. COMMAND ${CMAKE_COMMAND} -E copy ${_srcdir}/lib/win${DEPS_BITS}/libgmp-10.lib ${_dstdir}/lib/
  11. COMMAND ${CMAKE_COMMAND} -E copy ${_srcdir}/lib/win${DEPS_BITS}/libgmp-10.dll ${_dstdir}/bin/
  12. )
  13. add_custom_target(dep_GMP SOURCES ${_output})
  14. else ()
  15. set(_gmp_ccflags "-O2 -DNDEBUG -fPIC -DPIC -Wall -Wmissing-prototypes -Wpointer-arith -pedantic -fomit-frame-pointer -fno-common")
  16. set(_gmp_build_tgt "${CMAKE_SYSTEM_PROCESSOR}")
  17. if (APPLE)
  18. if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
  19. set(_gmp_build_arch aarch64)
  20. else ()
  21. set(_gmp_build_arch ${CMAKE_SYSTEM_PROCESSOR})
  22. endif()
  23. if (IS_CROSS_COMPILE)
  24. if (${CMAKE_OSX_ARCHITECTURES} MATCHES "arm")
  25. set(_gmp_host_arch aarch64)
  26. set(_gmp_host_arch_flags "-arch arm64")
  27. elseif (${CMAKE_OSX_ARCHITECTURES} MATCHES "x86_64")
  28. set(_gmp_host_arch x86_64)
  29. set(_gmp_host_arch_flags "-arch x86_64")
  30. endif()
  31. set(_gmp_ccflags "${_gmp_ccflags} ${_gmp_host_arch_flags} -mmacosx-version-min=${DEP_OSX_TARGET}")
  32. set(_gmp_build_tgt --build=${_gmp_build_arch}-apple-darwin --host=${_gmp_host_arch}-apple-darwin)
  33. else ()
  34. set(_gmp_ccflags "${_gmp_ccflags} -mmacosx-version-min=${DEP_OSX_TARGET}")
  35. set(_gmp_build_tgt "--build=${_gmp_build_arch}-apple-darwin")
  36. endif()
  37. elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  38. if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
  39. set(_gmp_ccflags "${_gmp_ccflags} -march=armv7-a") # Works on RPi-4
  40. set(_gmp_build_tgt armv7)
  41. endif()
  42. set(_gmp_build_tgt "--build=${_gmp_build_tgt}-pc-linux-gnu")
  43. else ()
  44. set(_gmp_build_tgt "") # let it guess
  45. endif()
  46. set(_cross_compile_arg "")
  47. if (CMAKE_CROSSCOMPILING)
  48. # TOOLCHAIN_PREFIX should be defined in the toolchain file
  49. set(_cross_compile_arg --host=${TOOLCHAIN_PREFIX})
  50. endif ()
  51. ExternalProject_Add(dep_GMP
  52. # URL https://gmplib.org/download/gmp/gmp-6.2.1.tar.bz2
  53. URL https://github.com/supermerill/SuperSlicer_deps/releases/download/gmp-6.2.1/gmp-6.2.1.tar.bz2
  54. URL_HASH SHA256=eae9326beb4158c386e39a356818031bd28f3124cf915f8c5b1dc4c7a36b4d7c
  55. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/GMP
  56. BUILD_IN_SOURCE ON
  57. CONFIGURE_COMMAND env "CFLAGS=${_gmp_ccflags}" "CXXFLAGS=${_gmp_ccflags}" ./configure ${_cross_compile_arg} --enable-shared=no --enable-cxx=yes --enable-static=yes "--prefix=${DESTDIR}/usr/local" ${_gmp_build_tgt}
  58. BUILD_COMMAND make -j
  59. INSTALL_COMMAND make install
  60. )
  61. endif ()