Skip to content

Conversation

@LecrisUT
Copy link
Contributor

This PR contains both the CMake implementation and CI reorganization. We can split it up later, but lets keep them together until the CI pass

@LecrisUT LecrisUT mentioned this pull request Feb 21, 2024
@LecrisUT LecrisUT force-pushed the cmake branch 2 times, most recently from c1f6922 to 002bdab Compare February 21, 2024 13:46
Copy link
Contributor Author

@LecrisUT LecrisUT left a comment

Choose a reason for hiding this comment

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

@JeromeCCP9 Here's the re-implementation. I have left a few comments

jobs:
tests:
name: Check on ${{ matrix.toolchain }} toolchain ${{ matrix.mpi }}
runs-on: ${{ matrix.os || 'ubuntu-latest' }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no macos and windows here, because we need to discuss what compilers to use there and where to get them

Comment on lines +12 to +17
LANGUAGES Fortran C
)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are some new C sources, but header only? Probably we don't need to add C to the main project in that case.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Adding C is useful for compiling with MKL, without this cmake cannot detect MKL automatically
https://cmake.org/cmake/help/latest/module/FindBLAS.html#intel-mkl

It is a bit annoying since we are actually a fortran code, but without this users need to define a lot of cmake variables for MKL.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What about using find_package(MKL) by default if it's intel compiler, otherwise have an option WANNIER90_MKL option that uses either MKL or default BLAS/LAPACK? I am not sure if it works on a pure Fortran project, but we can try and see

Copy link
Collaborator

Choose a reason for hiding this comment

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

Did a test, we can add some if conditionals to find either MKL or BLAS/LAPACK, however, in the

target_link_libraries(Wannier90_lib PRIVATE
        BLAS::BLAS LAPACK::LAPACK)

I guess we need to add another if for MKL as well, not sure if there is a simpler solution.

On the other hand, by enabling C language everything works automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I suggest we postpone the decision of using either implementation, because @giovannipizzi warned me that there is an issue between LAPACK and macos, which we need to think how to handle.

@LecrisUT
Copy link
Contributor Author

It seems the only failing tests are with ifx, should we change it to ifort and try again, or mark it as experimental for now.

@LecrisUT LecrisUT force-pushed the cmake branch 2 times, most recently from 388e5e4 to 7540c6f Compare February 22, 2024 10:43
@LecrisUT
Copy link
Contributor Author

@JeromeCCP9 There are a few issues with the demo.F90 interface using different variable types. It is also a bit confusing how to deal with mpi_comm being integer in the module file if it's built without mpi. Other than that, the C/C++ interface seems to fail with: undefined reference to symbol 'CFI_establish@@GFORTRAN_9'. Could you assist me with these?

@LecrisUT LecrisUT force-pushed the cmake branch 2 times, most recently from d3eaa3d to bf954ab Compare February 22, 2024 13:10
@LecrisUT LecrisUT mentioned this pull request Feb 22, 2024
@JeromeCCP9
Copy link
Collaborator

Yes, I'll attend to these, let me catch up this evening...

@JeromeCCP9 There are a few issues with the demo.F90 interface using different variable types. It is also a bit confusing how to deal with mpi_comm being integer in the module file if it's built without mpi. Other than that, the C/C++ interface seems to fail with: undefined reference to symbol 'CFI_establish@@GFORTRAN_9'. Could you assist me with these?

@JeromeCCP9
Copy link
Collaborator

This last week I've made some changes to the library and provided a new test driver for the c++ interface in a branch "c-for-gc," and these will be merged shortly into develop. I think that the existent tests must be replaced (by me), so it would make more sense to remove the demo.F90 tests from this PR, if possible? If not, then I merge later, that's also ok.

(Also, at the moment, the c++ interface relies on a f2018 support (for CFI_establish) and this needs to be tested for.)

@LecrisUT
Copy link
Contributor Author

This last week I've made some changes to the library and provided a new test driver for the c++ interface in a branch "c-for-gc," and these will be merged shortly into develop. I think that the existent tests must be replaced (by me)

I saw that, it's ok, just ping me and I will rebase and fix that.

remove the demo.F90

It would be good to have a Fortran test. In #444 I am mocking up a packaging test that would at least do a smoke test.

(Also, at the moment, the c++ interface relies on a f2018 support (for CFI_establish) and this needs to be tested for.)

Do we need specific flag to enable it?

Comment on lines +53 to +60
set(CMAKE_INSTALL_MODULEDIR ${_DEFAULT_CMAKE_INSTALL_MODULEDIR}
CACHE STRING
"Fortran module installation path (Not a cmake native variable)"
)
cmake_path(IS_ABSOLUTE CMAKE_INSTALL_MODULEDIR _is_absolute)
if (_is_absolute)
set(CMAKE_INSTALL_FULL_MODULEDIR ${CMAKE_INSTALL_MODULEDIR})
else ()
Copy link

@MehdiChinoune MehdiChinoune Jun 10, 2024

