Skip to content

point GMPXX_INCLUDE_DIR to locally built gmp#2030

Merged
alecjacobson merged 5 commits intomainfrom
alecjacobson/gmpxx-include-dir
May 1, 2022
Merged

point GMPXX_INCLUDE_DIR to locally built gmp#2030
alecjacobson merged 5 commits intomainfrom
alecjacobson/gmpxx-include-dir

Conversation

@alecjacobson
Copy link
Copy Markdown
Contributor

Fixes #2029

gmpxx is part of gmp and we're building it via cmake. Previously we weren't telling cgal where to find it and on some machines (mine at least) it was finding it at /usr/local/include. This caused /usr/local/include to be added to include paths which caused #2029 to happen (cgal was also found there and confused).

This should tell cgal where to find gmpxx and subsequently not add /usr/local/include.

set(GMP_INCLUDE_DIR "")
set(GMP_INCLUDE_DIR ${gmp_INCLUDE_DIR})
set(GMP_LIBRARIES gmp::gmp)
set(GMPXX_INCLUDE_DIR ${GMP_INCLUDE_DIR})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should add ignore_package(GMPXX 5.0.1) as well just to be safe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what this is doing? If it makes sense to add, then happy to.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(adding this doesn't seem to hurt)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ignore_package() is a function I wrote in this cgal.cmake. Basically it will add an empty GMPXXConfig.cmake file, thus preventing CGAL from using its own FindGMPXX.cmake file (and subsequently adding /usr/local/include to your include paths).


ignore_package(GMP 5.0.1)
set(GMP_INCLUDE_DIR "")
set(GMP_INCLUDE_DIR ${gmp_INCLUDE_DIR})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary, since our target gmp::gmp should carry the include dir already.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think CGAL's cmake is looking at GMPXX_INCLUDE_DIR so it needs to be explicitly set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed, if GMPXX_INCLUDE_DIR is set to "" then CGAL determines that CGAL_WITH_GMPXX:BOOL=OFF. By setting GMPXX_INCLUDE_DIR explicitly then we keep CGAL_WITH_GMPXX:BOOL=ON.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you add ignore_package(GMPXX 5.0.1), you can probably leave GMP_INCLUDE_DIR and GMPXX_INCLUDE_DIR set to "", since the fake GMPXXConfig.cmake will set GMPXX_FOUND to ON, and CGAL_WITH_GMPXX should subsequently be set to ON.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, got it. Didn't realize these were related. I pushed the change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're back to the state of the original PR which passes CI. If there's a more elegant way to handle GMPXX that maintains passing for Windows then let's merge it in a new PR. I'll merge this for now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by why would the CI succeed? With your changes you are not preventing CGAL's FindGMPXX from executing. But because you set the GMPXX_INCLUDE_DIR variable in advance, CGAL is using those locations. On Windows, it will still go through this find_path() command and silently fail to find GMPXX. On Linux/macOS, I am not sure whether it find them or not.

In the end I suppose your setup kinda works, though you may think you're using GMPXX on Windows when you are not.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. In the merge version GMPXX_INCLUDE_DIR is set to point to the gmp build for all systems, and I guess on windows cgal will realize that gmpxx should be off so it's ignored. Using the ignore_package caused windows build to fail out of the box. If there's a solution that avoids pretending that gmpxx is really there then we should merge it, but I'm not sure what that is and I end up pulling my hair out trying to debug the windows build.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the solution is simple:

if(WIN32)
    set(CMAKE_DISABLE_FIND_PACKAGE_GMPXX ON)
else()
    ignore_package(GMPXX 5.0.1)
    set(GMPXX_INCLUDE_DIR "")
    set(GMPXX_LIBRARIES ${GMP_LIBRARIES})
endif()

The end result should be basically the same though...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😊 Want to PR this and merge?

@alecjacobson alecjacobson merged commit 04f06d7 into main May 1, 2022
@alecjacobson alecjacobson deleted the alecjacobson/gmpxx-include-dir branch May 1, 2022 22:07
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

Successfully merging this pull request may close these issues.

cmake using -isystem for cgal includes and finding homebrew install instead?

2 participants