Skip to content

Commit

Permalink
Fix CMake packaging for installation.
Browse files Browse the repository at this point in the history
Add CMake config file (re2Config.cmake) for find_package(re2) - fixes finding Threads dependency
Add CMake version file (re2ConfigVersion.cmake) - allows find_package(re2 <VERSION> ...)

Change-Id: I6c1de1bfc59121085d70a277bd0821504b9d8736
Reviewed-on: https://code-review.googlesource.com/c/re2/+/59530
Reviewed-by: Andrei Bencsik <[email protected]>
Reviewed-by: Paul Wankadia <[email protected]>
  • Loading branch information
bencsikandrei authored and junyer committed Jan 6, 2022
1 parent d826d9f commit cb5bbb2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
cmake_minimum_required(VERSION 3.5.1)

project(RE2 CXX)
include(CMakePackageConfigHelpers)
include(CTest)
include(GNUInstallDirs)

Expand Down Expand Up @@ -154,10 +155,23 @@ set(RE2_HEADERS

install(FILES ${RE2_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/re2)
install(TARGETS re2 EXPORT re2Config
install(TARGETS re2 EXPORT re2Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(EXPORT re2Config
install(EXPORT re2Targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/re2 NAMESPACE re2::)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/re2Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/re2Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/re2
)
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/re2ConfigVersion.cmake
VERSION ${SONAME}.0.0
COMPATIBILITY SameMajorVersion
)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/re2Config.cmake
${CMAKE_CURRENT_BINARY_DIR}/re2ConfigVersion.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/re2)
22 changes: 22 additions & 0 deletions re2Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2022 The RE2 Authors. All Rights Reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

set_and_check(re2_INCLUDE_DIR ${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@)

if(UNIX)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_dependency(Threads REQUIRED)
endif()

check_required_components(re2)

if(TARGET re2::re2)
return()
endif()

include(${CMAKE_CURRENT_LIST_DIR}/re2Targets.cmake)

0 comments on commit cb5bbb2

Please sign in to comment.