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 mingkuang-Chuyu committed Nov 27, 2024
1 parent 19436f6 commit 17bf7fb
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
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
50 changes: 29 additions & 21 deletions config/config.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核心版本号,由于4.X并不兼容3.X。此值可以用于兼容性判断。
set(LTL_CoreVersion 5)
Expand Down 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 17bf7fb

Please sign in to comment.