GMP.cmake 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_tgt aarch64)
  20. endif()
  21. set(_gmp_ccflags "${_gmp_ccflags} -mmacosx-version-min=${DEP_OSX_TARGET}")
  22. set(_gmp_build_tgt "--build=${_gmp_build_tgt}-apple-darwin")
  23. elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
  24. if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm")
  25. set(_gmp_ccflags "${_gmp_ccflags} -march=armv7-a") # Works on RPi-4
  26. set(_gmp_build_tgt armv7)
  27. endif()
  28. set(_gmp_build_tgt "--build=${_gmp_build_tgt}-pc-linux-gnu")
  29. else ()
  30. set(_gmp_build_tgt "") # let it guess
  31. endif()
  32. set(_cross_compile_arg "")
  33. if (CMAKE_CROSSCOMPILING)
  34. # TOOLCHAIN_PREFIX should be defined in the toolchain file
  35. set(_cross_compile_arg --host=${TOOLCHAIN_PREFIX})
  36. endif ()
  37. ExternalProject_Add(dep_GMP
  38. URL https://gmplib.org/download/gmp/gmp-6.2.1.tar.bz2
  39. URL_HASH SHA256=eae9326beb4158c386e39a356818031bd28f3124cf915f8c5b1dc4c7a36b4d7c
  40. DOWNLOAD_DIR ${DEP_DOWNLOAD_DIR}/GMP
  41. BUILD_IN_SOURCE ON
  42. 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}
  43. BUILD_COMMAND make -j
  44. INSTALL_COMMAND make install
  45. )
  46. endif ()