From 02521401226e197ae87c121be49581e82ece1357 Mon Sep 17 00:00:00 2001 From: zheisure Date: Sat, 9 Nov 2024 07:59:52 +0000 Subject: [PATCH] [+]: support cmake install support cmake install, currently only target "xquic" is supported BREAKING CHANGE: Increased the minimum version requirement for cmake --- .gitignore | 1 + CMakeLists.txt | 50 +++++++++++++++++++++++++++++++++++++++---- cmake/Config.cmake.in | 23 ++++++++++++++++++++ 3 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 cmake/Config.cmake.in diff --git a/.gitignore b/.gitignore index 27a483fe7..0a6c8ff07 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ bss/ *.swp third_party/ .idea/ +.vscode/ cmake-build-debug/ diff --git a/CMakeLists.txt b/CMakeLists.txt index 70d61d130..bab9ddd6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -388,12 +386,14 @@ add_library( STATIC ${XQC_SOURCE} ) +target_include_directories(xquic-static PUBLIC $) add_library( xquic SHARED ${XQC_SOURCE} ) +target_include_directories(xquic PUBLIC $) if(PLATFORM MATCHES "mac") target_link_libraries( @@ -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:: +) \ No newline at end of file diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 000000000..fc4192890 --- /dev/null +++ b/cmake/Config.cmake.in @@ -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() \ No newline at end of file