Browse Source

bump mpfr version; add logic for mac os cross compiling

Alec Jacobson 2 years ago
parent
commit
379e8960d6
2 changed files with 51 additions and 2 deletions
  1. 28 0
      cmake/recipes/external/gmp.cmake
  2. 23 2
      cmake/recipes/external/mpfr.cmake

+ 28 - 0
cmake/recipes/external/gmp.cmake

@@ -10,6 +10,29 @@ if(WIN32)
 else()
   message(STATUS "Third-party: creating target 'gmp::gmp'")
 
+  # SERIOUSLY !?! CMAKE and configure use transposed definitions of "build" and
+  # "host"?
+  #
+  # https://cmake.org/cmake/help/latest/variable/CMAKE_SYSTEM_NAME.html#variable:CMAKE_SYSTEM_NAME
+  # https://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html
+  #
+  # Seems these aren't to be trusted much
+  # https://gitlab.kitware.com/cmake/cmake/-/issues/20989
+  if(APPLE)
+    # https://gmplib.org/list-archives/gmp-discuss/2020-November/006607.html
+    if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" AND ${CMAKE_OSX_ARCHITECTURES} STREQUAL "arm64")
+      set(gmp_BUILD "x86_64-apple-darwin")
+      set(gmp_HOST "arm64-apple-darwin")
+      set(gmp_CFLAGS "--target=arm64-apple-darwin")
+      set(gmp_LDFLAGS "-arch arm64")
+    elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64" AND ${CMAKE_OSX_ARCHITECTURES} STREQUAL "x86_64")
+      set(gmp_HOST "x86_64-apple-darwin")
+      set(gmp_BUILD "arm64-apple-darwin")
+      set(gmp_CFLAGS "--target=x86_64-apple-darwin13.0.0")
+      set(gmp_LDFLAGS "")
+    endif()
+  endif()
+
   include(FetchContent)
   include(ProcessorCount)
   ProcessorCount(Ncpu)
@@ -41,9 +64,14 @@ else()
       curl "https://gmplib.org/repo/gmp/raw-rev/5f32dbc41afc" "|" git apply -v
     ${gmp_ExternalProject_Add_extra_options}
     CONFIGURE_COMMAND 
+     ${CMAKE_COMMAND} -E env
+      CFLAGS=${gmp_CFLAGS}
+     LDFLAGS=${gmp_LDFLAGS}
       ${prefix}/src/gmp/configure 
       --disable-debug --disable-dependency-tracking --enable-cxx --with-pic
       --prefix=${gmp_INSTALL}
+      --build=${gmp_BUILD}
+      --host=${gmp_HOST}
       --disable-shared
     BUILD_COMMAND make -j${Ncpu}
     INSTALL_COMMAND make -j${Ncpu} install

+ 23 - 2
cmake/recipes/external/mpfr.cmake

@@ -14,6 +14,22 @@ if(WIN32)
 else()
   message(STATUS "Third-party: creating target 'mpfr::mpfr'")
 
+  # Praying this will work the same as gmp
+  if(APPLE)
+    # https://gmplib.org/list-archives/gmp-discuss/2020-November/006607.html
+    if(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64" AND ${CMAKE_OSX_ARCHITECTURES} STREQUAL "arm64")
+      set(mpfr_BUILD "x86_64-apple-darwin")
+      set(mpfr_HOST "arm64-apple-darwin")
+      set(mpfr_CFLAGS "--target=arm64-apple-darwin")
+      set(mpfr_LDFLAGS "-arch arm64")
+    elseif(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "arm64" AND ${CMAKE_OSX_ARCHITECTURES} STREQUAL "x86_64")
+      set(mpfr_HOST "x86_64-apple-darwin")
+      set(mpfr_BUILD "arm64-apple-darwin")
+      set(mpfr_CFLAGS "--target=x86_64-apple-darwin13.0.0")
+      set(mpfr_LDFLAGS "")
+    endif()
+  endif()
+
   include(FetchContent)
   include(ProcessorCount)
   ProcessorCount(Ncpu)
@@ -35,16 +51,21 @@ else()
   ExternalProject_Add(mpfr
     PREFIX ${prefix}
     DEPENDS gmp
-    URL  https://ftp.gnu.org/gnu/mpfr/mpfr-4.1.0.tar.xz
-    URL_MD5 bdd3d5efba9c17da8d83a35ec552baef
+    URL  https://ftp.gnu.org/gnu/mpfr/mpfr-4.2.0.tar.xz
+    URL_MD5 a25091f337f25830c16d2054d74b5af7
     UPDATE_DISCONNECTED true  # need this to avoid constant rebuild
     ${mpfr_ExternalProject_Add_extra_options} # avoid constant reconfigure
     CONFIGURE_COMMAND 
+     ${CMAKE_COMMAND} -E env
+      CFLAGS=${gmp_CFLAGS}
+     LDFLAGS=${gmp_LDFLAGS}
       ${prefix}/src/mpfr/configure 
       --disable-debug --disable-dependency-tracking  --disable-silent-rules --enable-cxx --with-pic
       --with-gmp-include=${gmp_INCLUDE_DIR} --with-gmp-lib=${gmp_LIB_DIR}
       --disable-shared
       --prefix=${mpfr_INSTALL}
+      --build=${gmp_BUILD}
+      --host=${gmp_HOST}
       --disable-shared
     BUILD_COMMAND make -j${Ncpu}
     INSTALL_COMMAND make -j${Ncpu} install