Skip to content

Commit

Permalink
Fea, 使用cmake INTERFACE机制支持VC-LTL布局引用(PR#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 authored and xupengjie1 committed Nov 19, 2024
1 parent 4565706 commit 5a1b885
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/Build&Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: 恢复编译产物
id: ltlBinCache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: |
TargetPlatform/**/*.lib
Expand All @@ -21,7 +21,7 @@ jobs:
- name: 恢复缓存
if: steps.ltlBinCache.outputs.cache-hit != 'true'
id: ltlCache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: Tools/**/libucrt_shared.lib
key: ltl_${{ hashFiles('**/Build_libucrt_shared.cmd') }}
Expand Down Expand Up @@ -191,7 +191,7 @@ jobs:
- name: 匹配Redist缓存
if: contains(github.ref, 'tags/')
id: ltlRedistCache
uses: actions/cache@v2
uses: actions/cache@v4
with:
path: VC-LTL*-Redist.7z
key: ltl_Redist_${{ hashFiles('Redist/**/*.dll') }}
Expand All @@ -203,14 +203,14 @@ jobs:
run: |
del VC-LTL-${{env.BuildVersion}}-Redist.7z /Q /F
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
path: |
*.nupkg
*.7z
# 失败时我们收集一些信息,用于诊断
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
if: failure()
with:
name: ErrorLog
Expand Down
4 changes: 3 additions & 1 deletion VC-LTL helper for cmake.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.5.2)
cmake_minimum_required(VERSION 3.13)

#
# VC-LTL自动化加载配置,建议你将此文件单独复制到你的工程再使用,该文件能自动识别当前环境是否存在VC-LTL,并且自动应用。
Expand Down Expand Up @@ -27,6 +27,8 @@
#控制TargetPlatform版本,目前可用版本为5.1.2600.0 6.0.6000.0(默认) 6.2.9200.0 10.0.10240.0 10.0.19041.0
#set(WindowsTargetPlatformMinVersion "10.0.10240.0")

#(PR#70 引入),默认关,开启后将使用cmake `INTERFACE`能力,然后单独`target_link_directories(工程名称 VC_LTL)` 即可引用
#option(VC_LTL_EnableCMakeInterface "VC_LTL_EnableCMakeInterface" on)
####################################################################################################################################################

