Changeset View
Changeset View
Standalone View
Standalone View
modules/ECMGeneratePkgConfigFile.cmake
Show All 10 Lines | |||||
11 | # | 11 | # | ||
12 | # ecm_generate_pkgconfig_file(BASE_NAME <baseName> | 12 | # ecm_generate_pkgconfig_file(BASE_NAME <baseName> | ||
13 | # [LIB_NAME <libName>] | 13 | # [LIB_NAME <libName>] | ||
14 | # [DEPS "<dep> [<dep> [...]]"] | 14 | # [DEPS "<dep> [<dep> [...]]"] | ||
15 | # [FILENAME_VAR <filename_variable>] | 15 | # [FILENAME_VAR <filename_variable>] | ||
16 | # [INCLUDE_INSTALL_DIR <dir>] | 16 | # [INCLUDE_INSTALL_DIR <dir>] | ||
17 | # [LIB_INSTALL_DIR <dir>] | 17 | # [LIB_INSTALL_DIR <dir>] | ||
18 | # [DEFINES -D<variable=value>...] | 18 | # [DEFINES -D<variable=value>...] | ||
19 | # [DESCRIPTION <library description>] | ||||
19 | # [INSTALL]) | 20 | # [INSTALL]) | ||
20 | # | 21 | # | ||
21 | # ``BASE_NAME`` is the name of the module. It's the name projects will use to | 22 | # ``BASE_NAME`` is the name of the module. It's the name projects will use to | ||
22 | # find the module. | 23 | # find the module. | ||
23 | # | 24 | # | ||
24 | # ``LIB_NAME`` is the name of the library that is being exported. If undefined, | 25 | # ``LIB_NAME`` is the name of the library that is being exported. If undefined, | ||
25 | # it will default to the ``BASE_NAME``. That means the ``LIB_NAME`` will be set | 26 | # it will default to the ``BASE_NAME``. That means the ``LIB_NAME`` will be set | ||
26 | # as the name field as well as the library to link to. | 27 | # as the name field as well as the library to link to. | ||
Show All 10 Lines | |||||
37 | # | 38 | # | ||
38 | # ``LIB_INSTALL_DIR`` specifies where the library is being installed. If it's | 39 | # ``LIB_INSTALL_DIR`` specifies where the library is being installed. If it's | ||
39 | # not specified, it will default to ``LIB_INSTALL_DIR``, | 40 | # not specified, it will default to ``LIB_INSTALL_DIR``, | ||
40 | # ``CMAKE_INSTALL_LIBDIR`` or just "lib/" in case they are specified. | 41 | # ``CMAKE_INSTALL_LIBDIR`` or just "lib/" in case they are specified. | ||
41 | # | 42 | # | ||
42 | # ``DEFINES`` is a list of preprocessor defines that it is recommended users of | 43 | # ``DEFINES`` is a list of preprocessor defines that it is recommended users of | ||
43 | # the library pass to the compiler when using it. | 44 | # the library pass to the compiler when using it. | ||
44 | # | 45 | # | ||
46 | # ``DESCRIPTION`` describes what this library is. If it's not specified, CMake | ||||
47 | # will first try to get the description from the metainfo.yaml file or will | ||||
48 | # create one based on ``LIB_NAME``. | ||||
49 | # | ||||
45 | # ``INSTALL`` will cause the module to be installed to the ``pkgconfig`` | 50 | # ``INSTALL`` will cause the module to be installed to the ``pkgconfig`` | ||
46 | # subdirectory of ``LIB_INSTALL_DIR``, unless the ``ECM_PKGCONFIG_INSTALL_DIR`` | 51 | # subdirectory of ``LIB_INSTALL_DIR``, unless the ``ECM_PKGCONFIG_INSTALL_DIR`` | ||
47 | # cache variable is set to something different. Note that the first call to | 52 | # cache variable is set to something different. Note that the first call to | ||
48 | # ecm_generate_pkgconfig_file with the ``INSTALL`` argument will cause | 53 | # ecm_generate_pkgconfig_file with the ``INSTALL`` argument will cause | ||
49 | # ``ECM_PKGCONFIG_INSTALL_DIR`` to be set to the cache, and will be used in any | 54 | # ``ECM_PKGCONFIG_INSTALL_DIR`` to be set to the cache, and will be used in any | ||
50 | # subsequent calls. | 55 | # subsequent calls. | ||
51 | # | 56 | # | ||
52 | # To properly use this macro a version needs to be set. To retrieve it, | 57 | # To properly use this macro a version needs to be set. To retrieve it, | ||
53 | # ``ECM_PKGCONFIG_INSTALL_DIR`` uses ``PROJECT_VERSION``. To set it, use the | 58 | # ``ECM_PKGCONFIG_INSTALL_DIR`` uses ``PROJECT_VERSION``. To set it, use the | ||
54 | # project() command (only available since CMake 3.0) or the ecm_setup_version() | 59 | # project() command (only available since CMake 3.0) or the ecm_setup_version() | ||
55 | # macro. | 60 | # macro. | ||
56 | # | 61 | # | ||
57 | # Example usage: | 62 | # Example usage: | ||
58 | # | 63 | # | ||
59 | # .. code-block:: cmake | 64 | # .. code-block:: cmake | ||
60 | # | 65 | # | ||
61 | # ecm_generate_pkgconfig_file( | 66 | # ecm_generate_pkgconfig_file( | ||
62 | # BASE_NAME KF5Archive | 67 | # BASE_NAME KF5Archive | ||
63 | # DEPS Qt5Core | 68 | # DEPS Qt5Core | ||
64 | # FILENAME_VAR pkgconfig_filename | 69 | # FILENAME_VAR pkgconfig_filename | ||
65 | # INSTALL | 70 | # INSTALL | ||
66 | # ) | 71 | # ) | ||
67 | # | 72 | # | ||
68 | # Since 1.3.0. | 73 | # Since 1.3.0. | ||
74 | # ``DESCRIPTION`` available since 5.1.41 | ||||
75 | # | ||||
69 | 76 | | |||
70 | #============================================================================= | 77 | #============================================================================= | ||
71 | # Copyright 2014 Aleix Pol Gonzalez <aleixpol@kde.org> | 78 | # Copyright 2014 Aleix Pol Gonzalez <aleixpol@kde.org> | ||
72 | # Copyright 2014 David Faure <faure@kde.org> | 79 | # Copyright 2014 David Faure <faure@kde.org> | ||
73 | # | 80 | # | ||
74 | # Redistribution and use in source and binary forms, with or without | 81 | # Redistribution and use in source and binary forms, with or without | ||
75 | # modification, are permitted provided that the following conditions | 82 | # modification, are permitted provided that the following conditions | ||
76 | # are met: | 83 | # are met: | ||
Show All 14 Lines | |||||
91 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 98 | # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
92 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 99 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
93 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 100 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
94 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 101 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
95 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 102 | # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
96 | 103 | | |||
97 | function(ECM_GENERATE_PKGCONFIG_FILE) | 104 | function(ECM_GENERATE_PKGCONFIG_FILE) | ||
98 | set(options INSTALL) | 105 | set(options INSTALL) | ||
99 | set(oneValueArgs BASE_NAME LIB_NAME FILENAME_VAR INCLUDE_INSTALL_DIR LIB_INSTALL_DIR) | 106 | set(oneValueArgs BASE_NAME LIB_NAME FILENAME_VAR INCLUDE_INSTALL_DIR LIB_INSTALL_DIR DESCRIPTION) | ||
100 | set(multiValueArgs DEPS DEFINES) | 107 | set(multiValueArgs DEPS DEFINES) | ||
101 | 108 | | |||
102 | cmake_parse_arguments(EGPF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | 109 | cmake_parse_arguments(EGPF "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
103 | 110 | | |||
104 | if(EGPF_UNPARSED_ARGUMENTS) | 111 | if(EGPF_UNPARSED_ARGUMENTS) | ||
105 | message(FATAL_ERROR "Unknown keywords given to ECM_GENERATE_PKGCONFIG_FILE(): \"${EGPF_UNPARSED_ARGUMENTS}\"") | 112 | message(FATAL_ERROR "Unknown keywords given to ECM_GENERATE_PKGCONFIG_FILE(): \"${EGPF_UNPARSED_ARGUMENTS}\"") | ||
106 | endif() | 113 | endif() | ||
107 | 114 | | |||
Show All 19 Lines | 133 | if(NOT EGPF_LIB_INSTALL_DIR) | |||
127 | if(LIB_INSTALL_DIR) | 134 | if(LIB_INSTALL_DIR) | ||
128 | set(EGPF_LIB_INSTALL_DIR "${LIB_INSTALL_DIR}") | 135 | set(EGPF_LIB_INSTALL_DIR "${LIB_INSTALL_DIR}") | ||
129 | elseif(CMAKE_INSTALL_LIBDIR) | 136 | elseif(CMAKE_INSTALL_LIBDIR) | ||
130 | set(EGPF_LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") | 137 | set(EGPF_LIB_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}") | ||
131 | else() | 138 | else() | ||
132 | set(EGPF_LIB_INSTALL_DIR "lib") | 139 | set(EGPF_LIB_INSTALL_DIR "lib") | ||
133 | endif() | 140 | endif() | ||
134 | endif() | 141 | endif() | ||
142 | if(NOT EGPF_DESCRIPTION) | ||||
143 | if(EXISTS ${CMAKE_SOURCE_DIR}/metainfo.yaml) | ||||
144 | file(STRINGS "${CMAKE_SOURCE_DIR}/metainfo.yaml" _EGPF_METAINFO_DESCRIPTION_STRING REGEX "^description:.*$") | ||||
145 | if(_EGPF_METAINFO_DESCRIPTION_STRING) | ||||
146 | string(REGEX REPLACE "^description:[ ]*(.*)" "\\1" EGPF_DESCRIPTION ${_EGPF_METAINFO_DESCRIPTION_STRING}) | ||||
147 | endif() | ||||
148 | endif() | ||||
149 | if("${EGPF_DESCRIPTION}" STREQUAL "") | ||||
150 | set(EGPF_DESCRIPTION "${EGPF_LIB_NAME} library.") | ||||
151 | endif() | ||||
152 | endif() | ||||
135 | 153 | | |||
136 | set(PKGCONFIG_TARGET_BASENAME ${EGPF_BASE_NAME}) | 154 | set(PKGCONFIG_TARGET_BASENAME ${EGPF_BASE_NAME}) | ||
137 | set(PKGCONFIG_TARGET_LIBNAME ${EGPF_LIB_NAME}) | 155 | set(PKGCONFIG_TARGET_LIBNAME ${EGPF_LIB_NAME}) | ||
138 | if (DEFINED EGPF_DEPS) | 156 | if (DEFINED EGPF_DEPS) | ||
139 | string(REPLACE ";" " " PKGCONFIG_TARGET_DEPS "${EGPF_DEPS}") | 157 | string(REPLACE ";" " " PKGCONFIG_TARGET_DEPS "${EGPF_DEPS}") | ||
140 | endif () | 158 | endif () | ||
141 | if(IS_ABSOLUTE "${EGPF_INCLUDE_INSTALL_DIR}") | 159 | if(IS_ABSOLUTE "${EGPF_INCLUDE_INSTALL_DIR}") | ||
142 | set(PKGCONFIG_TARGET_INCLUDES "-I${EGPF_INCLUDE_INSTALL_DIR}") | 160 | set(PKGCONFIG_TARGET_INCLUDES "-I${EGPF_INCLUDE_INSTALL_DIR}") | ||
143 | else() | 161 | else() | ||
144 | set(PKGCONFIG_TARGET_INCLUDES "-I${CMAKE_INSTALL_PREFIX}/${EGPF_INCLUDE_INSTALL_DIR}") | 162 | set(PKGCONFIG_TARGET_INCLUDES "-I${CMAKE_INSTALL_PREFIX}/${EGPF_INCLUDE_INSTALL_DIR}") | ||
145 | endif() | 163 | endif() | ||
146 | if(IS_ABSOLUTE "${EGPF_LIB_INSTALL_DIR}") | 164 | if(IS_ABSOLUTE "${EGPF_LIB_INSTALL_DIR}") | ||
147 | set(PKGCONFIG_TARGET_LIBS "${EGPF_LIB_INSTALL_DIR}") | 165 | set(PKGCONFIG_TARGET_LIBS "${EGPF_LIB_INSTALL_DIR}") | ||
148 | else() | 166 | else() | ||
149 | set(PKGCONFIG_TARGET_LIBS "${CMAKE_INSTALL_PREFIX}/${EGPF_LIB_INSTALL_DIR}") | 167 | set(PKGCONFIG_TARGET_LIBS "${CMAKE_INSTALL_PREFIX}/${EGPF_LIB_INSTALL_DIR}") | ||
150 | endif() | 168 | endif() | ||
169 | set(PKGCONFIG_TARGET_DESCRIPTION "${EGPF_DESCRIPTION}") | ||||
151 | set(PKGCONFIG_TARGET_DEFINES "") | 170 | set(PKGCONFIG_TARGET_DEFINES "") | ||
152 | if(EGPF_DEFINES) | 171 | if(EGPF_DEFINES) | ||
153 | set(PKGCONFIG_TARGET_DEFINES "${EGPF_DEFINE}") | 172 | set(PKGCONFIG_TARGET_DEFINES "${EGPF_DEFINE}") | ||
154 | endif() | 173 | endif() | ||
155 | 174 | | |||
156 | set(PKGCONFIG_FILENAME ${CMAKE_CURRENT_BINARY_DIR}/${PKGCONFIG_TARGET_BASENAME}.pc) | 175 | set(PKGCONFIG_FILENAME ${CMAKE_CURRENT_BINARY_DIR}/${PKGCONFIG_TARGET_BASENAME}.pc) | ||
157 | if (EGPF_FILENAME_VAR) | 176 | if (EGPF_FILENAME_VAR) | ||
158 | set(${EGPF_FILENAME_VAR} ${PKGCONFIG_FILENAME} PARENT_SCOPE) | 177 | set(${EGPF_FILENAME_VAR} ${PKGCONFIG_FILENAME} PARENT_SCOPE) | ||
159 | endif() | 178 | endif() | ||
160 | 179 | | |||
161 | file(WRITE ${PKGCONFIG_FILENAME} | 180 | file(WRITE ${PKGCONFIG_FILENAME} | ||
162 | " | 181 | " | ||
163 | Name: ${PKGCONFIG_TARGET_LIBNAME} | 182 | Name: ${PKGCONFIG_TARGET_LIBNAME} | ||
183 | Description: ${PKGCONFIG_TARGET_DESCRIPTION} | ||||
164 | Version: ${PROJECT_VERSION} | 184 | Version: ${PROJECT_VERSION} | ||
165 | Libs: -L${CMAKE_INSTALL_PREFIX}/${EGPF_LIB_INSTALL_DIR} -l${PKGCONFIG_TARGET_LIBNAME} | 185 | Libs: -L${CMAKE_INSTALL_PREFIX}/${EGPF_LIB_INSTALL_DIR} -l${PKGCONFIG_TARGET_LIBNAME} | ||
166 | Cflags: ${PKGCONFIG_TARGET_INCLUDES} ${PKGCONFIG_TARGET_DEFINES} | 186 | Cflags: ${PKGCONFIG_TARGET_INCLUDES} ${PKGCONFIG_TARGET_DEFINES} | ||
167 | Requires: ${PKGCONFIG_TARGET_DEPS} | 187 | Requires: ${PKGCONFIG_TARGET_DEPS} | ||
168 | " | 188 | " | ||
169 | ) | 189 | ) | ||
170 | 190 | | |||
171 | if(EGPF_INSTALL) | 191 | if(EGPF_INSTALL) | ||
172 | if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") | 192 | if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") | ||
173 | set(ECM_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/libdata/pkgconfig" CACHE PATH "The directory where pkgconfig will be installed to.") | 193 | set(ECM_PKGCONFIG_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/libdata/pkgconfig" CACHE PATH "The directory where pkgconfig will be installed to.") | ||
174 | else() | 194 | else() | ||
175 | set(ECM_PKGCONFIG_INSTALL_DIR "${EGPF_LIB_INSTALL_DIR}/pkgconfig" CACHE PATH "The directory where pkgconfig will be installed to.") | 195 | set(ECM_PKGCONFIG_INSTALL_DIR "${EGPF_LIB_INSTALL_DIR}/pkgconfig" CACHE PATH "The directory where pkgconfig will be installed to.") | ||
176 | endif() | 196 | endif() | ||
177 | install(FILES ${PKGCONFIG_FILENAME} DESTINATION ${ECM_PKGCONFIG_INSTALL_DIR}) | 197 | install(FILES ${PKGCONFIG_FILENAME} DESTINATION ${ECM_PKGCONFIG_INSTALL_DIR}) | ||
178 | endif() | 198 | endif() | ||
179 | endfunction() | 199 | endfunction() |