cmakelists切换为vcpkg库支持

This commit is contained in:
JackLee_CN 2024-10-12 22:08:32 +08:00
parent 23ac4af9ab
commit d08a065442
3 changed files with 37 additions and 12 deletions

View File

@ -1,6 +1,10 @@
#cmake #cmake
cmake_minimum_required(VERSION 3.16) cmake_minimum_required(VERSION 3.16)
set(VCPKG_ROOT "F:/SourceCode/vcpkg")
set(CMAKE_TOOLCHAIN_FILE "F:/SourceCode/vcpkg/scripts/buildsystems/vcpkg.cmake")
set(VCPKG_TARGET_TRIPLET "x64-mingw-static")
# #
project(XSteam VERSION 1.0.0 LANGUAGES CXX) project(XSteam VERSION 1.0.0 LANGUAGES CXX)
configure_file (version.h.in version.h @ONLY) configure_file (version.h.in version.h @ONLY)
@ -38,10 +42,9 @@ endif()
#QT .cmake #QT .cmake
SET(QT_DIR "D:/Dev/Qt/6.3.2/mingw1120_static_x64_base/lib/cmake") SET(QT_DIR "D:/Dev/Qt/6.3.2/mingw1120_static_x64_base/lib/cmake")
SET(MSYS2 "D:/Dev/msys64/mingw64/lib")
SET(JSON ${PROJECT_SOURCE_DIR}/3rdparty/json) SET(JSON ${PROJECT_SOURCE_DIR}/3rdparty/json)
LIST(APPEND CMAKE_PREFIX_PATH ${QT_DIR} ${MSYS2}) LIST(APPEND CMAKE_PREFIX_PATH ${QT_DIR})
#QT #QT
FIND_PACKAGE(Qt6 REQUIRED Core Gui Widgets Network) FIND_PACKAGE(Qt6 REQUIRED Core Gui Widgets Network)
@ -49,7 +52,6 @@ FIND_PACKAGE(Qt6 REQUIRED Core Gui Widgets Network)
# #
MESSAGE(STATUS "----------基础路径输出 START-------------") MESSAGE(STATUS "----------基础路径输出 START-------------")
MESSAGE(STATUS "QT_DIR_PATH=${QT_DIR}") MESSAGE(STATUS "QT_DIR_PATH=${QT_DIR}")
MESSAGE(STATUS "MSYS2_DIR_PATH=${MSYS2}")
MESSAGE(STATUS "JSON_DIR_PATH=${JSON}") MESSAGE(STATUS "JSON_DIR_PATH=${JSON}")
MESSAGE(STATUS "----------基础路径输出 END---------------") MESSAGE(STATUS "----------基础路径输出 END---------------")
@ -59,7 +61,6 @@ find_package(PkgConfig REQUIRED QUIET)
pkg_check_modules(LIBGIT2 REQUIRED IMPORTED_TARGET libgit2) pkg_check_modules(LIBGIT2 REQUIRED IMPORTED_TARGET libgit2)
if(LIBGIT2_FOUND) if(LIBGIT2_FOUND)
include_directories(${LIBGIT2_INCLUDE_DIRS}) include_directories(${LIBGIT2_INCLUDE_DIRS})
link_directories(${LIBGIT2_LIBRARIES})
message(STATUS "------------LIBGIT2 INFO----------------------") message(STATUS "------------LIBGIT2 INFO----------------------")
message(STATUS "LIBGIT2_FOUND=Yes") message(STATUS "LIBGIT2_FOUND=Yes")
message(STATUS "LIBGIT2 Found:->LIBGIT2_LIBRARIES:${LIBGIT2_LIBRARIES}") message(STATUS "LIBGIT2 Found:->LIBGIT2_LIBRARIES:${LIBGIT2_LIBRARIES}")
@ -81,7 +82,6 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(CURL REQUIRED IMPORTED_TARGET libcurl) pkg_check_modules(CURL REQUIRED IMPORTED_TARGET libcurl)
if(CURL_FOUND) if(CURL_FOUND)
include_directories(${CURL_INCLUDE_DIRS}) include_directories(${CURL_INCLUDE_DIRS})
#link_directories(${CURL_LIBRARIES})
message(STATUS "------------CURL INFO START---------------------") message(STATUS "------------CURL INFO START---------------------")
message(STATUS "CURL_FOUND=Yes") message(STATUS "CURL_FOUND=Yes")
message(STATUS "Curl Found:->CRUL_LIBRARIES:${CURL_LIBRARIES}") message(STATUS "Curl Found:->CRUL_LIBRARIES:${CURL_LIBRARIES}")
@ -149,12 +149,7 @@ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -fstack-check")
# #
target_link_options(${PROJECT_NAME} PUBLIC -Wl,--allow-multiple-definition) target_link_options(${PROJECT_NAME} PUBLIC -Wl,--allow-multiple-definition)
target_link_libraries( target_link_libraries(
${PROJECT_NAME} PRIVATE ${LIBGIT2_STATIC_LIBRARIES} -lwinhttp -lpcre.dll -lcrypto -lssl -lz ${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Network PkgConfig::LIBGIT2 PkgConfig::CURL
)
target_link_libraries(
${PROJECT_NAME} PRIVATE ${CURL_LINK_LIBRARIES}
)
target_link_libraries(
${PROJECT_NAME} PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets Qt6::Network
) )

16
CMakePresets.json Normal file
View File

@ -0,0 +1,16 @@
{
"version": 2,
"configurePresets": [
{
"name": "vcpkg-mingw-x64",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_MAKE_PROGRAM":"ninja.exe",
"CMAKE_C_COMPILER":"x86_64-w64-mingw32-gcc.exe",
"CMAKE_CXX_COMPILER":"x86_64-w64-mingw32-g++.exe",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
}
]
}

14
vcpkg-configuration.json Normal file
View File

@ -0,0 +1,14 @@
{
"default-registry": {
"kind": "git",
"baseline": "9558037875497b9db8cf38fcd7db68ec661bffe7",
"repository": "https://github.com/microsoft/vcpkg"
},
"registries": [
{
"kind": "artifact",
"location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
"name": "microsoft"
}
]
}