pkg_check_modules: handle space-joined linker flags
Following up on https://discourse.cmake.org/t/issues-with-opmi-cxx-pc-s-ldflags-and-pkg-check-modules-imported-target/9651 and https://github.com/open-mpi/ompi/issues/12194, pkg_check_modules(... IMPORTED_TARGET ...)
may discard significant -Wl
flags present in the .pc
file, presumably in its dedup phase.
E.g.
❯ cat /nix/store/radkdwgnz90jx0fjssajsikjymp631cb-openmpi-4.1.6/lib/pkgconfig/ompi-cxx.pc
# ...
Libs: -L${libdir} -L/nix/store/iyzz6m4dr6grn10qi67a1g1lp3wrnk7j-libfabric-1.20.0-dev/lib -L/nix/store/bfk76ihs1whd9l51pq1s93sn0j2zd6zq-pmix-5.0.1/lib -L/nix/store/bdd88wiwfzyi7fh04f04y05y7kh1ycz0-libnl-3.7.0-dev/lib -L/nix/store/c8byxr5hgiqyf69d3jr51wgi7g420xsl-libpsm2-12.0.1/lib -Wl,-rpath -Wl,${libdir} -Wl,-rpath -Wl,/nix/store/iyzz6m4dr6grn10qi67a1g1lp3wrnk7j-libfabric-1.20.0-dev/lib -Wl,-rpath -Wl,/nix/store/bfk76ihs1whd9l51pq1s93sn0j2zd6zq-pmix-5.0.1/lib -Wl,-rpath -Wl,/nix/store/bdd88wiwfzyi7fh04f04y05y7kh1ycz0-libnl-3.7.0-dev/lib -Wl,-rpath -Wl,/nix/store/c8byxr5hgiqyf69d3jr51wgi7g420xsl-libpsm2-12.0.1/lib -Wl,--enable-new-dtags -lmpi_cxx -lmpi
Libs.private: -lopen-rte -lopen-pal -lhwloc -lfabric -lucp -luct -lucm -lucs -libverbs -lrdmacm -levent_core -levent_pthreads -lpmix -lnl-3 -lnl-route-3 -lucc -lpsm2 -lm -lz
#
Cflags: -I${includedir}
...translates into
3jr51wgi7g420xsl-libpsm2-12.0.1/lib;-Wl,--enable-new-dtags;-lmpi_cxx;-lmpi
samples> MPI_CXX_LDFLAGS_OTHER=-Wl,-rpath;-Wl,/nix/store/radkdwgnz90jx0fjssajsikjymp631cb-openmpi-4.1.6/lib;-Wl,-rpath;-Wl,/nix/store/iyzz6m4dr6grn10qi67a1g1lp3wrnk7j-libfabric-1.20.0-dev/lib;-Wl,-rpath;-Wl,/nix/store/bfk76ihs1whd9l51pq
1s93sn0j2zd6zq-pmix-5.0.1/lib;-Wl,-rpath;-Wl,/nix/store/bdd88wiwfzyi7fh04f04y05y7kh1ycz0-libnl-3.7.0-dev/lib;-Wl,-rpath;-Wl,/nix/store/c8byxr5hgiqyf69d3jr51wgi7g420xsl-libpsm2-12.0.1/lib;-Wl,--enable-new-dtags
samples> MPI_CXX_LIBRARIES=mpi_cxx;mpi
...
samples> /nix/store/sfgnb6rr428bssyrs54d6d0vv2avi95c-gcc-wrapper-12.3.0/bin/g++ -O3 -DNDEBUG -Wl,-rpath -Wl,/nix/store/radkdwgnz90jx0fjssajsikjymp631cb-openmpi-4.1.6/lib -Wl,/nix/store/iyzz6m4dr6grn10qi67a1g1lp3wrnk7j-libfabric-1.20.0-dev/lib -Wl,/nix/store/bfk76ihs1whd9l51pq1s93sn0j2zd6zq-pmix-5.0.1/lib -Wl,/nix/store/bdd88wiwfzyi7fh04f04y05y7kh1ycz0-libnl-3.7.0-dev/lib -Wl,/nix/store/c8byxr5hgiqyf69d3jr51wgi7g420xsl-libpsm2-12.0.1/lib -Wl,--enable-new-dtags CMakeFiles/roundtrip.dir/exercise_sheets/sheet3/time.cc.o -o roundtrip /nix/store/radkdwgnz90jx0fjssajsikjymp631cb-openmpi-4.1.6/lib/libmpi_cxx.so /nix/store/radkdwgnz90jx0fjssajsikjymp631cb-openmpi-4.1.6/lib/libmpi.so
samples> /nix/store/fzlkaj1ax7gl655blfcr6zzvml1vx3bj-binutils-2.40/bin/ld: error: /nix/store/iyzz6m4dr6grn10qi67a1g1lp3wrnk7j-libfabric-1.20.0-dev/lib: read: Is a directory
samples> collect2: error: ld returned 1 exit status
Note how all but the first -Wl,-rpath
are omitted. While it is possible to rewrite the .pc
files (in this case generated by libtool) in a simpler format (-Wl,-rpath,...
, -Wl,-rpath,=
), CMake in this situation is arguably misinterpreting otherwise valid arguments.
Would you consider supporting this special case? Thanks