Skip to content

Commit 4f80ee8

Browse files
committed
CDRIVER-2293 add snappy/zlib flags to config files
When we bundle zlib and/or snappy, currently the Autotools build system actually builds and installs the libraries alongside libmongoc. To link statically to libmongoc in this configuration, you need to include the full path to zlib and/or snappy in the link line. This patch adds the full path to zlib/snappy in the CMake config file. This is a temporary workaround until we fully vendor zlib/snappy in CDRIVER-2363.
1 parent 48fae84 commit 4f80ee8

File tree

4 files changed

+80
-66
lines changed

4 files changed

+80
-66
lines changed

.evergreen/config.yml

Lines changed: 57 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,24 @@ functions:
358358
cat .evergreen/kerberos.realm | $SUDO tee -a /etc/krb5.conf
359359
fi
360360
361+
"link sample program" :
362+
- command: shell.exec
363+
type: test
364+
params:
365+
working_dir: "mongoc"
366+
script: |
367+
set -o errexit
368+
# Build libmongoc with the Autotools or CMake and compile a program
369+
# that links dynamically or statically to libmongoc, using
370+
# variables from CMake's find_package command.
371+
export BUILD_SAMPLE_WITH_CMAKE=${BUILD_SAMPLE_WITH_CMAKE}
372+
export ENABLE_SSL=${ENABLE_SSL}
373+
BUILD_MONGOC_WITH_CMAKE= LINK_STATIC= sh .evergreen/link-sample-program.sh
374+
BUILD_MONGOC_WITH_CMAKE=1 LINK_STATIC= sh .evergreen/link-sample-program.sh
375+
BUILD_MONGOC_WITH_CMAKE= LINK_STATIC=1 sh .evergreen/link-sample-program.sh
376+
BUILD_MONGOC_WITH_CMAKE=1 LINK_STATIC=1 sh .evergreen/link-sample-program.sh
377+
378+
361379
pre:
362380
- func: "fetch source"
363381
- func: "windows fix"
@@ -742,21 +760,21 @@ tasks:
742760
- func: "bootstrap mongo-orchestration"
743761
vars:
744762
VERSION: "3.4"
745-
- command: shell.exec
746-
type: test
747-
params:
748-
working_dir: "mongoc"
749-
script: |
750-
set -o errexit
751-
# Build libmongoc with the Autotools or CMake and compile a program
752-
# that links dynamically or statically to libmongoc, using
753-
# variables from CMake's find_package command.
754-
export BUILD_SAMPLE_WITH_CMAKE=1
755-
export ENABLE_SSL=
756-
BUILD_MONGOC_WITH_CMAKE= LINK_STATIC= sh .evergreen/link-sample-program.sh
757-
BUILD_MONGOC_WITH_CMAKE=1 LINK_STATIC= sh .evergreen/link-sample-program.sh
758-
BUILD_MONGOC_WITH_CMAKE= LINK_STATIC=1 sh .evergreen/link-sample-program.sh
759-
BUILD_MONGOC_WITH_CMAKE=1 LINK_STATIC=1 sh .evergreen/link-sample-program.sh
763+
- func: "link sample program"
764+
vars:
765+
BUILD_SAMPLE_WITH_CMAKE: "1"
766+
767+
- name: link-with-cmake-mac
768+
depends_on:
769+
- name: "make-release-archive"
770+
variant: releng
771+
commands:
772+
- func: "bootstrap mongo-orchestration"
773+
vars:
774+
VERSION: "3.4"
775+
- func: "link sample program"
776+
vars:
777+
BUILD_SAMPLE_WITH_CMAKE: "1"
760778

761779
- name: link-with-cmake-ssl
762780
depends_on:
@@ -766,21 +784,10 @@ tasks:
766784
- func: "bootstrap mongo-orchestration"
767785
vars:
768786
VERSION: "3.4"
769-
- command: shell.exec
770-
type: test
771-
params:
772-
working_dir: "mongoc"
773-
script: |
774-
set -o errexit
775-
# Build libmongoc with the Autotools or CMake and compile a program
776-
# that links dynamically or statically to libmongoc, using
777-
# variables from CMake's find_package command.
778-
export BUILD_SAMPLE_WITH_CMAKE=1
779-
export ENABLE_SSL=1
780-
BUILD_MONGOC_WITH_CMAKE= LINK_STATIC= sh .evergreen/link-sample-program.sh
781-
BUILD_MONGOC_WITH_CMAKE=1 LINK_STATIC= sh .evergreen/link-sample-program.sh
782-
BUILD_MONGOC_WITH_CMAKE= LINK_STATIC=1 sh .evergreen/link-sample-program.sh
783-
BUILD_MONGOC_WITH_CMAKE=1 LINK_STATIC=1 sh .evergreen/link-sample-program.sh
787+
- func: "link sample program"
788+
vars:
789+
BUILD_SAMPLE_WITH_CMAKE: "1"
790+
ENABLE_SSL: "1"
784791

