Skip to content

Commit 3f9417f

Browse files
Simplify Deprecated CMake Packages as Wrappers Around Current Packages (#1384)
* Refactor of the legacy cmake-package generation. - Remove a lot of variable capture that was relied upon when generating - The _LIBRARY/_LIBRARIES variables in the legacy packages now point to the imported target of their respective packages, which will handle all other "magic variable" definitions.
1 parent 0cf69f0 commit 3f9417f

18 files changed

+169
-369
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ include (LoadVersion)
1919
file (WRITE VERSION_CURRENT "${BUILD_VERSION}")
2020
LoadVersion (VERSION_CURRENT MONGOC)
2121

22+
# Extended version attributes that CMake doesn't (yet) understand, which include
23+
# the prerelease tag. Named here to match the variables generated by project()
24+
set(mongo-c-driver_VERSION_PRERELEASE ${MONGOC_PRERELEASE_VERSION})
25+
set(mongo-c-driver_VERSION_FULL ${MONGOC_VERSION})
26+
2227
include (MongoSettings)
2328
include (MongoPlatform)
2429
include (GeneratePkgConfig)

build/cmake/LegacyPackage.cmake

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
include (CMakePackageConfigHelpers)
2+
3+
# These aren't pkg-config files, they're CMake package configuration files.
4+
function (install_package_config_file prefix)
5+
foreach (suffix "config.cmake")
6+
configure_package_config_file (
7+
${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}-${prefix}-${suffix}.in
8+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-${prefix}-${suffix}
9+
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${prefix}
10+
)
11+
12+
install (
13+
FILES
14+
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-${prefix}-${suffix}
15+
DESTINATION
16+
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${prefix}
17+
)
18+
endforeach ()
19+
write_basic_package_version_file(
20+
${PROJECT_NAME}-${prefix}-config-version.cmake
21+
VERSION "${PROJECT_VERSION}"
22+
COMPATIBILITY SameMajorVersion
23+
)
24+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-${prefix}-config-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${prefix})
25+
endfunction ()
26+
27+
install_package_config_file ("1.0")
28+
29+
if (ENABLE_STATIC)
30+
install_package_config_file ("static-1.0")
31+
endif ()

src/libbson/build/cmake/libbson-static-1.0-config-version.cmake.in renamed to build/cmake/libbson-1.0-config.cmake.in

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,18 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
set (PACKAGE_VERSION @BSON_VERSION@)
15+
if(NOT libbson-1.0_FIND_QUIETLY)
16+
message(WARNING "This CMake package is deprecated. Prefer instead to use the \"bson-1.0\" package and link to mongo::bson_shared.")
17+
endif()
1618

17-
if ("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL "@BSON_MAJOR_VERSION@")
18-
if ("${PACKAGE_FIND_VERSION_MINOR}" EQUAL "@BSON_MINOR_VERSION@")
19-
set (PACKAGE_VERSION_EXACT TRUE)
20-
elseif ("${PACKAGE_FIND_VERSION_MINOR}" LESS "@BSON_MINOR_VERSION@")
21-
set (PACKAGE_VERSION_COMPATIBLE TRUE)
22-
else ()
23-
set (PACKAGE_VERSION_UNSUITABLE TRUE)
24-
endif ()
25-
elseif (PACKAGE_FIND_VERSION)
26-
set (PACKAGE_VERSION_UNSUITABLE TRUE)
27-
endif ()
19+
set (BSON_MAJOR_VERSION @libbson_VERSION_MAJOR@)
20+
set (BSON_MINOR_VERSION @libbson_VERSION_MINOR@)
21+
set (BSON_MICRO_VERSION @libbson_VERSION_PATCH@)
22+
set (BSON_VERSION @libbson_VERSION@)
23+
set (BSON_VERSION_FULL @libbson_VERSION_FULL@)
24+
25+
include(CMakeFindDependencyMacro)
26+
find_dependency(bson-1.0)
27+
28+
set (BSON_LIBRARY mongo::bson_shared)
29+
set (BSON_LIBRARIES mongo::bson_shared)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
15+
if(NOT libbson-static-1.0_FIND_QUIETLY)
16+
message(WARNING "This CMake package is deprecated. Prefer instead to use the \"bson-1.0\" package and link to mongo::bson_static.")
17+
endif()
18+
19+
set (BSON_STATIC_MAJOR_VERSION @libbson_VERSION_MAJOR@)
20+
set (BSON_STATIC_MINOR_VERSION @libbson_VERSION_MINOR@)
21+
set (BSON_STATIC_MICRO_VERSION @libbson_VERSION_PATCH@)
22+
set (BSON_STATIC_VERSION @libbson_VERSION@)
23+
set (BSON_STATIC_VERSION_FULL @libbson_VERSION_FULL@)
24+
25+
include(CMakeFindDependencyMacro)
26+
find_dependency(bson-1.0)
27+
28+
set (BSON_STATIC_LIBRARY mongo::bson_static)
29+
set (BSON_STATIC_LIBRARIES mongo::bson_static)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
15+
if(NOT libmongoc-1.0_FIND_QUIETLY)
16+
message(WARNING "This CMake package is deprecated. Prefer instead to use the \"mongoc-1.0\" package and link to mongo::mongoc_shared.")
17+
endif()
18+
19+
set (MONGOC_MAJOR_VERSION @libmongoc_VERSION_MAJOR@)
20+
set (MONGOC_MINOR_VERSION @libmongoc_VERSION_MINOR@)
21+
set (MONGOC_MICRO_VERSION @libmongoc_VERSION_PATCH@)
22+
set (MONGOC_VERSION @libmongoc_VERSION@)
23+
set (MONGOC_VERSION_FULL @libmongoc_VERSION_FULL@)
24+
25+
include(CMakeFindDependencyMacro)
26+
find_dependency (mongoc-1.0)
27+
28+
set(MONGOC_LIBRARY mongo::mongoc_shared)
29+
set(MONGOC_LIBRARIES mongo::mongoc_shared)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
15+
if(NOT libmongoc-static-1.0_FIND_QUIETLY)
16+
message(WARNING "This CMake package is deprecated. Prefer instead to use the \"mongoc-1.0\" package and link to mongo::mongoc_static.")
17+
endif()
18+
19+
set (MONGOC_STATIC_MAJOR_VERSION @libmongoc_VERSION_MAJOR@)
20+
set (MONGOC_STATIC_MINOR_VERSION @libmongoc_VERSION_MINOR@)
21+
set (MONGOC_STATIC_MICRO_VERSION @libmongoc_VERSION_PATCH@)
22+
set (MONGOC_STATIC_VERSION @libmongoc_VERSION@)
23+
set (MONGOC_STATIC_VERSION_FULL @libmongoc_VERSION_FULL@)
24+
25+
include(CMakeFindDependencyMacro)
26+
find_dependency (mongoc-1.0)
27+
28+
set(MONGOC_STATIC_LIBRARY mongo::mongoc_static)
29+
set(MONGOC_STATIC_LIBRARIES mongo::mongoc_static)

src/libbson/CMakeLists.txt

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
cmake_minimum_required (VERSION 3.15)
22

3-
project (libbson C)
3+
project (libbson
4+
LANGUAGES C
5+
# Inherit the version from mongo-c-driver
6+
VERSION "${PROJECT_VERSION}"
7+
DESCRIPTION "The libbson BSON serialization library"
8+
)
9+
10+
# These values are inherited from the mongo-c-driver parent. These are named as to
11+
# match the CMake variables generated by project().
12+
set(libbson_VERSION_PRERELEASE ${mongo-c-driver_VERSION_PRERELEASE})
13+
set(libbson_VERSION_FULL ${mongo-c-driver_VERSION_FULL})
414

515
# In the future we may need to check whether static dependencies are
616
# available. For now, AUTO means ON.
@@ -23,18 +33,11 @@ include (InstallRequiredSystemLibraries)
2333

2434
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/build/cmake)
2535

26-
# Set BSON_MAJOR_VERSION, BSON_MINOR_VERSION, etc.
27-
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/../../build/cmake)
28-
include (LoadVersion)
29-
LoadVersion (${PROJECT_SOURCE_DIR}/../../VERSION_CURRENT BSON)
30-
31-
message (STATUS "lib${BSON_OUTPUT_BASENAME} version (from VERSION_CURRENT file): ${BSON_VERSION}")
36+
set(CMAKE_C_VISIBILITY_PRESET hidden)
37+
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
3238

3339
set (BSON_API_VERSION 1.0)
3440

35-
set (CPACK_PACKAGE_VERSION_MAJOR ${BSON_MAJOR_VERSION})
36-
set (CPACK_PACKAGE_VERSION_MINOR ${BSON_MINOR_VERSION})
37-
3841
include (CPack)
3942
TEST_BIG_ENDIAN (BSON_BIG_ENDIAN)
4043

@@ -267,9 +270,6 @@ endif ()
267270
if (WIN32)
268271
# gethostbyname
269272
target_link_libraries (bson_shared PRIVATE ws2_32)
270-
# Can't find_library () system dependencies
271-
# must be handled specially since we can't resolve them
272-
set (BSON_SYSTEM_LIBRARIES ${BSON_SYSTEM_LIBRARIES} ws2_32)
273273
endif ()
274274

275275
if (MONGOC_ENABLE_STATIC_BUILD)
@@ -367,11 +367,6 @@ install (
367367
INCLUDES DESTINATION ${BSON_HEADER_INSTALL_DIR}
368368
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR}
369369
)
370-
set_target_properties(${TARGETS_TO_INSTALL} PROPERTIES
371-
pkg_config_NAME libbson
372-
pkg_config_DESCRIPTION "The libbson BSON serialization library."
373-
pkg_config_VERSION "${BSON_VERSION}"
374-
)
375370
set_property(TARGET ${TARGETS_TO_INSTALL} APPEND PROPERTY pkg_config_INCLUDE_DIRECTORIES "${BSON_HEADER_INSTALL_DIR}")
376371

377372
install (
@@ -390,22 +385,7 @@ if (ENABLE_APPLE_FRAMEWORK)
390385
)
391386
endif ()
392387

393-
set (LIBBSON_LIBRARIES "")
394-
foreach (_lib ${BSON_LIBRARIES})
395-
if (_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
396-
set (LIBBSON_LIBRARIES "${LIBBSON_LIBRARIES} ${_lib}")
397-
else ()
398-
set (LIBBSON_LIBRARIES "${LIBBSON_LIBRARIES} -l${_lib}")
399-
endif ()
400-
endforeach ()
401-
# System dependencies don't match the above regexs, but also don't want the -l
402-
foreach (_lib ${BSON_SYSTEM_LIBRARIES})
403-
set (LIBBSON_LIBRARIES "${LIBBSON_LIBRARIES} ${_lib}")
404-
endforeach ()
405-
406388
include (CMakePackageConfigHelpers)
407-
set (INCLUDE_INSTALL_DIRS "${BSON_HEADER_INSTALL_DIR}")
408-
set (LIBRARY_INSTALL_DIRS ${CMAKE_INSTALL_LIBDIR})
409389

410390
write_basic_package_version_file (
411391
"${CMAKE_CURRENT_BINARY_DIR}/bson/bson-${BSON_API_VERSION}-config-version.cmake"
@@ -439,7 +419,7 @@ install (
439419
Devel
440420
)
441421

442-
include (build/cmake/BSONPackage.cmake)
422+
include (LegacyPackage)
443423

444424
if (ENABLE_MAN_PAGES STREQUAL ON OR ENABLE_HTML_DOCS STREQUAL ON)
445425
find_package (Sphinx REQUIRED)

src/libbson/build/cmake/.gitignore

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/libbson/build/cmake/BSONPackage.cmake

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/libbson/build/cmake/libbson-1.0-config-version.cmake.in

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/libbson/build/cmake/libbson-1.0-config.cmake.in

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/libbson/build/cmake/libbson-static-1.0-config.cmake.in

Lines changed: 0 additions & 41 deletions
This file was deleted.

0 commit comments

Comments
 (0)