Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ubuntu still requires gmp regardless of CMAKE flags #8567

Closed
petrasvestartas opened this issue Oct 22, 2024 · 18 comments
Closed

Ubuntu still requires gmp regardless of CMAKE flags #8567

petrasvestartas opened this issue Oct 22, 2024 · 18 comments

Comments

@petrasvestartas
Copy link

petrasvestartas commented Oct 22, 2024

Issue Details

I set CMake flags but code still requires gmp, why?
The CMAKE code below is enough for mac and windows but not ubuntu. Please help!


  SET(CGAL_CMAKE_EXACT_NT_BACKEND BOOST_BACKEND CACHE STRING "")
  SET(CGAL_DISABLE_GMP ON CACHE BOOL "")
  SET(CMAKE_DISABLE_FIND_PACKAGE_GMP ON CACHE BOOL "")

Source Code

https://github.com/petrasvestartas/wood/blob/main/install_ubuntu.sh

Environment

@mering
Copy link

mering commented Oct 22, 2024

Same for us: We set CGAL_DISABLE_GMP to ON and define CGAL_NO_GMP but get the following building error with CGAL 6.0.1, Boost 1.86.0 and LLVM 18:

llvm/bin/../include/c++/v1/__type_traits/is_constructible.h:22:79: error: incomplete type 'boost::multiprecision::backends::gmp_int' used in type trait expression
   22 | struct _LIBCPP_TEMPLATE_VIS is_constructible : public integral_constant<bool, __is_constructible(_Tp, _Args...)> {};
      |                                                                               ^
boost/libs/multiprecision/include/boost/multiprecision/detail/number_base.hpp:162:20: note: in instantiation of template class 'std::is_constructible<boost::multiprecision::backends::gmp_int, boost::multiprecision::backends::gmp_int>' requested here
  162 |           && (std::is_constructible<typename Num::backend_type, typename detail::canonical<T, typename Num::backend_type>::type>::value 
      |                    ^
boost/libs/multiprecision/include/boost/multiprecision/detail/default_ops.hpp:3953:1: note: in instantiation of template class 'boost::multiprecision::is_compatible_arithmetic_type<boost::multiprecision::number<boost::multiprecision::backends::gmp_int>, boost::multiprecision::number<boost::multiprecision::backends::gmp_int>>' requested here
 3953 | BINARY_OP_FUNCTOR(gcd, number_kind_integer)
      | ^
boost/libs/multiprecision/include/boost/multiprecision/detail/default_ops.hpp:3599:12: note: expanded from macro 'BINARY_OP_FUNCTOR'
 3599 |            is_compatible_arithmetic_type<Arithmetic, number<Backend, et_on> >::value && (number_category<Backend>::value == category),                                                                                                                     \
      |            ^
cgal/include/CGAL/CORE/BigInt.h:151:10: note: while substituting deduced template arguments into function template 'gcd' [with Backend = boost::multiprecision::backends::gmp_int, Arithmetic = BigInt]
  151 |   return boost::multiprecision::gcd(a,b);
      |          ^
boost/libs/multiprecision/include/boost/multiprecision/fwd.hpp:106:17: note: forward declaration of 'boost::multiprecision::backends::gmp_int'
  106 |          struct gmp_int;
      |                 ^

@sloriot
Copy link
Member

sloriot commented Oct 22, 2024

@petrasvestartas Are you using CGAL 6.0.x or 5.6.1?

@mering
Copy link

mering commented Oct 22, 2024

FYI: For us this error appeared when trying to upgrade from 5.6.1 to 6.0.1. In 5.6.1 we didn't have problems with the same setup.

@sloriot
Copy link
Member

sloriot commented Oct 22, 2024

If I'm doing:
CGAL_DIR=~/CGAL/releases/CGAL-6.0.1 cmake -DCGAL_DISABLE_GMP=ON ~/CGAL/releases/CGAL-6.0.1/examples/Triangulation_2 && make info_insert_with_pair_iterator_2

it compiles and if I get not gmp linked:

$ ldd info_insert_with_pair_iterator_2 
	linux-vdso.so.1 (0x00007fff78bad000)
	libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007febaa800000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007febaa721000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007febaaa43000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007febaa540000)
	/lib64/ld-linux-x86-64.so.2 (0x00007febaab0f000)

Could you both give it a try and let me know what you have?

@mering
Copy link

mering commented Oct 22, 2024

We run CMake from Bazel.

We use the following configuration:

