Skip to content

Commit

Permalink
[+]: support cmake install
Browse files Browse the repository at this point in the history
support cmake install, currently only target "xquic" is supported

BREAKING CHANGE: Increased the minimum version requirement for cmake
  • Loading branch information
zheisure committed Nov 9, 2024
1 parent 28ccf41 commit 0252140
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ bss/
*.swp
third_party/
.idea/
.vscode/
cmake-build-debug/
50 changes: 46 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Copyright (c) 2022, Alibaba Group Holding Limited

cmake_minimum_required (VERSION 2.6)
project (xquic)
cmake_minimum_required (VERSION 3.15)
project (xquic VERSION 1.8.1)

set (xquic_VERSION_MAJOR 0)
set (xquic_VERSION_MINOR 1)
set (CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

option (XQC_ENABLE_BBR2 "enable bbr2" OFF)
Expand Down Expand Up @@ -388,12 +386,14 @@ add_library(
STATIC
${XQC_SOURCE}
)
target_include_directories(xquic-static PUBLIC $<INSTALL_INTERFACE:include>)

add_library(
xquic
SHARED
${XQC_SOURCE}
)
target_include_directories(xquic PUBLIC $<INSTALL_INTERFACE:include>)

if(PLATFORM MATCHES "mac")
target_link_libraries(
Expand Down Expand Up @@ -421,3 +421,45 @@ if(CMAKE_BUILD_TYPE STREQUAL MinSizeRel)
COMMAND ${CMAKE_STRIP} libxquic.so)
endif()

#-------------------- install --------------------#
include(CMakePackageConfigHelpers)

configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/xquicConfig.cmake"
INSTALL_DESTINATION "lib/cmake/xquic"
NO_SET_AND_CHECK_MACRO
)

write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/xquicConfigVersion.cmake"
VERSION "${PROJECT_VERSION}"
COMPATIBILITY AnyNewerVersion
)

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/xquicConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/xquicConfigVersion.cmake
DESTINATION lib/cmake/xquic
)

install(DIRECTORY include/xquic
FILES_MATCHING
DESTINATION "include"
PATTERN "*.h"
)

install(TARGETS xquic
EXPORT xquicTargets
DESTINATION lib
)

install(EXPORT xquicTargets
FILE xquicTargets.cmake
NAMESPACE xquic::
DESTINATION lib/cmake/xquic
)

export(EXPORT xquicTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/xquicTargets.cmake"
NAMESPACE xquic::
)
23 changes: 23 additions & 0 deletions cmake/Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

get_filename_component(xquic_ROOT "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
set(xquic_INCLUDE_DIRS "${xquic_ROOT}/include")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(xquic
REQUIRED_VARS xquic_INCLUDE_DIRS
)

if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/xquicTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/xquicTargets.cmake")
check_required_components(xquic)
message(STATUS "Imported target: xquic::xquic")
endif()

if (EXISTS "${CMAKE_CURRENT_LIST_DIR}/xquic-staticTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/xquic-staticTargets.cmake")
check_required_components(xquic-static)
message(STATUS "Imported target: xquic::xquic-static")
endif()

0 comments on commit 0252140

Please sign in to comment.