Skip to content

Commit 09d8209

Browse files
authored
Merge pull request #535 from ax3l/topic-pkgconfig-static
pkg-config: support static linking
2 parents c8f40a0 + 8806b9d commit 09d8209

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Features
2222
- CMake:
2323

2424
- build a shared library by default #506
25-
- generate pkg-config ``.pc`` file #532
25+
- generate pkg-config ``.pc`` file #532 #535
2626
- Python:
2727

2828
- manylinux2010 wheels for PyPI #523

CMakeLists.txt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,25 @@ configure_file(
731731
${openPMD_BINARY_DIR}/openPMDConfig.cmake
732732
@ONLY
733733
)
734+
735+
# get absolute paths to linked libraries
736+
function(openpmdreclibs tgtname outname)
737+
get_target_property(PC_PRIVATE_LIBS_TGT ${tgtname} INTERFACE_LINK_LIBRARIES)
738+
foreach(PC_LIB IN LISTS PC_PRIVATE_LIBS_TGT)
739+
if(TARGET ${PC_LIB})
740+
openpmdreclibs(${PC_LIB} ${outname})
741+
else()
742+
if(PC_LIB)
743+
string(APPEND ${outname} " ${PC_LIB}")
744+
endif()
745+
endif()
746+
endforeach()
747+
set(${outname} ${${outname}} PARENT_SCOPE)
748+
endfunction()
749+
734750
if(openPMD_HAVE_PKGCONFIG)
735-
CONFIGURE_FILE(
751+
openpmdreclibs(openPMD openPMD_PC_PRIVATE_LIBS)
752+
configure_file(
736753
${openPMD_SOURCE_DIR}/openPMD.pc.in
737754
${openPMD_BINARY_DIR}/openPMD.pc
738755
@ONLY

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
C++ & Python API for Scientific I/O with openPMD
23
================================================
34

@@ -289,6 +290,10 @@ Additional linker and compiler flags for your project are available via:
289290
pkg-config --libs openPMD
290291
# -L${HOME}/somepath/lib -lopenPMD
291292

293+
# if you build openPMD-api as static library with `-DBUILD_SHARED_LIBS=OFF`
294+
pkg-config --libs --static openPMD
295+
# -L/usr/local/lib -L/usr/lib/x86_64-linux-gnu/openmpi/lib -lopenPMD -pthread /usr/lib/libmpi.so -pthread /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so /usr/lib/libmpi.so /usr/lib/x86_64-linux-gnu/hdf5/openmpi/libhdf5.so /usr/lib/x86_64-linux-gnu/libsz.so /usr/lib/x86_64-linux-gnu/libz.so /usr/lib/x86_64-linux-gnu/libdl.so /usr/lib/x86_64-linux-gnu/libm.so -pthread /usr/lib/libmpi.so -pthread /usr/lib/x86_64-linux-gnu/openmpi/lib/libmpi_cxx.so /usr/lib/libmpi.so
296+
292297
pkg-config --cflags openPMD
293298
# -I${HOME}/somepath/include
294299
```

0 commit comments

Comments
 (0)