diff options
-rw-r--r-- | modules/ECMGeneratePkgConfigFile.cmake | 37 | ||||
-rw-r--r-- | tests/ECMGeneratePkgConfigFile/KF5CoreAddons4.pc | 13 | ||||
-rw-r--r-- | tests/ECMGeneratePkgConfigFile/run_test.cmake.config | 17 |
3 files changed, 64 insertions, 3 deletions
diff --git a/modules/ECMGeneratePkgConfigFile.cmake b/modules/ECMGeneratePkgConfigFile.cmake index 2fb45c83..99d26ada 100644 --- a/modules/ECMGeneratePkgConfigFile.cmake +++ b/modules/ECMGeneratePkgConfigFile.cmake @@ -16,7 +16,7 @@ projects. ecm_generate_pkgconfig_file(BASE_NAME <baseName> [LIB_NAME <libName>] - [DEPS "<dep> [<dep> [...]]"] + [DEPS [PRIVATE|PUBLIC] <dep> [[PRIVATE|PUBLIC] <dep> [...]]] [FILENAME_VAR <filename_variable>] [INCLUDE_INSTALL_DIR <dir>] [LIB_INSTALL_DIR <dir>] @@ -31,6 +31,13 @@ find the module. it will default to the ``BASE_NAME``. That means the ``LIB_NAME`` will be set as the name field as well as the library to link to. +``DEPS`` is the list of libraries required by this library. Libraries that are +not exposed to applications should be marked with ``PRIVATE``. The default +is ``PUBLIC``, but note that according to the +`Guide to pkg-config <https://people.freedesktop.org/~dbn/pkg-config-guide.html>` +marking dependencies as private is usually preferred. The ``PUBLIC`` and +``PRIVATE`` keywords are supported since 5.89.0. + ``FILENAME_VAR`` is specified with a variable name. This variable will receive the location of the generated file will be set, within the build directory. This way it can be used in case some processing is required. See @@ -130,7 +137,24 @@ function(ECM_GENERATE_PKGCONFIG_FILE) set(PKGCONFIG_TARGET_BASENAME ${EGPF_BASE_NAME}) set(PKGCONFIG_TARGET_LIBNAME ${EGPF_LIB_NAME}) if (DEFINED EGPF_DEPS) - string(REPLACE ";" " " PKGCONFIG_TARGET_DEPS "${EGPF_DEPS}") + # convert the dependencies to a list + string(REPLACE " " ";" EGPF_DEPS "${EGPF_DEPS}") + foreach(EGPF_DEP ${EGPF_DEPS}) + if("${EGPF_DEP}" STREQUAL "") + elseif("${EGPF_DEP}" STREQUAL "PRIVATE") + set(private_deps ON) + elseif("${EGPF_DEP}" STREQUAL "PUBLIC") + unset(private_deps) + else() + if(private_deps) + list(APPEND PKGCONFIG_TARGET_DEPS_PRIVATE "${EGPF_DEP}") + else() + list(APPEND PKGCONFIG_TARGET_DEPS "${EGPF_DEP}") + endif() + endif() + endforeach() + list(JOIN PKGCONFIG_TARGET_DEPS " " PKGCONFIG_TARGET_DEPS) + list(JOIN PKGCONFIG_TARGET_DEPS_PRIVATE " " PKGCONFIG_TARGET_DEPS_PRIVATE) endif () if(IS_ABSOLUTE "${EGPF_INCLUDE_INSTALL_DIR}") set(PKGCONFIG_TARGET_INCLUDES "${EGPF_INCLUDE_INSTALL_DIR}") @@ -153,7 +177,7 @@ function(ECM_GENERATE_PKGCONFIG_FILE) set(${EGPF_FILENAME_VAR} ${PKGCONFIG_FILENAME} PARENT_SCOPE) endif() - file(WRITE ${PKGCONFIG_FILENAME} + set(PKGCONFIG_CONTENT " prefix=${CMAKE_INSTALL_PREFIX} exec_prefix=\${prefix} @@ -168,6 +192,13 @@ Cflags: -I${PKGCONFIG_TARGET_INCLUDES} ${PKGCONFIG_TARGET_DEFINES} Requires: ${PKGCONFIG_TARGET_DEPS} " ) + if(PKGCONFIG_TARGET_DEPS_PRIVATE) + set(PKGCONFIG_CONTENT +"${PKGCONFIG_CONTENT}Requires.private: ${PKGCONFIG_TARGET_DEPS_PRIVATE} +" + ) + endif() + file(WRITE ${PKGCONFIG_FILENAME} "${PKGCONFIG_CONTENT}") if(EGPF_INSTALL) if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") diff --git a/tests/ECMGeneratePkgConfigFile/KF5CoreAddons4.pc b/tests/ECMGeneratePkgConfigFile/KF5CoreAddons4.pc new file mode 100644 index 00000000..0d59faad --- /dev/null +++ b/tests/ECMGeneratePkgConfigFile/KF5CoreAddons4.pc @@ -0,0 +1,13 @@ + +prefix=/usr +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=/usr/KCoreAddons + +Name: KF5CoreAddons4 +Description: KF5CoreAddons4 library. +Version: 5.43 +Libs: -L${prefix}/lib -lKF5CoreAddons4 +Cflags: -I/usr/KCoreAddons +Requires: Public1 Public2 +Requires.private: Private1 Private2 diff --git a/tests/ECMGeneratePkgConfigFile/run_test.cmake.config b/tests/ECMGeneratePkgConfigFile/run_test.cmake.config index f799b202..c0dec227 100644 --- a/tests/ECMGeneratePkgConfigFile/run_test.cmake.config +++ b/tests/ECMGeneratePkgConfigFile/run_test.cmake.config @@ -107,3 +107,20 @@ compare_files(GENERATED ${OutputFile} ORIGINALS ${origfiles}) file(REMOVE ${OutputFile}) file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/metainfo.yaml) + +message(STATUS "Test5: with public and private dependencies") +set(origfiles "${CMAKE_CURRENT_SOURCE_DIR}/KF5CoreAddons4.pc") + +file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/metainfo_without_description.yaml + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) +file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/metainfo_without_description.yaml ${CMAKE_CURRENT_BINARY_DIR}/metainfo.yaml) + +ecm_generate_pkgconfig_file(BASE_NAME KF5CoreAddons4 + DEPS Public1 PRIVATE Private1 Private2 PUBLIC Public2 + INCLUDE_INSTALL_DIR /usr/KCoreAddons + FILENAME_VAR OutputFile) + +compare_files(GENERATED ${OutputFile} + ORIGINALS ${origfiles}) +file(REMOVE ${OutputFile}) +file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/metainfo.yaml) |