BUILD.bazel
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")
load("@rules_license//rules:license.bzl", "license")

package(
    default_applicable_licenses = [":license"],
    default_visibility = ["//visibility:public"],
)

exports_files(["LICENSE"])

license(
    name = "license",
    package_name = "cgal",
    license_kinds = [
        "@rules_license//licenses/generic:by_exception_only",
    ],
)

RESTRICTED_CGAL_PACKAGES = [
    "Advancing_front_surface_reconstruction",
    "Algebraic_kernel_d",
    "Algebraic_kernel_for_circles",
    "Algebraic_kernel_for_spheres",
    "Alpha_shapes_2",
    "Alpha_shapes_3",
    "Apollonius_graph_2",
    "Arrangement_on_surface_2",
    "Barycentric_coordinates_2",
    "Boolean_set_operations_2",
    "Bounding_volumes",
    "CGAL_ipelets",
    "Circular_kernel_2",
    "Circular_kernel_3",
    "Classification",
    "Combinatorial_map",
    "Convex_hull_d",
    "Envelope_2",
    "Envelope_3",
    "Generalized_map",
    "GraphicsView",
    "Heat_method_3",
    "Hyperbolic_triangulation_2",
    "Inscribed_areas",
    "Interpolation",
    "Interval_skip_list",
    "Jet_fitting_3",
    "Linear_cell_complex",
    "Matrix_search",
    "Minkowski_sum_2",
    "Minkowski_sum_3",
    "Miscellany",
    "Nef_2",
    "Nef_3",
    "Nef_S2",
    "NewKernel_d",
    "OpenNL",
    "Optimal_bounding_box",
    "Optimal_transportation_reconstruction_2",
    "Optimisation_basic",
    "Partition_2",
    "Periodic_2_triangulation_2",
    "Periodic_3_mesh_3",
    "Periodic_3_triangulation_3",
    "Periodic_4_hyperbolic_triangulation_2",
    "Point_set_2",
    "Point_set_3",
    "Point_set_processing_3",
    "Poisson_surface_reconstruction_3",
    "Polygonal_surface_reconstruction",
    "Polyline_simplification_2",
    "Polynomial",
    "Polytope_distance_d",
    "Ridges_3",
    "Scale_space_reconstruction_3",
    "Segment_Delaunay_graph_2",
    "Segment_Delaunay_graph_Linf_2",
    "Set_movable_separability_2",
    "Shape_detection",
    "Skin_surface_3",
    "Snap_rounding_2",
    "Straight_skeleton_2",
    "Stream_lines_2",
    "Surface_mesh_approximation",
    "Surface_mesh_deformation",
    "Surface_mesh_parameterization",
    "Surface_mesh_segmentation",
    "Surface_mesh_shortest_path",
    "Surface_mesh_skeletonization",
    "Surface_mesh_topology",
    "Tetrahedral_remeshing",
    "Three",
    "Triangulation",
    "Visibility_2",
    "Voronoi_diagram_2",
]

filegroup(
    name = "cgal_allowed_files",
    srcs = glob(["**"], exclude =
        ["%s/**" % x for x in RESTRICTED_CGAL_PACKAGES],
    ),
    visibility = ["//visibility:public"],
)

# Shows a standard library using the Ninja generator
cmake(
    name = "cgal",
    build_args = [
        "-j4",
    ],
    cache_entries = {
        "BUILD_SHARED_LIBS": "OFF",
        "CGAL_DISABLE_GMP": "ON",
        "WITH_CGAL_Qt5": "OFF",
        "WITH_demos": "OFF",
        "WITH_examples": "OFF",
    },
    defines = [
        "CGAL_USE_CORE",
        "CGAL_HEADER_ONLY",
        "CGAL_EIGEN3_ENABLED",
        "CGAL_USE_OPENMESH",
        "CGAL_NO_GMP",
        "CGAL_NO_MPFR",
    ],
    env = {
        "CMAKE_BUILD_TYPE": "Release",
        "CMAKE_BUILD_PARALLEL_LEVEL": "4",
    },
    lib_source = ":cgal_allowed_files",
    out_headers_only = True,
    deps = [
        "@com_gitlab_libeigen_eigen//:eigen",
        "@openmesh",
        "@onetbb//:tbb",
        "@org_boost//:boost",
    ],
    install_args = [
        "--component",
        "Unspecified",
    ],
)
MODULE.bazel
bazel_dep(name = "toolchains_llvm", version = "1.1.2")

