1# Copyright 2017 MongoDB Inc.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15set (MONGOC_MAJOR_VERSION @MONGOC_MAJOR_VERSION@)
16set (MONGOC_MINOR_VERSION @MONGOC_MINOR_VERSION@)
17set (MONGOC_MICRO_VERSION @MONGOC_MICRO_VERSION@)
18set (MONGOC_VERSION @MONGOC_VERSION@)
19
20find_package (libbson-1.0 "@MONGOC_MAJOR_VERSION@.@MONGOC_MINOR_VERSION@" REQUIRED)
21
22# In a pure-CMake project this is inserted by configure_package_config_file(),
23# but we want to be able to build this file the same from the Autotools, so
24# let's manually insert this code.
25get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
26
27macro(set_and_check _var _file)
28  set(${_var} "${_file}")
29  if(NOT EXISTS "${_file}")
30    message(FATAL_ERROR "File or directory ${_file} referenced by variable ${_var} does not exist !")
31  endif()
32endmacro()
33
34set_and_check (MONGOC_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/libmongoc-1.0")
35list (APPEND MONGOC_INCLUDE_DIRS ${BSON_INCLUDE_DIRS})
36
37# We want to provide an absolute path to the library and we know the
38# directory and the base name, but not the suffix, so we use CMake's
39# find_library() to pick that up.  Users can override this by configuring
40# MONGOC_LIBRARY themselves.
41find_library(MONGOC_LIBRARY mongoc-1.0 PATHS "${PACKAGE_PREFIX_DIR}/lib" NO_DEFAULT_PATH)
42set (MONGOC_LIBRARIES ${MONGOC_LIBRARY} ${BSON_LIBRARIES})
43
44# If this file is generated by the Autotools on Mac, SSL_LIBS might be
45# "-framework CoreFoundation -framework Security". Split into a CMake array
46# like "-framework CoreFoundation;-framework Security".
47set (IS_FRAMEWORK_VAR 0)
48foreach (LIB @SASL_LIBS@ @SSL_LIBS@ @SHM_LIB@)
49   if (LIB STREQUAL "-framework")
50      set (IS_FRAMEWORK_VAR 1)
51      continue ()
52   elseif (IS_FRAMEWORK_VAR)
53      list (APPEND MONGOC_LIBRARIES "-framework ${LIB}")
54      set (IS_FRAMEWORK_VAR 0)
55   else ()
56      list (APPEND MONGOC_LIBRARIES ${LIB})
57   endif ()
58endforeach ()
59
60set (MONGOC_DEFINITIONS ${BSON_DEFINITIONS})
61