GMP.cmake 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. set(_srcdir ${CMAKE_CURRENT_LIST_DIR}/gmp)
  2. set(_dstdir ${${PROJECT_NAME}_DEP_INSTALL_PREFIX})
  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. string(TOUPPER "${CMAKE_BUILD_TYPE}" _buildtype_upper)
  16. set(_gmp_ccflags "${CMAKE_CXX_FLAGS_${_buildtype_upper}} -fPIC -DPIC -Wall -Wmissing-prototypes -Wpointer-arith -pedantic -fomit-frame-pointer -fno-common")
  17. set(_gmp_build_tgt "${CMAKE_SYSTEM_PROCESSOR}")
  18. set(_cross_compile_arg "")
  19. if (APPLE)
  20. if (CMAKE_OSX_ARCHITECTURES)
  21. set(_gmp_build_tgt ${CMAKE_OSX_ARCHITECTURES})
  22. set(_gmp_ccflags "${_gmp_ccflags} -arch ${CMAKE_OSX_ARCHITECTURES}")
  23. endif ()
  24. if (${_gmp_build_tgt} MATCHES "arm")
  25. set(_gmp_build_tgt aarch64)
  26. endif()
  27. if (CMAKE_OSX_ARCHITECTURES)
  28. set(_cross_compile_arg --host=${_gmp_build_tgt}-apple-darwin21)
  29. endif ()
  30. set(_gmp_ccflags "${_gmp_ccflags} -mmacosx-version-min=${DEP_OSX_TARGET}")
  31. set(_gmp_build_tgt "--build=${_gmp_build_tgt}-apple-darwin")
  32. elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  33. if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
  34. set(_gmp_ccflags "${_gmp_ccflags} -march=armv7-a") # Works on RPi-4
  35. set(_gmp_build_tgt armv7)
  36. endif()
  37. set(_gmp_build_tgt "--build=${_gmp_build_tgt}-pc-linux-gnu")
  38. else ()
  39. set(_gmp_build_tgt "") # let it guess
  40. endif()
  41. if (CMAKE_CROSSCOMPILING)
  42. # TOOLCHAIN_PREFIX should be defined in the toolchain file
  43. set(_cross_compile_arg --host=${TOOLCHAIN_PREFIX})
  44. endif ()
  45. ExternalProject_Add(dep_GMP
  46. EXCLUDE_FROM_ALL ON
  47. # URL https://gmplib.org/download/gmp/gmp-6.2.1.tar.bz2
  48. URL https://github.com/supermerill/SuperSlicer_deps/releases/download/gmp-6.2.1/gmp-6.2.1.tar.bz2
  49. URL_HASH SHA256=eae9326beb4158c386e39a356818031bd28f3124cf915f8c5b1dc4c7a36b4d7c
  50. DOWNLOAD_DIR ${${PROJECT_NAME}_DEP_DOWNLOAD_DIR}/GMP
  51. BUILD_IN_SOURCE ON
  52. CONFIGURE_COMMAND env "CFLAGS=${_gmp_ccflags}" "CXXFLAGS=${_gmp_ccflags}" ./configure ${_cross_compile_arg} --enable-shared=no --enable-cxx=yes --enable-static=yes "--prefix=${${PROJECT_NAME}_DEP_INSTALL_PREFIX}" ${_gmp_build_tgt}
  53. BUILD_COMMAND make -j
  54. INSTALL_COMMAND make install
  55. )
  56. endif ()