From 3333facb851ef550e40e30f85743fdf2306a1a73 Mon Sep 17 00:00:00 2001 From: Harshula Jayasuriya Date: Tue, 3 Dec 2024 04:49:21 +1100 Subject: [PATCH] build: generate a pkgconf pc file from cmake (#1565) --- CMakeLists.txt | 31 +++++++++++++++++++++++++++++++ FMS.pc.in | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 676116f932..aed1a0af88 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -460,3 +460,34 @@ install(EXPORT FMSExports NAMESPACE FMS:: FILE fms-targets.cmake DESTINATION ${CONFIG_INSTALL_DESTINATION}) + +# pkgconf +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix ${CMAKE_INSTALL_PREFIX}) +set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) +set(includedir ${CMAKE_INSTALL_PREFIX}/${includeDir}) + +set(CC ${CMAKE_C_COMPILER}) +set(FC ${CMAKE_Fortran_COMPILER}) +set(CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}") +set(CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${CMAKE_BUILD_TYPE}}") +set(FCFLAGS "${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}}") +set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE}}") + +set(VERSION ${PROJECT_VERSION}) + +# TODO: If FMS depends on a library that is built as a static library, it +# should be listed here as an ldflag. +set(LIBS "") + +if(NOT ${NetCDF_Fortran_LIBRARY_SHARED}) + # autotools: Libs.private: -lnetcdff -lnetcdf + string(APPEND LIBS ${NetCDF_Fortran_LIBRARIES}) +endif() + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/FMS.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/FMS.pc @ONLY) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FMS.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig + COMPONENT utilities) diff --git a/FMS.pc.in b/FMS.pc.in index bc993b5740..c9f2a96e5c 100644 --- a/FMS.pc.in +++ b/FMS.pc.in @@ -35,7 +35,7 @@ Name: FMS Description: The Flexible Modeling System Infrastructure Library URL: https://www.gfdl.noaa.gov/fms Version: @VERSION@ -Libs: -L$(libdir) -lFMS +Libs: -L${libdir} -lFMS Libs.private: @LIBS@ Cflags: -I${includedir} Fflags: -I${includedir}