MNT: Use policy_max in cmake_minimum_required#990
Conversation
efe5e13 to
4254eaf
Compare
|
👋 @shimwell @ahnaf-tahmid-chowdhury @gonuke @pshriwise as you all reviewed PR #969, which was the last time Line 2 in a435d06 was touched, can I get one of you to approve a CI run on this before I request review (in the event that I might want to clear or clarify a few things first)? |
|
Thanks to whoever enabled the CI. 👍 The macOS build tests are failing but given DAGMC/.github/workflows/mac_build_test.yml Lines 58 to 75 in a435d06 and this seems to be unrelated to this PR specifically and more issues with what's currently installed by the Homebrew |
3bc9d92 to
df42c97
Compare
* Set policy_max which defines the maximum CMake policy. cmake_minimum_required sets two minimums: the real (lower) minimum and the (upper) minimum based on has been tested with. The defaults (CMake policies) will be set to the highest value possible between the two values. - c.f. https://cmake.org/cmake/help/latest/command/cmake_minimum_required.html * Move cmake_minimum_required position in files given warning: cmake_minimum_required() should be called prior to this top-level project() call. Please see the cmake-commands(7) manual for usage documentation of both commands. * Older versions of CMake v3.x policies are being deprecated and as of CMake v4, compatibility with CMake < 3.5 has been removed, so all CMake v2 policies are no longer useable. * FATAL_ERROR option is accepted but ignored by CMake 2.6 and higher, and so is removed as it can have no effect. * CMake policy is not changed on CMake patch releases, so specifying a CMake version beyond the minor level to the patch level is not informative or meaningful.
* Homebrew's Eigen in 2026 is Eigen v5.x, which is incompatible with MOAB
v5.5.1 FindEigen3.cmake. Homebrew has bad version control, and so
instead of trying to force Homebrew to install a compatible version,
build Eigen v3.4.0 (a header-only library) from source to ensure that
Eigen3Config.cmake is generated for DAGMC's CMake invocation to use
find_package(Eigen3 REQUIRED NO_MODULE).
* Additionally, in CMavke v4 TestEndianess.c.in was renamed to
TestEndianness.c.in to fix a typo. MOAB v5.5.1 used a custom
config/TestBigEndian.cmake that hardcodes the use of TestEndianess.c.in.
$ git grep "TestEndianess.c.in"
config/TestBigEndian.cmake:39: CONFIGURE_FILE("${CMAKE_ROOT}/Modules/TestEndianess.c.in"
As config/ is first in CMAKE_MODULE_PATH, MOAB's broken version is used
instead of CMake's working built-in module. To avoid this, set
HAVE_WORDS_BIGENDIAN=TRUE to skip the test, instead of deleting the broken
module. This works as HAVE_WORDS_BIGENDIAN=TRUE skips the test
test_big_endian, defaulting to little-endian, which for effectively all runner
platforms is correct.
$ git grep -m 1 '(HAVE_' -- config/TestBigEndian.cmake
config/TestBigEndian.cmake:8: IF(HAVE_${VARIABLE} MATCHES ^HAVE_${VARIABLE}$)
* Use modern CMake syntax of the general pattern cmake -G <generator> -DCMAKE_INSTALL_PREFIX=<prefix> -S src -B build cmake build -LH cmake --build build --clean-first --parallel <number parallel> cmake --install build which allows for more portability, and allows for CMake to be more efficient in its execution and use alternative generators like ninja.
df42c97 to
d14f06f
Compare
|
👋 @shimwell @ahnaf-tahmid-chowdhury @gonuke @pshriwise this is ready for review now (and needs a CI approval again). Let me know if you have any questions. 👍 |
gonuke
left a comment
There was a problem hiding this comment.
Thanks @matthewfeickert - I wasn't aware of this CMake policy. I am curious whether what the value of adding the max version is? I suppose if a newer version makes our CMake configuration break, this would detect/avoid that? On the other hand, it creates a maintenance burden to keep updating this periodically.
I made a note about the change in gtest - wonder what your thoughts are there?
| # as ${gtest_SOURCE_DIR} and to the root binary directory as | ||
| # ${gtest_BINARY_DIR}. | ||
| # Language "C" is required for find_package(Threads). | ||
| cmake_minimum_required(VERSION 2.6...4.2) |
There was a problem hiding this comment.
I think this is otherwise-unedited copy of the google-test-suite code. Is it problematic to leave this one as-is and make an issue to change our dependence on this, either by updating the version we have copied in or make it an external dependency?
There was a problem hiding this comment.
Is it problematic to leave this one as-is and make an issue to change our dependence on this, either by updating the version we have copied in or make it an external dependency?
It actually won't build at all, given that CMake v4.0 dropped all policies older than 3.5 (longer summary in #990 (comment)). It there a particularly strong reason to vendor gtest compared to having it as an external? If not, having it as a dependency would probably be more long-term sustainable with CMake.
| brew install eigen hdf5 | ||
| brew install hdf5 | ||
|
|
||
| # Homebrew's Eigen in 2026 is Eigen v5.x, which is incompatible with |
There was a problem hiding this comment.
Huh... maybe we should be moving this forward in MOAB under a different issue...
There was a problem hiding this comment.
@gonuke I'm happy to migrate any MOAB related things to https://bitbucket.org/fathomteam/moab/src/master/. I had assumed that as MOAB v5.6.0 existed on conda-forge but DAGMC was testing against MOAB v5.5.1 that there was some restriction on DAGMC's compatibility with the v5.6.x series of MOAB. If not (that's great) then MOAB related things can for sure be moved upstream and separated out from this PR.
| git clone -b 5.5.1 --depth 1 --shallow-submodules https://bitbucket.org/fathomteam/moab moab_src | ||
|
|
||
| # In CMavke v4 TestEndianess.c.in was renamed to TestEndianness.c.in | ||
| # to fix a typo. MOAB v5.5.1 used a custom config/TestBigEndian.cmake |
There was a problem hiding this comment.
Seems like another place for a MOAB issue/update?
@gonuke The short version of this is somewhat the opposite of your statement. Here's a much longer summary taken from my colleague Henry Schreiner on a GitLab project MR (I'm quoting exactly here, so the CMake versions in question will be different):
In practice this is low effort in that builds are ideally tested with latest (or at least modern) releases of tooling, and so when a new major or modern version of CMake comes out you bump the |
gonuke
left a comment
There was a problem hiding this comment.
Thanks for the interest, investment and education @matthewfeickert
Lets go forward with this as is and generate some new issues for things that arose here
Description
Fixes to Mac Build/Test workflow
v5.x, which is incompatible with MOABv5.5.1FindEigen3.cmake. Homebrew has bad version control, and so instead of trying to force Homebrew to install a compatible version, build Eigenv3.4.0(a header-only library) from source to ensure thatEigen3Config.cmakeis generated for DAGMC's CMake invocation to usefind_package(Eigen3 REQUIRED NO_MODULE).TestEndianess.c.inwas renamed toTestEndianness.c.into fix a typo. MOABv5.5.1used a customconfig/TestBigEndian.cmakethat hardcodes the use ofTestEndianess.c.in.As
config/is first inCMAKE_MODULE_PATH, MOAB's broken version is used instead of CMake's working built-in module. To avoid this, setHAVE_WORDS_BIGENDIAN=TRUEto skip the test, instead of deleting the broken module. This works asHAVE_WORDS_BIGENDIAN=TRUEskips the testtest_big_endian, defaulting to little-endian, which for effectively all runner platforms is correct.MOAB_DIR, which I did not expect.Motivation and Context
Changes
Maintenance and build longevity.
Behavior
What is the current behavior? What is the new behavior?
The CMake policy is frozen at old or fully deprecated versions which are no longer accessible by modern CMake. The CMake policy_max range allows for setting the lower minimum and then updating the lower and the upper minimums as needed given changes, allowing for the most wide range of viable builds.
Changelog file
All pull requests are required to update the CHANGELOG file with the PR. Your update can take different forms including:
✔️