From 9579d8d0ffb84c8c2ade5b24de90b1c1f191aef5 Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Tue, 4 Jul 2023 00:11:46 +0200 Subject: [PATCH] gdal.pc generation: use CMAKE_INSTALL_INCLUDEDIR/CMAKE_INSTALL_LIBDIR for includedir/libdir (refs #8012) --- cmake/helpers/GdalGenerateConfig.cmake | 28 ++++++++++++++++++++++++++ cmake/template/gdal.pc.in | 4 ++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/cmake/helpers/GdalGenerateConfig.cmake b/cmake/helpers/GdalGenerateConfig.cmake index b45958f48dde..6305f662d08e 100644 --- a/cmake/helpers/GdalGenerateConfig.cmake +++ b/cmake/helpers/GdalGenerateConfig.cmake @@ -276,6 +276,34 @@ function(gdal_generate_config) endif() gdal_join_and_quote(CONFIG_LIBS) + # For gdal.pc libdir variable. Not strictly needed, but quite standard + # to have one in a .pc + if(IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") + if( "${CMAKE_INSTALL_LIBDIR}" MATCHES "^${CONFIG_PREFIX}.*") + file(RELATIVE_PATH _rel_path "${CONFIG_PREFIX}" "${CMAKE_INSTALL_LIBDIR}") + set(CONFIG_LIBDIR "\${exec_prefix}/${_rel_path}") + else() + set(CONFIG_LIBDIR "${CMAKE_INSTALL_LIBDIR}") + endif() + else() + set(CONFIG_LIBDIR "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}") + endif() + gdal_join_and_quote(CONFIG_LIBDIR) + + # For gdal.pc includedir variable. Not strictly needed, but quite standard + # to have one in a .pc + if(IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") + if( "${CMAKE_INSTALL_INCLUDEDIR}" MATCHES "^${CONFIG_PREFIX}.*") + file(RELATIVE_PATH _rel_path "${CONFIG_PREFIX}" "${CMAKE_INSTALL_INCLUDEDIR}") + set(CONFIG_INCLUDEDIR "\${exec_prefix}/${_rel_path}") + else() + set(CONFIG_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}") + endif() + else() + set(CONFIG_INCLUDEDIR "\${exec_prefix}/${CMAKE_INSTALL_INCLUDEDIR}") + endif() + gdal_join_and_quote(CONFIG_INCLUDEDIR) + get_property(libs GLOBAL PROPERTY "${arg_GLOBAL_PROPERTY}") if(NOT MSVC AND CMAKE_THREAD_LIBS_INIT) list(APPEND libs ${CMAKE_THREAD_LIBS_INIT}) diff --git a/cmake/template/gdal.pc.in b/cmake/template/gdal.pc.in index 23d99f8687c3..9aefa4b0d5c6 100644 --- a/cmake/template/gdal.pc.in +++ b/cmake/template/gdal.pc.in @@ -5,8 +5,8 @@ CONFIG_INST_CFLAGS=@CONFIG_CFLAGS@ CONFIG_INST_DATA=@CONFIG_DATA@ prefix=${CONFIG_INST_PREFIX} exec_prefix=${prefix} -libdir=${exec_prefix}/lib -includedir=${exec_prefix}/include +libdir=@CONFIG_LIBDIR@ +includedir=@CONFIG_INCLUDEDIR@ datadir=${CONFIG_INST_DATA} Name: libgdal