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

Generate a pkgconf pc file from cmake #1565

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

harshula
Copy link
Contributor

@harshula harshula commented Aug 2, 2024

While adding pkgconf support to an old fork of FMS, built via Spack, I noticed that the upstream FMS' CMake was not generating the pkgconf pc file.

Testing output:

/opt/release/linux-rocky8-x86_64/intel-2021.2.0/fms-test-b6u4j7f37pf4m2sxontqprjm5wklfxlz/lib64/pkgconfig/FMS.pc:
prefix=/opt/release/linux-rocky8-x86_64/intel-2021.2.0/fms-test-b6u4j7f37pf4m2sxontqprjm5wklfxlz
exec_prefix=/opt/release/linux-rocky8-x86_64/intel-2021.2.0/fms-test-b6u4j7f37pf4m2sxontqprjm5wklfxlz
libdir=/opt/release/linux-rocky8-x86_64/intel-2021.2.0/fms-test-b6u4j7f37pf4m2sxontqprjm5wklfxlz/lib64
includedir=/opt/release/linux-rocky8-x86_64/intel-2021.2.0/fms-test-b6u4j7f37pf4m2sxontqprjm5wklfxlz/include

# Including the following, as they may be useful when building other components
# and as a way to better record how the library was built.
ccompiler=/opt/spack/lib/spack/env/intel/icc
fccompiler=/opt/spack/lib/spack/env/intel/ifort
cppflagss.compiled=
cflags.compiled= -sox -traceback
fcflags.compiled= -fpp -fno-alias -auto -safe-cray-ptr -ftz -assume byterecl -align array64byte -nowarn -sox -traceback
ldflags.compiled=

Name: FMS
Description: The Flexible Modeling System Infrastructure Library
URL: https://www.gfdl.noaa.gov/fms
Version: 2024.2.0
Libs: -L${libdir} -lFMS
Libs.private:
Cflags: -I${includedir}
Fflags: -I${includedir}

What are the relevant CMake variables that should go in Libs.private? Also, ${CMAKE_INSTALL_LIBDIR} is lib64 whereas the FMS library is installed in lib.

@harshula harshula force-pushed the generate-pc-file-from-cmake branch from 95703c6 to bdf5ec6 Compare August 6, 2024 14:18
@rem1776
Copy link
Contributor

rem1776 commented Aug 29, 2024

What are the relevant CMake variables that should go in Libs.private? Also, ${CMAKE_INSTALL_LIBDIR} is lib64 whereas the FMS library is installed in lib.

@harshula Sorry for the delay, didn't notice that question in there initially. The required flags would be for netcdf and mpi. libyaml is also used optionally. I think the relevant CMake variables would be here:

# - NetCDF_<comp>_LIBRARIES - the libraries for the component
# - NetCDF_<comp>_LIBRARY_SHARED - Boolean is true if libraries for component are shared
# - NetCDF_<comp>_INCLUDE_DIRS - the include directories for specified component

# LIBYAML_INCLUDE_DIR
# LIBYAML_LIBRARIES

I think MPI_C/Fortran_INCLUDE_DIRS and MPI_C/Fortran_LINK_FLAGS would be the ones for MPI, but I'm not 100% sure on that.

@climbfuji Do you know why there would be the difference in the install directory locations? Since we mainly utilize the autotools build I figure you may have more insight than me.

@climbfuji
Copy link
Contributor

What are the relevant CMake variables that should go in Libs.private? Also, ${CMAKE_INSTALL_LIBDIR} is lib64 whereas the FMS library is installed in lib.

@harshula Sorry for the delay, didn't notice that question in there initially. The required flags would be for netcdf and mpi. libyaml is also used optionally. I think the relevant CMake variables would be here:

# - NetCDF_<comp>_LIBRARIES - the libraries for the component
# - NetCDF_<comp>_LIBRARY_SHARED - Boolean is true if libraries for component are shared
# - NetCDF_<comp>_INCLUDE_DIRS - the include directories for specified component

# LIBYAML_INCLUDE_DIR
# LIBYAML_LIBRARIES

I think MPI_C/Fortran_INCLUDE_DIRS and MPI_C/Fortran_LINK_FLAGS would be the ones for MPI, but I'm not 100% sure on that.

@climbfuji Do you know why there would be the difference in the install directory locations? Since we mainly utilize the autotools build I figure you may have more insight than me.

Are you referring to the comment above that libfms goes into lib instead of lib64? As far as I know, you can use GNUInstallDirs https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html in cmake, which sets the install directories correctly for whatever system you are on?

@rem1776
Copy link
Contributor