785792
- name: link-with-cmake-windows
786793
depends_on:
@@ -850,21 +857,17 @@ tasks:
850857
- func: "bootstrap mongo-orchestration"
851858
vars:
852859
VERSION: "3.4"
853-
- command: shell.exec
854-
type: test
855-
params:
856-
working_dir: "mongoc"
857-
script: |
858-
set -o errexit
859-
# Build libmongoc with the Autotools or CMake and compile a program
860-
# that links dynamically or statically to libmongoc, using
861-
# variables from "pkg-config".
862-
export BUILD_SAMPLE_WITH_CMAKE=
863-
export ENABLE_SSL=
864-
BUILD_MONGOC_WITH_CMAKE= LINK_STATIC= sh .evergreen/link-sample-program.sh
865-
BUILD_MONGOC_WITH_CMAKE=1 LINK_STATIC= sh .evergreen/link-sample-program.sh
866-
BUILD_MONGOC_WITH_CMAKE= LINK_STATIC=1 sh .evergreen/link-sample-program.sh
867-
BUILD_MONGOC_WITH_CMAKE=1 LINK_STATIC=1 sh .evergreen/link-sample-program.sh
860+
- func: "link sample program"
861+
862+
- name: link-with-pkg-config-mac
863+
depends_on:
864+
- name: "make-release-archive"
865+
variant: releng
866+
commands:
867+
- func: "bootstrap mongo-orchestration"
868+
vars:
869+
VERSION: "3.4"
870+
- func: "link sample program"
868871

869872
- name: link-with-pkg-config-ssl
870873
depends_on:
@@ -874,21 +877,9 @@ tasks:
874877
- func: "bootstrap mongo-orchestration"
875878
vars:
876879
VERSION: "3.4"
877-
- command: shell.exec
878-
type: test
879-
params:
880-
working_dir: "mongoc"
881-
script: |
882-
set -o errexit
883-
# Build libmongoc with the Autotools or CMake and compile a program
884-
# that links dynamically or statically to libmongoc, using
885-
# variables from "pkg-config".
886-
export BUILD_SAMPLE_WITH_CMAKE=
887-
export ENABLE_SSL=1
888-
BUILD_MONGOC_WITH_CMAKE= LINK_STATIC= sh .evergreen/link-sample-program.sh
889-
BUILD_MONGOC_WITH_CMAKE=1 LINK_STATIC= sh .evergreen/link-sample-program.sh
890-
BUILD_MONGOC_WITH_CMAKE= LINK_STATIC=1 sh .evergreen/link-sample-program.sh
891-
BUILD_MONGOC_WITH_CMAKE=1 LINK_STATIC=1 sh .evergreen/link-sample-program.sh
880+
- func: "link sample program"
881+
vars:
882+
ENABLE_SSL: "1"
892883

893884
- name: debug-compile-nosasl-nossl
894885
tags: ["debug-compile", "nosasl", "nossl"]
@@ -6570,6 +6561,9 @@ buildvariants:
65706561
- ubuntu1604-test
65716562
- ubuntu1404-build
65726563
- ubuntu1404-test
6564+
- name: "link-with-cmake-mac"
6565+
distros:
6566+
- macos-1012
65736567
- name: "link-with-cmake-windows"
65746568
distros:
65756569
- windows-64-vs2015-compile
@@ -6587,6 +6581,9 @@ buildvariants:
65876581
- ubuntu1604-test
65886582
- ubuntu1404-build
65896583
- ubuntu1404-test
6584+
- name: "link-with-pkg-config-mac"
6585+
distros:
6586+
- macos-1012
65906587

65916588

65926589
- name: clang34ubuntu

.evergreen/link-sample-program.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ set -o errexit # Exit the script with error if any of the commands fail
1111

1212
echo "BUILD_MONGOC_WITH_CMAKE=$BUILD_MONGOC_WITH_CMAKE LINK_STATIC=$LINK_STATIC BUILD_SAMPLE_WITH_CMAKE=$BUILD_SAMPLE_WITH_CMAKE"
1313

14-
CMAKE=${CMAKE:-/opt/cmake/bin/cmake}
15-
1614
if command -v gtar 2>/dev/null; then
1715
TAR=gtar
1816
else
1917
TAR=tar
2018
fi
2119

2220
if [ $(uname) = "Darwin" ]; then
21+
CMAKE=${CMAKE:-/Applications/Cmake.app/Contents/bin/cmake}
2322
SO=dylib
2423
LIB_SO=libmongoc-1.0.0.dylib
2524
LDD="otool -L"
2625
else
26+
CMAKE=${CMAKE:-/opt/cmake/bin/cmake}
2727
SO=so
2828
LIB_SO=libmongoc-1.0.so.0
2929
LDD=ldd

build/cmake/libmongoc-static-1.0-config.cmake.in

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,18 @@ list (APPEND MONGOC_STATIC_INCLUDE_DIRS ${BSON_STATIC_INCLUDE_DIRS})
3939
# find_library() to pick that up. Users can override this by configuring
4040
# MONGOC_STATIC_LIBRARY themselves.
4141
find_library(MONGOC_STATIC_LIBRARY mongoc-static-1.0 PATHS "${PACKAGE_PREFIX_DIR}/lib" NO_DEFAULT_PATH)
42-
set (MONGOC_STATIC_LIBRARIES ${MONGOC_STATIC_LIBRARY} ${BSON_STATIC_LIBRARIES})
42+
if (MSVC)
43+
set (MONGOC_STATIC_LIB_EXT "lib")
44+
else ()
45+
set (MONGOC_STATIC_LIB_EXT "a")
46+
endif ()
47+
if (@MONGOC_ZLIB_BUNDLED@)
48+
set (ZLIB_STATIC_LIBRARY "${PACKAGE_PREFIX_DIR}/lib/libz.${MONGOC_STATIC_LIB_EXT}")
49+
endif ()
50+
if (@MONGOC_SNAPPY_BUNDLED@)
51+
set (SNAPPY_STATIC_LIBRARY "${PACKAGE_PREFIX_DIR}/lib/libsnappy.${MONGOC_STATIC_LIB_EXT}")
52+
endif ()
53+
set (MONGOC_STATIC_LIBRARIES ${MONGOC_STATIC_LIBRARY} ${ZLIB_STATIC_LIBRARY} ${SNAPPY_STATIC_LIBRARY} ${BSON_STATIC_LIBRARIES})
4354

4455
# If this file is generated by the Autotools on Mac, SSL_LIBS might be
4556
# "-framework CoreFoundation -framework Security". Split into a CMake array

configure.ac

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,20 @@ AC_SUBST(MONGOC_CC)
6868
AM_INIT_AUTOMAKE([foreign subdir-objects tar-ustar])
6969
m4_include([build/autotools/SetupAutomake.m4])
7070

71-
# Substitute our dependencies into the pkg-config files.
71+
# Substitute our dependencies into the pkg-config and CMake config files.
7272
MONGOC_LIBS="${SASL_LIBS} ${SSL_LIBS} ${SHM_LIB}"
73-
if test "x$with_zlib" != "xbundled"; then
73+
if test "x$with_zlib" = "xbundled"; then
74+
AC_SUBST(MONGOC_ZLIB_BUNDLED, 1)
75+
else
7476
MONGOC_LIBS="${MONGOC_LIBS} ${ZLIB_LIBS}"
7577
fi
76-
if test "x$with_snappy" != "xbundled"; then
78+
79+
if test "x$with_snappy" = "xbundled"; then
80+
AC_SUBST(MONGOC_SNAPPY_BUNDLED, 1)
81+
else
7782
MONGOC_LIBS="${MONGOC_LIBS} ${SNAPPY_LIBS}"
7883
fi
84+
7985
AC_SUBST(MONGOC_LIBS)
8086

8187
AC_CONFIG_FILES([

0 commit comments

Comments
 (0)