mirror of
https://github.com/libgit2/libgit2.git
synced 2026-01-25 02:56:17 +00:00
We currently hand-code logic to configure where to install our artifacts via the `LIB_INSTALL_DIR`, `INCLUDE_INSTALL_DIR` and `BIN_INSTALL_DIR` variables. This is reinventing the wheel, as CMake already provide a way to do that via `CMAKE_INSTALL_<DIR>` paths, e.g. `CMAKE_INSTALL_LIB`. This requires users of libgit2 to know about the discrepancy and will require special hacks for any build systems that handle these variables in an automated way. One such example is Gentoo Linux, which sets up these paths in both the cmake and cmake-utils eclass. So let's stop doing that: the GNUInstallDirs module handles it in a better way for us, especially so as the actual values are dependent on CMAKE_INSTALL_PREFIX. This commit removes our own set of variables and instead refers users to use the standard ones. As a second benefit, this commit also fixes our pkgconfig generation to use the GNUInstallDirs module. We had a bug there where we ignored the CMAKE_INSTALL_PREFIX when configuring the libdir and includedir keys, so if libdir was set to "lib64", then libdir would be an invalid path. With GNUInstallDirs, we can now use `CMAKE_INSTALL_FULL_LIBDIR`, which handles the prefix for us.
78 lines
2.6 KiB
CMake
78 lines
2.6 KiB
CMake
# pkg-config file generation
|
|
#
|
|
|
|
function(pkg_build_config)
|
|
set(options)
|
|
set(oneValueArgs NAME DESCRIPTION VERSION FILENAME LIBS_SELF)
|
|
set(multiValueArgs LIBS PRIVATE_LIBS REQUIRES CFLAGS)
|
|
|
|
cmake_parse_arguments(PKGCONFIG "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
|
|
|
|
if (NOT DEFINED PKGCONFIG_FILENAME AND DEFINED PKGCONFIG_NAME)
|
|
set(PKGCONFIG_FILENAME ${PKGCONFIG_NAME})
|
|
endif()
|
|
if (NOT DEFINED PKGCONFIG_FILENAME)
|
|
message(FATAL_ERROR "Missing FILENAME argument")
|
|
endif()
|
|
set(PKGCONFIG_FILE "${PROJECT_BINARY_DIR}/${PKGCONFIG_FILENAME}.pc")
|
|
|
|
if (NOT DEFINED PKGCONFIG_DESCRIPTION)
|
|
message(FATAL_ERROR "Missing DESCRIPTION argument")
|
|
endif()
|
|
|
|
if (NOT DEFINED PKGCONFIG_VERSION)
|
|
message(FATAL_ERROR "Missing VERSION argument")
|
|
endif()
|
|
|
|
# Write .pc "header"
|
|
file(WRITE "${PKGCONFIG_FILE}"
|
|
"prefix=\"${CMAKE_INSTALL_PREFIX}\"\n"
|
|
"libdir=\"${CMAKE_INSTALL_FULL_LIBDIR}\"\n"
|
|
"includedir=\"${CMAKE_INSTALL_FULL_INCLUDEDIR}\"\n"
|
|
"\n"
|
|
"Name: ${PKGCONFIG_NAME}\n"
|
|
"Description: ${PKGCONFIG_DESCRIPTION}\n"
|
|
"Version: ${PKGCONFIG_VERSION}\n"
|
|
)
|
|
|
|
# Prepare Libs
|
|
if(NOT DEFINED PKGCONFIG_LIBS_SELF)
|
|
set(PKGCONFIG_LIBS_SELF "${PKGCONFIG_FILE}")
|
|
endif()
|
|
|
|
if(NOT DEFINED PKGCONFIG_LIBS)
|
|
set(PKGCONFIG_LIBS "-l${PKGCONFIG_LIBS_SELF}")
|
|
else()
|
|
list(INSERT PKGCONFIG_LIBS 0 "-l${PKGCONFIG_LIBS_SELF}")
|
|
endif()
|
|
|
|
list(REMOVE_DUPLICATES PKGCONFIG_LIBS)
|
|
string(REPLACE ";" " " PKGCONFIG_LIBS "${PKGCONFIG_LIBS}")
|
|
file(APPEND "${PKGCONFIG_FILE}" "Libs: -L\${libdir} ${PKGCONFIG_LIBS}\n")
|
|
|
|
# Prepare Libs.private
|
|
if(DEFINED PKGCONFIG_PRIVATE_LIBS)
|
|
list(REMOVE_DUPLICATES PKGCONFIG_PRIVATE_LIBS)
|
|
string(REPLACE ";" " " PKGCONFIG_PRIVATE_LIBS "${PKGCONFIG_PRIVATE_LIBS}")
|
|
file(APPEND "${PKGCONFIG_FILE}" "Libs.private: ${PKGCONFIG_PRIVATE_LIBS}\n")
|
|
endif()
|
|
|
|
# Prepare Requires.private
|
|
if(DEFINED PKGCONFIG_REQUIRES)
|
|
list(REMOVE_DUPLICATES PKGCONFIG_REQUIRES)
|
|
string(REPLACE ";" " " PKGCONFIG_REQUIRES "${PKGCONFIG_REQUIRES}")
|
|
file(APPEND "${PKGCONFIG_FILE}" "Requires.private: ${PKGCONFIG_REQUIRES}\n")
|
|
endif()
|
|
|
|
# Prepare Cflags
|
|
if(DEFINED PKGCONFIG_CFLAGS)
|
|
string(REPLACE ";" " " PKGCONFIG_CFLAGS "${PKGCONFIG_CFLAGS}")
|
|
else()
|
|
set(PKGCONFIG_CFLAGS "")
|
|
endif()
|
|
file(APPEND "${PKGCONFIG_FILE}" "Cflags: -I\${includedir} ${PKGCONFIG_CFLAGS}\n")
|
|
|
|
# Install .pc file
|
|
install(FILES "${PKGCONFIG_FILE}" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
|
endfunction()
|