rem1776 commented Sep 2, 2024

@climbfuji Yeah that's what I was referring to, thanks for the info.

It seems like this line should be updated to use whichever lib directory is set by GNUInstallDirs.

set(CONFIG_INSTALL_DESTINATION lib/cmake/fms)

@climbfuji
Copy link
Contributor

@climbfuji Yeah that's what I was referring to, thanks for the info.

It seems like this line should be updated to use whichever lib directory is set by GNUInstallDirs.

set(CONFIG_INSTALL_DESTINATION lib/cmake/fms)

Is that line needed at all? Shouldn't cmake place those cmake files in the correct place w/o it?

@rem1776
Copy link
Contributor

rem1776 commented Sep 3, 2024

Is that line needed at all? Shouldn't cmake place those cmake files in the correct place w/o it?

I think it might be needed as a required argument for configure_package_config_file.

@harshula
Copy link
Contributor Author

Hi @rem1776 & @climbfuji , I've created a separate PR, #1589 , to decide on ${CMAKE_INSTALL_LIBDIR} Vs lib. After that decision is made, I will update this PR accordingly.

@harshula
Copy link
Contributor Author

Hi @rem1776 & @climbfuji , I did an FMS 2024.03.tar.gz autotools build while using Spack built dependencies. I built netcdf as static libraries, using Spack ( spack install --only dependencies fms %intel@2021.2.0 target=x86_64 ^netcdf-c~shared ^netcdf-fortran~shared).

The FMS.pc file looks like:

#***********************************************************************
#*                   GNU Lesser General Public License
#*
#* This file is part of the GFDL Flexible Modeling System (FMS).
#*
#* FMS is free software: you can redistribute it and/or modify it under
#* the terms of the GNU Lesser General Public License as published by
#* the Free Software Foundation, either version 3 of the License, or (at
#* your option) any later version.
#*
#* FMS is distributed in the hope that it will be useful, but WITHOUT
#* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
#* for more details.
#*
#* You should have received a copy of the GNU Lesser General Public
#* License along with FMS.  If not, see <http://www.gnu.org/licenses/>.
#***********************************************************************

prefix=/opt
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

# Including the following, as they may be useful when building other components
# and as a way to better record how the library was built.
ccompiler=mpicc
fccompiler=mpifort
cppflagss.compiled= -fopenmp
cflags.compiled=-I/opt/release/linux-rocky8-x86_64/intel-2021.2.0/netcdf-c-4.9.2-chhxlgbmo52jl5jxr6jdduooa5hukdji/include -fopenmp
fcflags.compiled=-I/opt/release/linux-rocky8-x86_64/intel-2021.2.0/netcdf-fortran-4.6.1-o7w4mq2twc22q6k4wq5lu7le36jzfaws/include -I/opt/release/linux-rocky8-x86_64/intel-2021.2.0/netcdf-fortran-4.6.1-o7w4mq2twc22q6k4wq5lu7le36jzfaws/include  -FR -real-size 64 -fopenmp
ldflags.compiled=-L/opt/release/linux-rocky8-x86_64/intel-2021.2.0/netcdf-c-4.9.2-chhxlgbmo52jl5jxr6jdduooa5hukdji/lib -L/opt/release/linux-rocky8-x86_64/intel-2021.2.0/hdf5-1.14.3-hhugjls2qcwfrp5bdscl7s2sxleqsuyw/lib -lnetcdf -lhdf5_hl -lhdf5 -lm -L/opt/release/linux-rocky8-x86_64/intel-2021.2.0/netcdf-fortran-4.6.1-o7w4mq2twc22q6k4wq5lu7le36jzfaws/lib -lnetcdff -lnetcdf -lm -L/opt/release/linux-rocky8-x86_64/intel-2021.2.0/netcdf-c-4.9.2-chhxlgbmo52jl5jxr6jdduooa5hukdji/lib -L/opt/release/linux-rocky8-x86_64/intel-2021.2.0/hdf5-1.14.3-hhugjls2qcwfrp5bdscl7s2sxleqsuyw/lib -lnetcdf -lhdf5_hl -lhdf5 -lm

Name: FMS
Description: The Flexible Modeling System Infrastructure Library
URL: https://www.gfdl.noaa.gov/fms
Version: 2024.03
Libs: -L$(libdir) -lFMS
Libs.private: -lnetcdff -lnetcdf 
Cflags: -I${includedir}
Fflags: -I${includedir}

The above appears to confirm the Guide to pkg-config:

Libs.private: The link flags for private libraries required by this package but not exposed to applications.

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.

3 participants