From 6411c720ca41dda1689789458bce0259f57330fb Mon Sep 17 00:00:00 2001 From: daonvshu <1286772338@qq.com> Date: Tue, 7 May 2024 16:07:27 +0800 Subject: [PATCH] add install script --- CMakeLists.txt | 2 +- src/CMakeLists.txt | 46 +++++++++++++++++++++++++++++++++----- src/QRouterConfig.cmake.in | 6 +++++ test/CMakeLists.txt | 4 ++-- 4 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 src/QRouterConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index c2fc950..f74971e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.12) project(qrouter) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 78db9bd..3c782b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,6 @@ -cmake_minimum_required(VERSION 3.2) -project(qrouterlib) +cmake_minimum_required(VERSION 3.12) + +project(qrouter VERSION 0.0.8) set(CMAKE_AUTOMOC ON) set(CMAKE_INCLUDE_CURRENT_DIR ON) @@ -7,6 +8,8 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) find_package(QT NAMES Qt6 Qt5 REQUIRED) find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core Gui Widgets REQUIRED) +set(CMAKE_DEBUG_POSTFIX "d") + add_library(${PROJECT_NAME} abstractrouterwidget.cpp qrouter.cpp @@ -16,12 +19,43 @@ add_library(${PROJECT_NAME} container/stackroutercontainer.cpp ) -target_include_directories(${PROJECT_NAME} PUBLIC ../include) - -add_library(qrouter::lib ALIAS ${PROJECT_NAME}) - target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets +) + +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ +) + +include(CMakePackageConfigHelpers) + +install(TARGETS ${PROJECT_NAME} + EXPORT QRouterTargets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION include +) + +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../include/ + DESTINATION include + FILES_MATCHING PATTERN "*.h" +) + +configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/QRouterConfig.cmake.in + "${CMAKE_CURRENT_BINARY_DIR}/QRouterConfig.cmake" + INSTALL_DESTINATION lib/cmake/QRouter +) + +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/QRouterConfig.cmake" + DESTINATION lib/cmake/QRouter +) + +install(EXPORT QRouterTargets + FILE QRouterTargets.cmake + DESTINATION lib/cmake/QRouter ) \ No newline at end of file diff --git a/src/QRouterConfig.cmake.in b/src/QRouterConfig.cmake.in new file mode 100644 index 0000000..e912ef1 --- /dev/null +++ b/src/QRouterConfig.cmake.in @@ -0,0 +1,6 @@ +@PACKAGE_INIT@ + +include(CMakeFindDependencyMacro) +@_find_dependency_calls@ + +include("${CMAKE_CURRENT_LIST_DIR}/QRouterTargets.cmake") \ No newline at end of file diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c5a3d7a..071212c 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.12) project(qroutertest) set(CMAKE_CXX_STANDARD 14) @@ -30,5 +30,5 @@ target_link_libraries(${PROJECT_NAME} Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets - qrouter::lib + qrouter ) \ No newline at end of file