Pass GMP to libpoly (#6411)
authorGereon Kremer <gereon.kremer@cs.rwth-aachen.de>
Wed, 21 Apr 2021 19:33:21 +0000 (21:33 +0200)
committerGitHub <noreply@github.com>
Wed, 21 Apr 2021 19:33:21 +0000 (19:33 +0000)
This PR makes sure that our build of libpoly works on systems without GMP: by passing the paths to GMP we use ourselves to libpoly, we make sure libpoly always has a suitable version of GMP.
Also, we make libpoly somewhat faster to build by disabling tests.

cmake/FindPoly.cmake

index 4521605b90b709ac143ef002fcefddd51effb019..2030ca8067bdf86b7e19d86f9b170b05e5bad73e 100644 (file)
@@ -47,7 +47,7 @@ if(NOT Poly_FOUND_SYSTEM)
   if(CCWIN)
     # Roughly following https://stackoverflow.com/a/44383330/2375725
     set(patchcmd
-        PATCH_COMMAND
+        COMMAND
         patch
         <SOURCE_DIR>/src/CMakeLists.txt
         ${CMAKE_CURRENT_LIST_DIR}/deps-utils/Poly-patch-cmake.patch
@@ -66,19 +66,28 @@ if(NOT Poly_FOUND_SYSTEM)
     unset(patchcmd)
   endif()
 
+  get_target_property(GMP_INCLUDE_DIR GMP INTERFACE_INCLUDE_DIRECTORIES)
+  get_target_property(GMP_LIBRARY GMP IMPORTED_LOCATION)
+  get_filename_component(GMP_LIB_PATH "${GMP_LIBRARY}" DIRECTORY)
+
   ExternalProject_Add(
     Poly-EP
     ${COMMON_EP_CONFIG}
     URL https://github.com/SRI-CSL/libpoly/archive/refs/tags/v${Poly_VERSION}.tar.gz
     URL_HASH SHA1=7af3bbb7a2bca6ef2a41e79447baac08ff30d2fd
     DOWNLOAD_NAME libpoly.tar.gz
-    ${patchcmd}
+    PATCH_COMMAND
+      sed -i.orig
+      "s,add_subdirectory(test/polyxx),add_subdirectory(test/polyxx EXCLUDE_FROM_ALL),g"
+      <SOURCE_DIR>/CMakeLists.txt ${patchcmd}
     CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release
                -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
                -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
                -DLIBPOLY_BUILD_PYTHON_API=OFF
                -DLIBPOLY_BUILD_STATIC=ON
                -DLIBPOLY_BUILD_STATIC_PIC=ON
+               -DCMAKE_INCLUDE_PATH=${GMP_INCLUDE_DIR}
+               -DCMAKE_LIBRARY_PATH=${GMP_LIB_PATH}
     BUILD_COMMAND ${CMAKE_MAKE_PROGRAM} static_pic_poly static_pic_polyxx
     INSTALL_COMMAND ${CMAKE_MAKE_PROGRAM} install
     COMMAND ${CMAKE_COMMAND} -E copy src/libpicpoly.a
@@ -93,6 +102,7 @@ if(NOT Poly_FOUND_SYSTEM)
     DEPENDEES install
     COMMAND ${CMAKE_COMMAND} -E remove_directory <BINARY_DIR>/test/
   )
+  add_dependencies(Poly-EP GMP)
 
   set(Poly_INCLUDE_DIR "${DEPS_BASE}/include/")
   set(Poly_LIBRARIES "${DEPS_BASE}/lib/libpicpoly.a")