use_repo(non_module_deps, "com_googleapis_storage_chrome_linux_amd64_sysroot")

# Inspect supported toolchains at https://github.com/bazel-contrib/toolchains_llvm/blob/master/toolchain/internal/llvm_distributions.bzl
llvm = use_extension(
    "@toolchains_llvm//toolchain/extensions:llvm.bzl",
    "llvm",
    dev_dependency = True,
)
llvm.toolchain(
    llvm_version = "18.1.4",
)
llvm.sysroot(
    label = "@com_googleapis_storage_chrome_linux_amd64_sysroot//:all_files",
    targets = ["linux-x86_64"],
)
use_repo(llvm, "llvm_toolchain")

register_toolchains(
    "@llvm_toolchain//:all",
    dev_dependency = True,
)

bazel_dep(name = "rules_cc", version = "0.0.10")
bazel_dep(name = "rules_foreign_cc", version = "0.10.1")

Is there anything which looks suspicious to you or where you need additional info?

@sloriot
Copy link
Member

sloriot commented Oct 22, 2024

@mering, is it what you use to "install" CGAL? The cmake option -DCGAL_DISABLE=ON must be provided to all compilation units using CGAL. That is nothing is hardcoded in the installed version of CGAL (it is a simple copy)

@petrasvestartas
Copy link
Author

petrasvestartas commented Oct 22, 2024

@sloriot

I have just tried with 6.0.1 - same problem.
1 year ago, there was no problem, so I suspect that CGAL is not catching my OS: Ubuntu 24.04.1 LTS

These flags works on windows and mac, but not ubuntu:

  set(CGAL_CMAKE_EXACT_NT_BACKEND BOOST_BACKEND CACHE STRING "")
  set(CGAL_DISABLE_GMP ON CACHE BOOL "Disable GMP in CGAL")
  set(CMAKE_DISABLE_FIND_PACKAGE_GMP ON CACHE BOOL "Disable find package GMP in CMake")

@sloriot If you have ubuntu, could try to run this bash file, it suppose it to work just by drag and drop in your terminal:
https://github.com/petrasvestartas/wood/blob/main/install_ubuntu.sh

This .cpp break the compilation with gmp:

image

Source file:
https://github.com/petrasvestartas/wood/blob/2c841fb0632b1cd789676eb0bc6899ae75f6648b/cmake/src/wood/include/cgal_mesh_boolean.cpp#L4

It uses:

#include <CGAL/Polygon_mesh_processing/repair.h>
#include <CGAL/Polygon_mesh_processing/measure.h>
#include <CGAL/Polygon_mesh_processing/orientation.h>

@mering
Copy link

mering commented Oct 22, 2024

@mering, is it what you use to "install" CGAL? The cmake option -DCGAL_DISABLE=ON must be provided to all compilation units using CGAL. That is nothing is hardcoded in the installed version of CGAL (it is a simple copy)

@sloriot What do you mean by "install". This basically runs cmake with the specified cache_entries, and then uses ninja to build and install into a specific directory and copies the cgal library from there.

@sloriot
Copy link
Member

sloriot commented Oct 23, 2024

@mering, is it what you use to "install" CGAL? The cmake option -DCGAL_DISABLE=ON must be provided to all compilation units using CGAL. That is nothing is hardcoded in the installed version of CGAL (it is a simple copy)

@sloriot What do you mean by "install". This basically runs cmake with the specified cache_entries, and then uses ninja to build and install into a specific directory and copies the cgal library from there.

I mean those options should be passed everytime you are compiling a program using CGAL. From what I understand the bazel config file is for copying the library in your third party path. Passing options there is actually not needed. What intricate me is that you said it is working with CGAL 5.6.1
Maybe we should set up a call to better understand your issue.

@sloriot
Copy link
Member

sloriot commented Oct 23, 2024

@petrasvestartas running your script, it gets CGAL 5.6.1 installed.

@petrasvestartas
Copy link
Author

@sloriot

I have just pushed a CMake update with 6.0.1 version, could you please try again?
Thank you.

@sloriot
Copy link
Member

sloriot commented Oct 23, 2024

@sloriot

I have just pushed a CMake update with 6.0.1 version, could you please try again? Thank you.

It's working after having patched wood/cmake/src/wood/include/cgal_box_search.h to replace boost::get by std::get_if (I don't really understand why I get this error because when I tried the first time before your changes the std::get_if were there. Maybe it's a logic error in your cmake)

EDIT: Well I may have clicked too fast. I indeed have link error with gmp. Investigating...