if(NOT VC_LTL_Root)
Expand Down
48 changes: 28 additions & 20 deletions config/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ if(${SupportLTL} STREQUAL "true")
elseif(CMAKE_GENERATOR_PLATFORM)
# -A 参数已经传递,仅在 CMake 3.1更高版本中支持
message("CMAKE_GENERATOR_PLATFORM = " ${CMAKE_GENERATOR_PLATFORM})
if(${CMAKE_GENERATOR_PLATFORM} STREQUAL "Win32")
string(TOLOWER "${CMAKE_GENERATOR_PLATFORM}" CMAKE_GENERATOR_PLATFORM_LOWER)
if(${CMAKE_GENERATOR_PLATFORM_LOWER} STREQUAL "win32")
set(LTLPlatform "Win32")
elseif(${CMAKE_GENERATOR_PLATFORM} STREQUAL "x64")
elseif(${CMAKE_GENERATOR_PLATFORM_LOWER} STREQUAL "x64")
set(LTLPlatform "x64")
elseif(${CMAKE_GENERATOR_PLATFORM} STREQUAL "arm")
elseif(${CMAKE_GENERATOR_PLATFORM_LOWER} STREQUAL "arm")
set(LTLPlatform "arm")
elseif(${CMAKE_GENERATOR_PLATFORM} STREQUAL "arm64")
elseif(${CMAKE_GENERATOR_PLATFORM_LOWER} STREQUAL "arm64")
set(LTLPlatform "arm64")
else()
message(WARNING "VC-LTL not load, Unknown Platform!!!")
Expand All @@ -44,13 +45,14 @@ if(${SupportLTL} STREQUAL "true")
elseif(CMAKE_VS_PLATFORM_NAME)
# CMake 3.1以及更早版本不支持 -A 参数,因此通过 CMAKE_VS_PLATFORM_NAME解决
message("CMAKE_VS_PLATFORM_NAME = " ${CMAKE_VS_PLATFORM_NAME})
if(${CMAKE_VS_PLATFORM_NAME} STREQUAL "Win32")
string(TOLOWER "${CMAKE_VS_PLATFORM_NAME}" CMAKE_VS_PLATFORM_NAME_LOWER)
if(${CMAKE_VS_PLATFORM_NAME_LOWER} STREQUAL "win32")
set(LTLPlatform "Win32")
elseif(${CMAKE_VS_PLATFORM_NAME} STREQUAL "x64")
elseif(${CMAKE_VS_PLATFORM_NAME_LOWER} STREQUAL "x64")
set(LTLPlatform "x64")
elseif(${CMAKE_VS_PLATFORM_NAME} STREQUAL "arm")
elseif(${CMAKE_VS_PLATFORM_NAME_LOWER} STREQUAL "arm")
set(LTLPlatform "arm")
elseif(${CMAKE_VS_PLATFORM_NAME} STREQUAL "arm64")
elseif(${CMAKE_VS_PLATFORM_NAME_LOWER} STREQUAL "arm64")
set(LTLPlatform "arm64")
else()
message(WARNING "VC-LTL not load, Unknown Platform!!!")
Expand Down Expand Up @@ -81,13 +83,14 @@ if(${SupportLTL} STREQUAL "true")
elseif(VCPKG_TARGET_ARCHITECTURE)
#为了兼容VCPKG
message("VCPKG_TARGET_ARCHITECTURE = " ${VCPKG_TARGET_ARCHITECTURE})
if(${VCPKG_TARGET_ARCHITECTURE} STREQUAL "x86")
string(TOLOWER "${VCPKG_TARGET_ARCHITECTURE}" VCPKG_TARGET_ARCHITECTURE_LOWER)
if(${VCPKG_TARGET_ARCHITECTURE_LOWER} STREQUAL "x86")
set(LTLPlatform "Win32")
elseif(${VCPKG_TARGET_ARCHITECTURE} STREQUAL "x64")
elseif(${VCPKG_TARGET_ARCHITECTURE_LOWER} STREQUAL "x64")
set(LTLPlatform "x64")
elseif(${VCPKG_TARGET_ARCHITECTURE} STREQUAL "arm")
elseif(${VCPKG_TARGET_ARCHITECTURE_LOWER} STREQUAL "arm")
set(LTLPlatform "arm")
elseif(${VCPKG_TARGET_ARCHITECTURE} STREQUAL "arm64")
elseif(${VCPKG_TARGET_ARCHITECTURE_LOWER} STREQUAL "arm64")
set(LTLPlatform "arm64")
else()
message(WARNING "VC-LTL not load, Unknown Platform!!!")
Expand All @@ -96,13 +99,14 @@ if(${SupportLTL} STREQUAL "true")
elseif(DEFINED ENV{VSCMD_ARG_TGT_ARCH})
#VSCMD_ARG_TGT_ARCH参数只有2017才有,因此兼容性更差
message("VSCMD_ARG_TGT_ARCH = " $ENV{VSCMD_ARG_TGT_ARCH})
if($ENV{VSCMD_ARG_TGT_ARCH} STREQUAL "x86")
string(TOLOWER "$ENV{VSCMD_ARG_TGT_ARCH}" VSCMD_ARG_TGT_ARCH_LOWER)
if(${VSCMD_ARG_TGT_ARCH_LOWER} STREQUAL "x86")
set(LTLPlatform "Win32")
elseif($ENV{VSCMD_ARG_TGT_ARCH} STREQUAL "x64")
elseif(${VSCMD_ARG_TGT_ARCH_LOWER} STREQUAL "x64")
set(LTLPlatform "x64")
elseif($ENV{VSCMD_ARG_TGT_ARCH} STREQUAL "arm")
elseif(${VSCMD_ARG_TGT_ARCH_LOWER} STREQUAL "arm")
set(LTLPlatform "arm")
elseif($ENV{VSCMD_ARG_TGT_ARCH} STREQUAL "arm64")
elseif(${VSCMD_ARG_TGT_ARCH_LOWER} STREQUAL "arm64")
set(LTLPlatform "arm64")
else()
message(WARNING "VC-LTL not load, Unknown Platform!!!")
Expand Down Expand Up @@ -212,10 +216,14 @@ if(${SupportLTL} STREQUAL "true")

#message("INCLUDE " $ENV{INCLUDE})
#message("LIB " $ENV{LIB})

include_directories(BEFORE SYSTEM ${VC_LTL_Include})
link_directories(${VC_LTL_Library})

if(VC_LTL_EnableCMakeInterface)
add_library(VC_LTL INTERFACE)
target_include_directories(VC_LTL SYSTEM BEFORE INTERFACE ${VC_LTL_Include})
target_link_directories(VC_LTL INTERFACE ${VC_LTL_Library})
else()
include_directories(BEFORE SYSTEM ${VC_LTL_Include})
link_directories(${VC_LTL_Library})
endif()
#message("INCLUDE " $ENV{INCLUDE})
#message("LIB " $ENV{LIB})

Expand Down

0 comments on commit 5a1b885

Please sign in to comment.