File tree 11 files changed +79
-3
lines changed
11 files changed +79
-3
lines changed Original file line number Diff line number Diff line change 12
12
#
13
13
# See https://github.com/pre-commit/pre-commit
14
14
15
+ # third-party content
16
+ exclude : ^tools/JoinPaths.cmake$
17
+
15
18
repos :
16
19
# Standard hooks
17
20
- repo : https://github.com/pre-commit/pre-commit-hooks
Original file line number Diff line number Diff line change @@ -198,6 +198,9 @@ else()
198
198
endif ()
199
199
200
200
include ("${CMAKE_CURRENT_SOURCE_DIR} /tools/pybind11Common.cmake" )
201
+ # https://github.com/jtojnar/cmake-snips/#concatenating-paths-when-building-pkg-config-files
202
+ # TODO: cmake 3.20 adds the cmake_path() function, which obsoletes this snippet
203
+ include ("${CMAKE_CURRENT_SOURCE_DIR} /tools/JoinPaths.cmake" )
201
204
202
205
# Relative directory setting
203
206
if (USE_PYTHON_INCLUDE_DIR AND DEFINED Python_INCLUDE_DIRS)
@@ -262,6 +265,16 @@ if(PYBIND11_INSTALL)
262
265
NAMESPACE "pybind11::"
263
266
DESTINATION ${PYBIND11_CMAKECONFIG_INSTALL_DIR} )
264
267
268
+ # pkg-config support
269
+ if (NOT prefix_for_pc_file)
270
+ set (prefix_for_pc_file "${CMAKE_INSTALL_PREFIX} " )
271
+ endif ()
272
+ join_paths(includedir_for_pc_file "\$ {prefix}" "${CMAKE_INSTALL_INCLUDEDIR} " )
273
+ configure_file ("${CMAKE_CURRENT_SOURCE_DIR} /tools/pybind11.pc.in"
274
+ "${CMAKE_CURRENT_BINARY_DIR} /pybind11.pc" @ONLY)
275
+ install (FILES "${CMAKE_CURRENT_BINARY_DIR} /pybind11.pc"
276
+ DESTINATION "${CMAKE_INSTALL_DATAROOTDIR} /pkgconfig/" )
277
+
265
278
# Uninstall target
266
279
if (PYBIND11_MASTER_PROJECT)
267
280
configure_file ("${CMAKE_CURRENT_SOURCE_DIR} /tools/cmake_uninstall.cmake.in"
Original file line number Diff line number Diff line change 6
6
7
7
8
8
from ._version import __version__ , version_info
9
- from .commands import get_cmake_dir , get_include
9
+ from .commands import get_cmake_dir , get_include , get_pkgconfig_dir
10
10
11
11
__all__ = (
12
12
"version_info" ,
13
13
"__version__" ,
14
14
"get_include" ,
15
15
"get_cmake_dir" ,
16
+ "get_pkgconfig_dir" ,
16
17
)
Original file line number Diff line number Diff line change 4
4
import sys
5
5
import sysconfig
6
6
7
- from .commands import get_cmake_dir , get_include
7
+ from .commands import get_cmake_dir , get_include , get_pkgconfig_dir
8
8
9
9
10
10
def print_includes () -> None :
@@ -36,13 +36,20 @@ def main() -> None:
36
36
action = "store_true" ,
37
37
help = "Print the CMake module directory, ideal for setting -Dpybind11_ROOT in CMake." ,
38
38
)
39
+ parser .add_argument (
40
+ "--pkgconfigdir" ,
41
+ action = "store_true" ,
42
+ help = "Print the pkgconfig directory, ideal for setting $PKG_CONFIG_PATH." ,
43
+ )
39
44
args = parser .parse_args ()
40
45
if not sys .argv [1 :]:
41
46
parser .print_help ()
42
47
if args .includes :
43
48
print_includes ()
44
49
if args .cmakedir :
45
50
print (get_cmake_dir ())
51
+ if args .pkgconfigdir :
52
+ print (get_pkgconfig_dir ())
46
53
47
54
48
55
if __name__ == "__main__" :
Original file line number Diff line number Diff line change @@ -23,3 +23,15 @@ def get_cmake_dir() -> str:
23
23
24
24
msg = "pybind11 not installed, installation required to access the CMake files"
25
25
raise ImportError (msg )
26
+
27
+
28
+ def get_pkgconfig_dir () -> str :
29
+ """
30
+ Return the path to the pybind11 pkgconfig directory.
31
+ """
32
+ pkgconfig_installed_path = os .path .join (DIR , "share" , "pkgconfig" )
33
+ if os .path .exists (pkgconfig_installed_path ):
34
+ return pkgconfig_installed_path
35
+
36
+ msg = "pybind11 not installed, installation required to access the pkgconfig files"
37
+ raise ImportError (msg )
Original file line number Diff line number Diff line change @@ -127,6 +127,7 @@ def remove_output(*sources: str) -> Iterator[None]:
127
127
"-DCMAKE_INSTALL_PREFIX=pybind11" ,
128
128
"-DBUILD_TESTING=OFF" ,
129
129
"-DPYBIND11_NOPYTHON=ON" ,
130
+ "-Dprefix_for_pc_file=${pcfiledir}/../../" ,
130
131
]
131
132
if "CMAKE_ARGS" in os .environ :
132
133
fcommand = [
Original file line number Diff line number Diff line change 59
59
"share/cmake/pybind11/pybind11Tools.cmake" ,
60
60
}
61
61
62
+ pkgconfig_files = {
63
+ "share/pkgconfig/pybind11.pc" ,
64
+ }
65
+
62
66
py_files = {
63
67
"__init__.py" ,
64
68
"__main__.py" ,
69
73
}
70
74
71
75
headers = main_headers | detail_headers | stl_headers
72
- src_files = headers | cmake_files
76
+ src_files = headers | cmake_files | pkgconfig_files
73
77
all_files = src_files | py_files
74
78
75
79
82
86
"pybind11/share" ,
83
87
"pybind11/share/cmake" ,
84
88
"pybind11/share/cmake/pybind11" ,
89
+ "pybind11/share/pkgconfig" ,
85
90
"pyproject.toml" ,
86
91
"setup.cfg" ,
87
92
"setup.py" ,
Original file line number Diff line number Diff line change
1
+ # This module provides function for joining paths
2
+ # known from most languages
3
+ #
4
+ # SPDX-License-Identifier: (MIT OR CC0-1.0)
5
+ # Copyright 2020 Jan Tojnar
6
+ # https://github.com/jtojnar/cmake-snips
7
+ #
8
+ # Modelled after Python’s os.path.join
9
+ # https://docs.python.org/3.7/library/os.path.html#os.path.join
10
+ # Windows not supported
11
+ function (join_paths joined_path first_path_segment)
12
+ set (temp_path "${first_path_segment} " )
13
+ foreach (current_segment IN LISTS ARGN)
14
+ if (NOT ("${current_segment} " STREQUAL "" ))
15
+ if (IS_ABSOLUTE "${current_segment} " )
16
+ set (temp_path "${current_segment} " )
17
+ else ()
18
+ set (temp_path "${temp_path} /${current_segment} " )
19
+ endif ()
20
+ endif ()
21
+ endforeach ()
22
+ set (${joined_path} "${temp_path} " PARENT_SCOPE)
23
+ endfunction ()
Original file line number Diff line number Diff line change
1
+ prefix=@prefix_for_pc_file@
2
+ includedir=@includedir_for_pc_file@
3
+
4
+ Name: @PROJECT_NAME@
5
+ Description: Seamless operability between C++11 and Python
6
+ Version: @PROJECT_VERSION@
7
+ Cflags: -I${includedir}
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ main_headers = glob.glob("pybind11/include/pybind11/*.h")
29
29
detail_headers = glob .glob ("pybind11/include/pybind11/detail/*.h" )
30
30
stl_headers = glob .glob ("pybind11/include/pybind11/stl/*.h" )
31
31
cmake_files = glob .glob ("pybind11/share/cmake/pybind11/*.cmake" )
32
+ pkgconfig_files = glob .glob ("pybind11/share/pkgconfig/*.pc" )
32
33
headers = main_headers + detail_headers + stl_headers
33
34
34
35
cmdclass = {"install_headers" : InstallHeadersNested }
51
52
headers = headers ,
52
53
data_files = [
53
54
(base + "share/cmake/pybind11" , cmake_files ),
55
+ (base + "share/pkgconfig" , pkgconfig_files ),
54
56
(base + "include/pybind11" , main_headers ),
55
57
(base + "include/pybind11/detail" , detail_headers ),
56
58
(base + "include/pybind11/stl" , stl_headers ),
Original file line number Diff line number Diff line change @@ -17,13 +17,15 @@ setup(
17
17
"pybind11.include.pybind11.detail" ,
18
18
"pybind11.include.pybind11.stl" ,
19
19
"pybind11.share.cmake.pybind11" ,
20
+ "pybind11.share.pkgconfig" ,
20
21
],
21
22
package_data = {
22
23
"pybind11" : ["py.typed" ],
23
24
"pybind11.include.pybind11" : ["*.h" ],
24
25
"pybind11.include.pybind11.detail" : ["*.h" ],
25
26
"pybind11.include.pybind11.stl" : ["*.h" ],
26
27
"pybind11.share.cmake.pybind11" : ["*.cmake" ],
28
+ "pybind11.share.pkgconfig" : ["*.pc" ],
27
29
},
28
30
extras_require = {
29
31
"global" : ["pybind11_global==$version" ]
You can’t perform that action at this time.
0 commit comments