Skip to content

Simplify Deprecated CMake Packages as Wrappers Around Current Packages #1384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 18, 2023
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ include (LoadVersion)
file (WRITE VERSION_CURRENT "${BUILD_VERSION}")
LoadVersion (VERSION_CURRENT MONGOC)

# Extended version attributes that CMake doesn't (yet) understand, which include
# the prerelease tag. Named here to match the variables generated by project()
set(mongo-c-driver_VERSION_PRERELEASE ${MONGOC_PRERELEASE_VERSION})
set(mongo-c-driver_VERSION_FULL ${MONGOC_VERSION})

include (MongoSettings)
include (MongoPlatform)
include (GeneratePkgConfig)
Expand Down
31 changes: 31 additions & 0 deletions build/cmake/LegacyPackage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
include (CMakePackageConfigHelpers)

# These aren't pkg-config files, they're CMake package configuration files.
function (install_package_config_file prefix)
foreach (suffix "config.cmake")
configure_package_config_file (
${CMAKE_CURRENT_LIST_DIR}/${PROJECT_NAME}-${prefix}-${suffix}.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-${prefix}-${suffix}
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${prefix}
)

install (
FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-${prefix}-${suffix}
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${prefix}
)
endforeach ()
write_basic_package_version_file(
${PROJECT_NAME}-${prefix}-config-version.cmake
VERSION "${PROJECT_VERSION}"
COMPATIBILITY SameMajorVersion
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-${prefix}-config-version.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}-${prefix})
endfunction ()

install_package_config_file ("1.0")

if (ENABLE_STATIC)
install_package_config_file ("static-1.0")
endif ()
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.

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

if ("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL "@BSON_MAJOR_VERSION@")
if ("${PACKAGE_FIND_VERSION_MINOR}" EQUAL "@BSON_MINOR_VERSION@")
set (PACKAGE_VERSION_EXACT TRUE)
elseif ("${PACKAGE_FIND_VERSION_MINOR}" LESS "@BSON_MINOR_VERSION@")
set (PACKAGE_VERSION_COMPATIBLE TRUE)
else ()
set (PACKAGE_VERSION_UNSUITABLE TRUE)
endif ()
elseif (PACKAGE_FIND_VERSION)
set (PACKAGE_VERSION_UNSUITABLE TRUE)
endif ()
set (BSON_MAJOR_VERSION @libbson_VERSION_MAJOR@)
set (BSON_MINOR_VERSION @libbson_VERSION_MINOR@)
set (BSON_MICRO_VERSION @libbson_VERSION_PATCH@)
set (BSON_VERSION @libbson_VERSION@)
set (BSON_VERSION_FULL @libbson_VERSION_FULL@)

include(CMakeFindDependencyMacro)
find_dependency(bson-1.0)

set (BSON_LIBRARY mongo::bson_shared)
set (BSON_LIBRARIES mongo::bson_shared)
29 changes: 29 additions & 0 deletions build/cmake/libbson-static-1.0-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2017 MongoDB Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if(NOT libbson-static-1.0_FIND_QUIETLY)
message(WARNING "This CMake package is deprecated. Prefer instead to use the \"bson-1.0\" package and link to mongo::bson_static.")
endif()

set (BSON_STATIC_MAJOR_VERSION @libbson_VERSION_MAJOR@)
set (BSON_STATIC_MINOR_VERSION @libbson_VERSION_MINOR@)
set (BSON_STATIC_MICRO_VERSION @libbson_VERSION_PATCH@)
set (BSON_STATIC_VERSION @libbson_VERSION@)
set (BSON_STATIC_VERSION_FULL @libbson_VERSION_FULL@)

include(CMakeFindDependencyMacro)
find_dependency(bson-1.0)

set (BSON_STATIC_LIBRARY mongo::bson_static)
set (BSON_STATIC_LIBRARIES mongo::bson_static)
29 changes: 29 additions & 0 deletions build/cmake/libmongoc-1.0-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2017 MongoDB Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if(NOT libmongoc-1.0_FIND_QUIETLY)
message(WARNING "This CMake package is deprecated. Prefer instead to use the \"mongoc-1.0\" package and link to mongo::mongoc_shared.")
endif()

set (MONGOC_MAJOR_VERSION @libmongoc_VERSION_MAJOR@)
set (MONGOC_MINOR_VERSION @libmongoc_VERSION_MINOR@)
set (MONGOC_MICRO_VERSION @libmongoc_VERSION_PATCH@)
set (MONGOC_VERSION @libmongoc_VERSION@)
set (MONGOC_VERSION_FULL @libmongoc_VERSION_FULL@)

include(CMakeFindDependencyMacro)
find_dependency (mongoc-1.0)

set(MONGOC_LIBRARY mongo::mongoc_shared)
set(MONGOC_LIBRARIES mongo::mongoc_shared)
29 changes: 29 additions & 0 deletions build/cmake/libmongoc-static-1.0-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright 2017 MongoDB Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

if(NOT libmongoc-static-1.0_FIND_QUIETLY)
message(WARNING "This CMake package is deprecated. Prefer instead to use the \"mongoc-1.0\" package and link to mongo::mongoc_static.")
endif()

set (MONGOC_STATIC_MAJOR_VERSION @libmongoc_VERSION_MAJOR@)
set (MONGOC_STATIC_MINOR_VERSION @libmongoc_VERSION_MINOR@)
set (MONGOC_STATIC_MICRO_VERSION @libmongoc_VERSION_PATCH@)
set (MONGOC_STATIC_VERSION @libmongoc_VERSION@)
set (MONGOC_STATIC_VERSION_FULL @libmongoc_VERSION_FULL@)

include(CMakeFindDependencyMacro)
find_dependency (mongoc-1.0)

set(MONGOC_STATIC_LIBRARY mongo::mongoc_static)
set(MONGOC_STATIC_LIBRARIES mongo::mongoc_static)
48 changes: 14 additions & 34 deletions src/libbson/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
cmake_minimum_required (VERSION 3.15)

project (libbson C)
project (libbson
LANGUAGES C
# Inherit the version from mongo-c-driver
VERSION "${PROJECT_VERSION}"
DESCRIPTION "The libbson BSON serialization library"
)

# These values are inherited from the mongo-c-driver parent. These are named as to
# match the CMake variables generated by project().
set(libbson_VERSION_PRERELEASE ${mongo-c-driver_VERSION_PRERELEASE})
set(libbson_VERSION_FULL ${mongo-c-driver_VERSION_FULL})

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

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

# Set BSON_MAJOR_VERSION, BSON_MINOR_VERSION, etc.
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/../../build/cmake)
include (LoadVersion)
LoadVersion (${PROJECT_SOURCE_DIR}/../../VERSION_CURRENT BSON)

message (STATUS "lib${BSON_OUTPUT_BASENAME} version (from VERSION_CURRENT file): ${BSON_VERSION}")
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

set (BSON_API_VERSION 1.0)

set (CPACK_PACKAGE_VERSION_MAJOR ${BSON_MAJOR_VERSION})
set (CPACK_PACKAGE_VERSION_MINOR ${BSON_MINOR_VERSION})

Comment on lines -35 to -37
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These values are inferred from project(), which now contains the correct version information.

(Not sure if we have many CPack users anyway, though)

include (CPack)
TEST_BIG_ENDIAN (BSON_BIG_ENDIAN)

Expand Down Expand Up @@ -267,9 +270,6 @@ endif ()
if (WIN32)
# gethostbyname
target_link_libraries (bson_shared PRIVATE ws2_32)
# Can't find_library () system dependencies
# must be handled specially since we can't resolve them
set (BSON_SYSTEM_LIBRARIES ${BSON_SYSTEM_LIBRARIES} ws2_32)
endif ()

if (MONGOC_ENABLE_STATIC_BUILD)
Expand Down Expand Up @@ -367,11 +367,6 @@ install (
INCLUDES DESTINATION ${BSON_HEADER_INSTALL_DIR}
FRAMEWORK DESTINATION ${CMAKE_INSTALL_BINDIR}
)
set_target_properties(${TARGETS_TO_INSTALL} PROPERTIES
pkg_config_NAME libbson
pkg_config_DESCRIPTION "The libbson BSON serialization library."
pkg_config_VERSION "${BSON_VERSION}"
)
Comment on lines -370 to -374
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inferred from project()

set_property(TARGET ${TARGETS_TO_INSTALL} APPEND PROPERTY pkg_config_INCLUDE_DIRECTORIES "${BSON_HEADER_INSTALL_DIR}")

install (
Expand All @@ -390,22 +385,7 @@ if (ENABLE_APPLE_FRAMEWORK)
)
endif ()

set (LIBBSON_LIBRARIES "")
foreach (_lib ${BSON_LIBRARIES})
if (_lib MATCHES ".*/.*" OR _lib MATCHES "^-")
set (LIBBSON_LIBRARIES "${LIBBSON_LIBRARIES} ${_lib}")
else ()
set (LIBBSON_LIBRARIES "${LIBBSON_LIBRARIES} -l${_lib}")
endif ()
endforeach ()
# System dependencies don't match the above regexs, but also don't want the -l
foreach (_lib ${BSON_SYSTEM_LIBRARIES})
set (LIBBSON_LIBRARIES "${LIBBSON_LIBRARIES} ${_lib}")
endforeach ()

include (CMakePackageConfigHelpers)
set (INCLUDE_INSTALL_DIRS "${BSON_HEADER_INSTALL_DIR}")
set (LIBRARY_INSTALL_DIRS ${CMAKE_INSTALL_LIBDIR})
Comment on lines -393 to -408
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only used by the old script generation during configure_file, so these aren't needed otherwise.


write_basic_package_version_file (
"${CMAKE_CURRENT_BINARY_DIR}/bson/bson-${BSON_API_VERSION}-config-version.cmake"
Expand Down Expand Up @@ -439,7 +419,7 @@ install (
Devel
)

include (build/cmake/BSONPackage.cmake)
include (LegacyPackage)

if (ENABLE_MAN_PAGES STREQUAL ON OR ENABLE_HTML_DOCS STREQUAL ON)
find_package (Sphinx REQUIRED)
Expand Down
4 changes: 0 additions & 4 deletions src/libbson/build/cmake/.gitignore

This file was deleted.

30 changes: 0 additions & 30 deletions src/libbson/build/cmake/BSONPackage.cmake

This file was deleted.

27 changes: 0 additions & 27 deletions src/libbson/build/cmake/libbson-1.0-config-version.cmake.in

This file was deleted.

35 changes: 0 additions & 35 deletions src/libbson/build/cmake/libbson-1.0-config.cmake.in

This file was deleted.

41 changes: 0 additions & 41 deletions src/libbson/build/cmake/libbson-static-1.0-config.cmake.in

This file was deleted.

Loading