Skip to content

Commit 8ee3e7b

Browse files
authored
Support version constraints when finding CRoaring with CMake (#739)
* Add version generation and separate config and targets so that versions are supported * Add comment
1 parent 1a2c980 commit 8ee3e7b

File tree

2 files changed

+65
-6
lines changed

2 files changed

+65
-6
lines changed

cmake/config.cmake.in

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
19+
@PACKAGE_INIT@
20+
21+
cmake_minimum_required(VERSION @CMAKE_MINIMUM_REQUIRED_VERSION@)
22+
23+
include("${CMAKE_CURRENT_LIST_DIR}/roaring-targets.cmake" REQUIRED)
24+
include("${CMAKE_CURRENT_LIST_DIR}/roaring-config-version.cmake" REQUIRED)
25+
26+
set(${CMAKE_FIND_PACKAGE_NAME}_CONFIG "${CMAKE_CURRENT_LIST_FILE}")
27+
include(FindPackageHandleStandardArgs)
28+
find_package_handle_standard_args(${CMAKE_FIND_PACKAGE_NAME} CONFIG_MODE)

src/CMakeLists.txt

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,42 @@ install(TARGETS roaring
7171
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
7272
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
7373
)
74-
install(EXPORT roaring-config
75-
FILE roaring-config.cmake
76-
NAMESPACE roaring::
77-
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/roaring
78-
)
74+
75+
include(CMakePackageConfigHelpers)
76+
77+
# Set up both the build and install trees as suitable for find_package calls.
78+
# Configuring the build tree as well as the install tree makes it much easier
79+
# to test other libraries against custom builds of CRoaring by pointing
80+
# CMAKE_PREFIX_PATH or equivalent directly at the build directory of CRoaring.
81+
foreach(tree_type BUILD INSTALL)
82+
if(tree_type STREQUAL "BUILD")
83+
set(install_location ".")
84+
else()
85+
set(install_location "${CMAKE_INSTALL_LIBDIR}/cmake/roaring")
86+
endif()
87+
88+
set(build_location "${PROJECT_BINARY_DIR}/${install_location}")
89+
write_basic_package_version_file(
90+
"${build_location}/roaring-config-version.cmake"
91+
VERSION ${ROARING_LIB_VERSION}
92+
COMPATIBILITY SameMajorVersion)
93+
configure_package_config_file("${CMAKE_SOURCE_DIR}/cmake/config.cmake.in"
94+
"${build_location}/roaring-config.cmake"
95+
INSTALL_DESTINATION "${install_location}")
96+
97+
if(tree_type STREQUAL "BUILD")
98+
export(EXPORT roaring-config
99+
FILE "${build_location}/roaring-targets.cmake"
100+
NAMESPACE roaring::)
101+
102+
else()
103+
install(DIRECTORY "${build_location}/" DESTINATION "${install_location}")
104+
install(EXPORT roaring-config
105+
DESTINATION "${install_location}"
106+
FILE "roaring-targets.cmake"
107+
NAMESPACE roaring::)
108+
endif()
109+
endforeach()
79110

80111
if(NOT MSVC)
81112
## We output the library at the root of the current directory where cmake is invoked
@@ -112,4 +143,4 @@ if(ROARING_SANITIZE_THREADS)
112143
message(STATUS "Enabling thread sanitizer")
113144
target_compile_options(roaring PUBLIC -fsanitize=thread -fno-sanitize-recover=all)
114145
target_link_libraries(roaring PUBLIC -fsanitize=thread -fno-sanitize-recover=all)
115-
endif()
146+
endif()

0 commit comments

Comments
 (0)