@petrasvestartas
Copy link
Author

@sloriot EDIT: Well I may have clicked too fast. I indeed have link error with gmp. Investigating...
Thank you :)

@sloriot
Copy link
Member

sloriot commented Oct 23, 2024

Works with:

--- a/cmake/CMakeLists.txt
+++ b/cmake/CMakeLists.txt
@@ -405,7 +405,9 @@ if (BUILD_MY_PROJECTS)
   # if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR APPLE)
   #   message("GNU OR APPLE")
   # else()
-  #   target_link_directories(${PROJECT_NAME} PUBLIC "${CMAKE_BINARY_DIR}/install/cgal/auxiliary/gmp/lib/" )
+  set(CGAL_DIR "${CMAKE_BINARY_DIR}/install/cgal/lib/cmake/CGAL")
+  find_package(CGAL REQUIRED)
+  target_link_libraries(${PROJECT_NAME} PUBLIC CGAL::CGAL)
   # endif()
 
   ###############################################################################
diff --git a/cmake/src/wood/include/cgal_box_search.h b/cmake/src/wood/include/cgal_box_search.h
index 2dee714..35ec995 100644
--- a/cmake/src/wood/include/cgal_box_search.h
+++ b/cmake/src/wood/include/cgal_box_search.h
@@ -421,7 +421,7 @@ namespace cgal
                 if (!result)
                     return false;
 
-                if (const IK::Point_2 *p = boost::get<IK::Point_2>(&*result))
+                if (const IK::Point_2 *p = std::get_if<IK::Point_2>(&*result))
                 {
                     p0 = IK::Point_3(p->hx(), p->hy(), 0);
                     p0 = xform_Inv.transform(p0);
@@ -611,7 +611,7 @@ namespace cgal
 
                 if (result)
                 {
-                    if (const IK::Point_2 *p = boost::get<IK::Point_2>(&*result))
+                    if (const IK::Point_2 *p = std::get_if<IK::Point_2>(&*result))
                     {
                         p0 = IK::Point_3(p->hx(), p->hy(), 0);
                         p0 = xform_Inv.transform(p0);

@petrasvestartas
Copy link
Author

petrasvestartas commented Oct 23, 2024

@sloriot I think boost is detected on your system automatically. In my case boost was not found.

Combined with your solution, the code below worked for me.
Thank you very much for your help, I would not have solved it myself.

This issue is solved (to my original question, it can be closed).

  ###############################################################################
  # BOOST
  ###############################################################################

  # Include directories so that boost coould find its headers
  include_directories(${petras_include_paths})

  # Set Boost include directory
  set(BOOST_ROOT ${CMAKE_BINARY_DIR}/install/boost)
  set(BOOST_INCLUDEDIR ${BOOST_ROOT}/include)
  set(BOOST_LIBRARYDIR ${BOOST_ROOT}/lib)
  # Find Boost
  find_package(Boost 1.72 REQUIRED)



  ###############################################################################
  # CGAL
  ###############################################################################

  # Find CGAL
  set(CGAL_DIR "${CMAKE_BINARY_DIR}/install/cgal/lib/cmake/CGAL")
  find_package(CGAL REQUIRED)

  # Link CGAL to the project
  target_link_libraries(${PROJECT_NAME} PUBLIC CGAL::CGAL)

@lrineau
Copy link
Member

lrineau commented Oct 23, 2024

You can probably replace all that with:

list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/install")

find_package(Boost 1.72 REQUIRED)
find_package(CGAL REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC CGAL::CGAL)

The addition of "${CMAKE_BINARY_DIR}/install" to CMAKE_PREFIX_PATH should make the following find_package detect Boost and CGAL automatically.

See the documentation of find_package, section "Config Mode Search Procedure".

@petrasvestartas
Copy link
Author

petrasvestartas commented Oct 23, 2024

@lrineau almost :) the find_package function is always a bit of magic to me.

I need to add:

  set(BOOST_ROOT ${CMAKE_BINARY_DIR}/install/boost)`

to

  list(APPEND CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/install")

  find_package(Boost 1.72 REQUIRED)
  find_package(CGAL REQUIRED)
  target_link_libraries(${PROJECT_NAME} PUBLIC CGAL::CGAL)

@lrineau
Copy link
Member

lrineau commented Oct 24, 2024

This issue is solved (to my original question, it can be closed).

Seems you found the solution. Closing the issue...

@lrineau lrineau closed this as completed Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants