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
--
Powered by www.kitware.com
Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
Kitware offers various services to support the CMake community. For more
information on each offering, please visit:
CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake