Permalink
Browse files

CDRIVER-2083 Update .cmake variable naming scheme

This commit updates the libbson submodule commit point.

libbson already publishes two .cmake files, one for shared builds and one
for static builds.  The updated libbson commit publishes variables under
separate namespaces, BSON_* and BSON_STATIC_*.

This commit uses those .cmake files directly instead of our own FindBSON
config file and uses the new variable names where appropriate.

This commit also changes the generated .cmake files for libmongoc to
follow the same MONGOC_* and MONGOC_STATIC_* naming convention for
downstream users.

mongocxx (and maybe the PHP driver) will need a corresponding update.
1 parent ea6d8ee commit 5bb1e4b61de99a432cd39111c841c29ac0cc621d @xdg xdg committed Apr 14, 2017
@@ -14,7 +14,7 @@ cd src\libbson
%CMAKE_MAKE_PROGRAM% install
cd ..\..
-%CMAKE% -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=%CMAKE_MAKE_PROGRAM% -DCMAKE_PREFIX_PATH=%INSTALL_DIR% %CONFIGURE_FLAGS%
+%CMAKE% -G "MinGW Makefiles" -DCMAKE_MAKE_PROGRAM=%CMAKE_MAKE_PROGRAM% -DCMAKE_PREFIX_PATH=%INSTALL_DIR%\lib\cmake %CONFIGURE_FLAGS%
%CMAKE_MAKE_PROGRAM%
%CMAKE_MAKE_PROGRAM% install
@@ -125,7 +125,7 @@ cd src/libbson
"$BUILD" $BUILD_FLAGS INSTALL.vcxproj
cd ../..
-"$CMAKE" -G "$CC" "-DCMAKE_PREFIX_PATH=${INSTALL_DIR}" $CONFIGURE_FLAGS
+"$CMAKE" -G "$CC" "-DCMAKE_PREFIX_PATH=${INSTALL_DIR}/lib/cmake" $CONFIGURE_FLAGS
"$BUILD" $BUILD_FLAGS ALL_BUILD.vcxproj
"$BUILD" $BUILD_FLAGS INSTALL.vcxproj
@@ -36,9 +36,9 @@ msbuild.exe INSTALL.vcxproj
cd ..\..
rem Build libmongoc
if "%ENABLE_SSL%"=="1" (
- %CMAKE% -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DENABLE_SSL=WINDOWS .
+ %CMAKE% -G "Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH=%INSTALL_DIR%\lib\cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DENABLE_SSL=WINDOWS .
) else (
- %CMAKE% -G "Visual Studio 14 2015 Win64" -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DENABLE_SSL=OFF .
+ %CMAKE% -G "Visual Studio 14 2015 Win64" -DCMAKE_PREFIX_PATH=%INSTALL_DIR%\lib\cmake -DCMAKE_INSTALL_PREFIX=%INSTALL_DIR% -DENABLE_SSL=OFF .
)
msbuild.exe /m ALL_BUILD.vcxproj
@@ -59,7 +59,7 @@ if [ "$BUILD_MONGOC_WITH_CMAKE" ]; then
cd ../..
# Our CMake build system always installs both dynamic and static libmongoc.
- $CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR $SSL_CMAKE_OPTION .
+ $CMAKE -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR -DCMAKE_PREFIX_PATH=$INSTALL_DIR/lib/cmake $SSL_CMAKE_OPTION .
make
make install
EXPECT_STATIC=1
View
@@ -33,7 +33,28 @@ if (NOT ${MONGOC_VERSION} STREQUAL ${MONGOC_RELEASED_VERSION})
message("Previous release (from VERSION_RELEASED file): ${MONGOC_RELEASED_VERSION}")
endif()
-include(FindBSON REQUIRED)
+# The input variable BSON_ROOT_DIR is respected for backwards compatibility,
+# but you should use the standard CMAKE_PREFIX_PATH instead.
+message (STATUS "Searching for libbson CMake packages")
+find_package (libbson-1.0
+ "${MONGOC_MAJOR_VERSION}.${MONGOC_MINOR_VERSION}.${MONGOC_MICRO_VERSION}"
+ HINTS
+ ${BSON_ROOT_DIR}
+ REQUIRED)
+
+find_package (libbson-static-1.0
+ "${MONGOC_MAJOR_VERSION}.${MONGOC_MINOR_VERSION}.${MONGOC_MICRO_VERSION}"
+ HINTS
+ ${BSON_ROOT_DIR}
+ REQUIRED)
+
+message ("-- libbson found version \"${BSON_VERSION}\"")
+message ("-- libbson include path \"${BSON_INCLUDE_DIRS}\"")
+message ("-- libbson libraries \"${BSON_LIBRARIES}\"")
+
+message ("-- libbson-static found version \"${BSON_STATIC_VERSION}\"")
+message ("-- libbson-static include path \"${BSON_STATIC_INCLUDE_DIRS}\"")
+message ("-- libbson-static libraries \"${BSON_STATIC_LIBRARIES}\"")
if (NOT (ENABLE_SSL STREQUAL DARWIN
OR ENABLE_SSL STREQUAL WINDOWS
@@ -290,13 +311,9 @@ configure_file (
include_directories("${PROJECT_BINARY_DIR}/src/mongoc")
include_directories("${SOURCE_DIR}/src/mongoc")
-include_directories (${BSON_INCLUDE_DIRS})
-link_directories (${BSON_LIBRARY_DIRS})
-
-set(LIBS ${LIBS} ${BSON_LIBRARIES})
if (UNIX AND NOT APPLE)
- set(LIBS ${LIBS} rt)
+ set(SHM_LIB -lrt)
endif()
if (APPLE)
@@ -483,7 +500,7 @@ if (MONGOC_ENABLE_SASL)
message (STATUS "Compiling against Windows SSPI")
set (SOURCES ${SOURCES} ${SOURCE_DIR}/src/mongoc/mongoc-cluster-sspi.c)
set (SOURCES ${SOURCES} ${SOURCE_DIR}/src/mongoc/mongoc-sspi.c)
- set (LIBS ${LIBS} secur32.lib crypt32.lib Shlwapi.lib)
+ set (SASL_LIBS ${SASL_LIBS} secur32.lib crypt32.lib Shlwapi.lib)
endif()
endif()
@@ -492,13 +509,15 @@ add_library(mongoc_static STATIC ${SOURCES} ${HEADERS})
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
-set (LIBS ${LIBS} ${SASL_LIBS} ${SSL_LIBS} ${SHM_LIB})
+set (LIBS ${SASL_LIBS} ${SSL_LIBS} ${SHM_LIB})
-target_link_libraries(mongoc_shared ${LIBS})
-target_link_libraries(mongoc_static ${LIBS})
+target_link_libraries (mongoc_shared ${LIBS} ${BSON_LIBRARIES})
+target_include_directories (mongoc_shared PUBLIC ${BSON_INCLUDE_DIRS})
+target_compile_definitions (mongoc_shared PUBLIC MONGOC_COMPILATION ${BSON_DEFINITIONS})
-set_target_properties(mongoc_shared PROPERTIES COMPILE_DEFINITIONS "MONGOC_COMPILATION;BSON_COMPILATION")
-set_target_properties(mongoc_static PROPERTIES COMPILE_DEFINITIONS "MONGOC_COMPILATION;BSON_COMPILATION")
+target_link_libraries (mongoc_static ${LIBS} ${BSON_STATIC_LIBRARIES})
+target_include_directories (mongoc_static PUBLIC ${BSON_STATIC_INCLUDE_DIRS})
+target_compile_definitions (mongoc_static PUBLIC MONGOC_COMPILATION MONGOC_STATIC ${BSON_STATIC_DEFINITIONS})
# CMake wants to make different symlinks than the Autotools, see
# https://cmake.org/pipermail/cmake/2007-September/016501.html
@@ -519,7 +538,7 @@ function(mongoc_add_test test use_shared)
if (${use_shared})
target_link_libraries(${test} mongoc_shared)
else()
- set_target_properties(${test} PROPERTIES COMPILE_DEFINITIONS "MONGOC_COMPILATION;BSON_COMPILATION")
+ target_compile_definitions(${test} PUBLIC "MONGOC_COMPILATION")
target_link_libraries(${test} mongoc_static)
endif()
if(WIN32)
@@ -534,7 +553,6 @@ function(mongoc_add_example example use_shared)
if (${use_shared})
target_link_libraries(${example} mongoc_shared)
else()
- set_target_properties(${example} PROPERTIES COMPILE_DEFINITIONS "MONGOC_COMPILATION;BSON_COMPILATION")
target_link_libraries(${example} mongoc_static)
endif()
if(WIN32)
View
2 NEWS
@@ -1,6 +1,8 @@
Next Release
============
+ * Now requires the use of CMake config files for libbson to build libmongoc
+ with CMake
* New function mongoc_uri_set_auth_mechanism to update the authentication
mechanism of a mongoc_uri_t after it is created from a string.
* New function mongoc_bulk_operation_insert_with_opts provides immediate
View
@@ -1,80 +0,0 @@
-# Read-Only variables:
-# BSON_FOUND - system has the BSON library
-# BSON_INCLUDE_DIRS - the BSON include directory
-# BSON_LIBRARIES - The libraries needed to use BSON
-# BSON_VERSION - This is set to $major.$minor.$revision$path (eg. 0.4.1)
-
-
-# The input variable BSON_ROOT_DIR is respected for backwards compatibility,
-# but you should use the standard CMAKE_PREFIX_PATH instead.
-message (STATUS "Searching for libbson CMake package")
-
-find_package (libbson-1.0
- "${MONGOC_MAJOR_VERSION}.${MONGOC_MINOR_VERSION}.${MONGOC_MICRO_VERSION}"
- HINTS
- ${BSON_ROOT_DIR})
-
-if (NOT BSON_VERSION)
- find_package(PkgConfig QUIET)
- if (PKG_CONFIG_FOUND)
- pkg_search_module (BSON libbson-1.0)
- else ()
- # No CMake package installed for libbson - was it installed with the Autotools
- # or a system package manager?
- message ("Can't find libbson-config.cmake, nor pkg-config, searching for libbson-1.0/bson.h")
- find_path(BSON_INCLUDE_DIR
- NAMES
- libbson-1.0/bson.h
- HINTS
- ${BSON_ROOT_DIR}
- PATH_SUFFIXES
- include
- )
-
- if (NOT BSON_INCLUDE_DIR)
- message (FATAL_ERROR "Could not find libbson-1.0/bson.h")
- endif ()
-
- set (BSON_INCLUDE_DIRS "${BSON_INCLUDE_DIR}/libbson-1.0")
-
- file (STRINGS "${BSON_INCLUDE_DIR}/bson-version.h" bson_version_s
- REGEX "^#define[\t ]+BSON_VERSION_S[\t ]+\"\(.*)\"$")
-
- string (REGEX REPLACE "^#define[\t ]+BSON_VERSION_S[\t ]+\"\(.*)\"$"
- "\\1" BSON_VERSION "${bson_version_s}")
-
- find_library(BSON_LIBRARIES
- NAMES
- "bson-1.0"
- HINTS
- ${BSON_ROOT_DIR}
- PATH_SUFFIXES
- bin
- lib
- )
- endif ()
-endif ()
-
-include(FindPackageHandleStandardArgs)
-
-if (BSON_VERSION)
- set (BSON "${BSON_LIBRARIES}")
- message ("-- Found version \"${BSON_VERSION}\"")
- message ("-- Include path \"${BSON_INCLUDE_DIRS}\"")
- message ("-- Library path \"${BSON_LIBRARY_DIRS}\"")
-else ()
- find_package_handle_standard_args(BSON "Could NOT find BSON"
- BSON_VERSION
- BSON_LIBRARIES
- BSON_INCLUDE_DIRS
- )
-endif ()
-
-mark_as_advanced(BSON_INCLUDE_DIRS BSON_LIBRARIES)
-
-if(WIN32)
- set (BSON_LIBRARIES ${BSON} ws2_32)
-else()
- find_package (Threads REQUIRED)
- set (BSON_LIBRARIES ${BSON} ${CMAKE_THREAD_LIBS_INIT})
-endif()
View
@@ -1,6 +1,5 @@
EXTRA_DIST += \
build/cmake/FindSASL2.cmake \
- build/cmake/FindBSON.cmake \
build/cmake/MongoCPackage.cmake \
build/cmake/libmongoc-1.0-config.cmake.in \
build/cmake/libmongoc-1.0-config-version.cmake.in \
@@ -19,7 +19,27 @@ set (MONGOC_VERSION @MONGOC_VERSION@)
find_package (libbson-1.0 "@MONGOC_MAJOR_VERSION@.@MONGOC_MINOR_VERSION@" REQUIRED)
-set (MONGOC_LIBRARIES mongoc-1.0 ${BSON_LIBRARIES})
+# In a pure-CMake project this is inserted by configure_package_config_file(),
+# but we want to be able to build this file the same from the Autotools, so
+# let's manually insert this code.
+get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
+
+macro(set_and_check _var _file)
+ set(${_var} "${_file}")
+ if(NOT EXISTS "${_file}")
+ message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
+ endif()
+endmacro()
+
+set_and_check (MONGOC_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/libmongoc-1.0")
+list (APPEND MONGOC_INCLUDE_DIRS ${BSON_INCLUDE_DIRS})
+
+# We want to provide an absolute path to the library and we know the
+# directory and the base name, but not the suffix, so we use CMake's
+# find_library() to pick that up. Users can override this by configuring
+# MONGOC_LIBRARY themselves.
+find_library(MONGOC_LIBRARY mongoc-1.0 PATHS "${PACKAGE_PREFIX_DIR}/lib" NO_DEFAULT_PATH)
+set (MONGOC_LIBRARIES ${MONGOC_LIBRARY} ${BSON_LIBRARIES})
# If this file is generated by the Autotools on Mac, SSL_LIBS might be
# "-framework CoreFoundation -framework Security". Split into a CMake array
@@ -37,20 +57,4 @@ foreach (LIB @SASL_LIBS@ @SSL_LIBS@ @SHM_LIB@)
endif ()
endforeach ()
-# In a pure-CMake project this is inserted by configure_package_config_file(),
-# but we want to be able to build this file the same from the Autotools, so
-# let's manually insert this code.
-get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
-
-macro(set_and_check _var _file)
- set(${_var} "${_file}")
- if(NOT EXISTS "${_file}")
- message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
- endif()
-endmacro()
-
-set_and_check (MONGOC_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/libmongoc-1.0")
-set (MONGOC_INCLUDE_DIRS ${MONGOC_INCLUDE_DIRS} ${BSON_INCLUDE_DIRS})
-
-set_and_check (MONGOC_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/lib")
-set (MONGOC_LIBRARY_DIRS ${MONGOC_LIBRARY_DIRS} ${BSON_LIBRARY_DIRS})
+set (MONGOC_DEFINITIONS ${BSON_DEFINITIONS})
@@ -12,14 +12,34 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-set (MONGOC_MAJOR_VERSION @MONGOC_MAJOR_VERSION@)
-set (MONGOC_MINOR_VERSION @MONGOC_MINOR_VERSION@)
-set (MONGOC_MICRO_VERSION @MONGOC_MICRO_VERSION@)
-set (MONGOC_VERSION @MONGOC_VERSION@)
+set (MONGOC_STATIC_MAJOR_VERSION @MONGOC_MAJOR_VERSION@)
+set (MONGOC_STATIC_MINOR_VERSION @MONGOC_MINOR_VERSION@)
+set (MONGOC_STATIC_MICRO_VERSION @MONGOC_MICRO_VERSION@)
+set (MONGOC_STATIC_VERSION @MONGOC_VERSION@)
find_package (libbson-static-1.0 "@MONGOC_MAJOR_VERSION@.@MONGOC_MINOR_VERSION@" REQUIRED)
-set (MONGOC_LIBRARIES mongoc-static-1.0 ${BSON_LIBRARIES})
+# In a pure-CMake project this is inserted by configure_package_config_file(),
+# but we want to be able to build this file the same from the Autotools, so
+# let's manually insert this code.
+get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
+
+macro(set_and_check _var _file)
+ set(${_var} "${_file}")
+ if(NOT EXISTS "${_file}")
+ message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
+ endif()
+endmacro()
+
+set_and_check (MONGOC_STATIC_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/libmongoc-1.0")
+list (APPEND MONGOC_STATIC_INCLUDE_DIRS ${BSON_STATIC_INCLUDE_DIRS})
+
+# We want to provide an absolute path to the library and we know the
+# directory and the base name, but not the suffix, so we use CMake's
+# find_library() to pick that up. Users can override this by configuring
+# MONGOC_STATIC_LIBRARY themselves.
+find_library(MONGOC_STATIC_LIBRARY mongoc-static-1.0 PATHS "${PACKAGE_PREFIX_DIR}/lib" NO_DEFAULT_PATH)
+set (MONGOC_STATIC_LIBRARIES ${MONGOC_STATIC_LIBRARY} ${BSON_STATIC_LIBRARIES})
# If this file is generated by the Autotools on Mac, SSL_LIBS might be
# "-framework CoreFoundation -framework Security". Split into a CMake array
@@ -30,28 +50,11 @@ foreach (LIB @SASL_LIBS@ @SSL_LIBS@ @SHM_LIB@)
set (IS_FRAMEWORK_VAR 1)
continue ()
elseif (IS_FRAMEWORK_VAR)
- list (APPEND MONGOC_LIBRARIES "-framework ${LIB}")
+ list (APPEND MONGOC_STATIC_LIBRARIES "-framework ${LIB}")
set (IS_FRAMEWORK_VAR 0)
else ()
- list (APPEND MONGOC_LIBRARIES ${LIB})
+ list (APPEND MONGOC_STATIC_LIBRARIES ${LIB})
endif ()
endforeach ()
-# In a pure-CMake project this is inserted by configure_package_config_file(),
-# but we want to be able to build this file the same from the Autotools, so
-# let's manually insert this code.
-get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
-
-macro(set_and_check _var _file)
- set(${_var} "${_file}")
- if(NOT EXISTS "${_file}")
- message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
- endif()
-endmacro()
-
-set_and_check (MONGOC_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/libmongoc-1.0")
-set (MONGOC_INCLUDE_DIRS ${MONGOC_INCLUDE_DIRS} ${BSON_INCLUDE_DIRS})
-
-set_and_check (MONGOC_LIBRARY_DIRS "${PACKAGE_PREFIX_DIR}/lib")
-set (MONGOC_LIBRARY_DIRS ${MONGOC_LIBRARY_DIRS} ${BSON_LIBRARY_DIRS})
-add_definitions (-DMONGOC_STATIC)
+set (MONGOC_STATIC_DEFINITIONS MONGOC_STATIC ${BSON_STATIC_DEFINITIONS})
@@ -32,13 +32,10 @@ find_package (libmongoc-1.0 1.7 REQUIRED)
message ("-- mongoc found version \"${MONGOC_VERSION}\"")
message ("-- mongoc include path \"${MONGOC_INCLUDE_DIRS}\"")
-message ("-- mongoc library path \"${MONGOC_LIBRARY_DIRS}\"")
-
-
-link_directories (${MONGOC_LIBRARY_DIRS})
-include_directories (${MONGOC_INCLUDE_DIRS})
+message ("-- mongoc libraries \"${MONGOC_LIBRARIES}\"")
# The "hello_mongoc.c" sample program is shared among four tests.
add_executable (hello_mongoc ../../hello_mongoc.c)
target_include_directories (hello_mongoc PRIVATE "${MONGOC_INCLUDE_DIRS}")
target_link_libraries (hello_mongoc PRIVATE "${MONGOC_LIBRARIES}")
+target_compile_definitions (hello_mongoc PRIVATE "${MONGOC_DEFINITIONS}")
@@ -30,15 +30,12 @@ project (hello_mongoc LANGUAGES C)
# Specify the minimum version you require.
find_package (libmongoc-static-1.0 1.7 REQUIRED)
-message ("-- mongoc found version \"${MONGOC_VERSION}\"")
-message ("-- mongoc include path \"${MONGOC_INCLUDE_DIRS}\"")
-message ("-- mongoc library path \"${MONGOC_LIBRARY_DIRS}\"")
-
-
-link_directories (${MONGOC_LIBRARY_DIRS})
-include_directories (${MONGOC_INCLUDE_DIRS})
+message ("-- mongoc found version \"${MONGOC_STATIC_VERSION}\"")
+message ("-- mongoc include path \"${MONGOC_STATIC_INCLUDE_DIRS}\"")
+message ("-- mongoc libraries \"${MONGOC_STATIC_LIBRARIES}\"")
# The "hello_mongoc.c" sample program is shared among four tests.
add_executable (hello_mongoc ../../hello_mongoc.c)
-target_include_directories (hello_mongoc PRIVATE "${MONGOC_INCLUDE_DIRS}")
-target_link_libraries (hello_mongoc PRIVATE "${MONGOC_LIBRARIES}")
+target_include_directories (hello_mongoc PRIVATE "${MONGOC_STATIC_INCLUDE_DIRS}")
+target_link_libraries (hello_mongoc PRIVATE "${MONGOC_STATIC_LIBRARIES}")
+target_compile_definitions (hello_mongoc PRIVATE "${MONGOC_STATIC_DEFINITIONS}")

0 comments on commit 5bb1e4b

Please sign in to comment.