[CMake] FindPkgConfig and OS X frameworks
David Golden
david at mongodb.com
Thu Dec 15 14:37:42 EST 2016
Hello.
In packaging the MongoDB C++ driver with CMake, we hit a snag when a
dependency included OS X frameworks in the pkg-config information:
$ PKG_CONFIG_PATH=/usr/local/custom/mongodb/lib/pkgconfig \
pkg-config --cflags --libs libmongoc-1.0
-I/usr/local/custom/mongodb/include/libmongoc-1.0
-I/usr/local/custom/mongodb/include/libbson-1.0 -L/usr/local/custom/mongodb/lib
-lmongoc-1.0 -framework Security -framework CoreFoundation -lbson-1.0
We have a custom .cmake module that uses FindPkgConfig with a line like
this:
pkg_check_modules(LIBMONGOC REQUIRED libmongoc-1.0>=${LibMongoC_FIND_VERSION}
)
However the resulting LIBMONGOC_LIBRARIES omits the frameworks, pushing
them into LIBMONGOC_LDFLAGS_OTHER:
LIBMONGOC_LDFLAGS_OTHER:INTERNAL=-framework;Security;-
framework;CoreFoundation
We were able to recover these back into LIBMONGOC_LIBRARIES through this
round-about hack:
if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND LIBMONGOC_LDFLAGS_OTHER)
# "-framework;Security;-framework;CoreFoundation" to
# "-framework Security;-framework CoreFoundation"
string(REPLACE "-framework;" "-framework " LIBMONGOC_FRAMEWORKS
"${LIBMONGOC_LDFLAGS_OTHER}")
list(APPEND LIBMONGOC_LIBRARIES ${LIBMONGOC_FRAMEWORKS})
set(LIBMONGOC_LIBRARIES ${LIBMONGOC_LIBRARIES} CACHE INTERNAL "")
endif()
This eventually results in adding '-framework Security' etc. to
target_link_libraries(), which seems to solve the problem we had
experienced. (Though one SO post
<http://stackoverflow.com/a/28313304/11800> said this could produce parse
errors, we didn't experience any)
Extensive online searching didn't turn up a standard, well-accepted
idiomatic way to handle OS X frameworks from pkg-config. Have we missed
something? Is this a bug in FindPkgConfig not recognizing OS X framework
entries? What do people suggest?
For reference, my testing used CMake 3.6.2.
Thank you very much,
David Golden
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20161215/f0aead6c/attachment.html>
More information about the CMake
mailing list