Choose a reason for hiding this comment

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

It's not a good idea to use CMAKE_ prefixed variables (To avoid a possible future conflict).
I think WANNIER90_INSTALL_MODULEDIR is better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fully aware of that. The issue is that CMake install support for Fortran has not been implemented and these are a bit tricky because these are ABI dependent and there is no discussion on how it should be designed. This path is also one that should be common among all dependencies, thus the preference of CMAKE_ variable.

Currently this is made compatible with fortran-stdlib in hopes that there can be convergence towards that.

Comment on lines 1 to 9
prefix: @CMAKE_INSTALL_PREFIX@

Name: wannier
Version: @PROJECT_VERSION@
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@

Cflags: -I@CMAKE_INSTALL_FULL_MODULEDIR@ -I@CMAKE_INSTALL_FULL_INCLUDEDIR@
Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lwannier90

Choose a reason for hiding this comment

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

Suggested change
prefix: @CMAKE_INSTALL_PREFIX@
Name: wannier
Version: @PROJECT_VERSION@
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@
Cflags: -I@CMAKE_INSTALL_FULL_MODULEDIR@ -I@CMAKE_INSTALL_FULL_INCLUDEDIR@
Libs: -L@CMAKE_INSTALL_FULL_LIBDIR@ -lwannier90
prefix: @CMAKE_INSTALL_PREFIX@
libdir: ${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir: ${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
moduledirL: ${prefix}/@WANNIER90_INSTALL_MODULEDIR@
Name: wannier
Version: @PROJECT_VERSION@
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@
Cflags: -I${moduledir} -I${includedir}
Libs: -L${libdir} -lwannier90

Using full paths make it unrelocatable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, there was some context for this, but I completely lost it. Maybe it was related to testing the pkg-config file in the integration tests since the file in the build directory is not usable. Really don't remember why I made it like that.

There are more issues there though because PUBLIC linked libraries are not included. In principle this should be written as:

file(GENERATE OUTPUT wannier.pc.in INPUT wannier.pc.in.in)
configure_file(${CMAKE_CURRENT_BINARY_DIR}/wannier.pc.in wannier.pc)

And use a gen-ex depending on the target property to get the -l/-L/-I flags needed there. Didn't get the time to investigate what are appropriate flags for it though, would appreciate some help/discussion on this.

This is necessary because of the use mpi_f08 that is conditionally used in the Fortran module api.

Copy link

@MehdiChinoune MehdiChinoune Jun 10, 2024

Choose a reason for hiding this comment

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

You could add a new string variable WANNIER_LINK_LIBRARIES and add any library wannier is linked to. then add Requires: @WANNIER_LINK_LIBRARIES@ to wannier.pc.in file.
but WANNIER_LINK_LIBRARIES should contain the names of their .pc files.

Copy link
Contributor Author

@LecrisUT LecrisUT Jun 10, 2024

Choose a reason for hiding this comment

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

The question is where do we get the values to construct it? If we figure out that, I can write a prototype to be more templatable.

These values are taken from targets like MPI::MPI_Fortran. We can investigate that is populate in there with things like: https://stackoverflow.com/a/34292622. It should be in an *_INTERFACE_* like property. But maybe target Wannier_lib should be used to check that instead

@LecrisUT LecrisUT force-pushed the cmake branch 4 times, most recently from 2393d90 to ef03aef Compare June 11, 2024 09:52
@LecrisUT LecrisUT force-pushed the cmake branch 5 times, most recently from 13df820 to e26ac57 Compare February 9, 2025 19:51
@LecrisUT LecrisUT force-pushed the cmake branch 3 times, most recently from 92633c8 to 74827e6 Compare February 9, 2025 20:32
@LecrisUT
Copy link
Contributor Author

LecrisUT commented Feb 9, 2025

@JeromeCCP9 Can you check this PR again? I have disabled tests that fail, but you can work on it gradually in subsequent PRs. It would be great to get this in, because I plan to package this for Fedora soon because of quantum-espresso dependency

@JeromeCCP9
Copy link
Collaborator

Hi Christian! Yes, surely we'll work on this and include it in 4.0. For me the main concern was that the configuration files were a bit too complex and complicated, but let me go through it and we'll discuss later.

Thank you for revisiting this! It is good timing. Jerome

@JeromeCCP9 JeromeCCP9 self-requested a review March 10, 2025 12:26
Copy link
Collaborator

@JeromeCCP9 JeromeCCP9 left a comment

Choose a reason for hiding this comment

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

Provides rich cmake support for Wannier90!

@JeromeCCP9 JeromeCCP9 force-pushed the cmake branch 2 times, most recently from ecf0969 to f0f72e7 Compare March 10, 2025 17:01
@jryates jryates merged commit 3bfc300 into wannier-developers:develop Mar 10, 2025
1 of 2 checks passed
@LecrisUT LecrisUT deleted the cmake branch July 8, 2025 19:43
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.

5 participants