From 39c6b523e4613c0a5df4501d0e75dd027d39f465 Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Wed, 8 Jan 2025 14:22:54 +0100 Subject: [PATCH] Provide namespaced CMake targets (#4737) --- src/bin/CMakeLists.txt | 1 + src/bin/msquic-config.cmake.in | 12 +++++++----- src/inc/CMakeLists.txt | 1 + src/platform/CMakeLists.txt | 2 ++ src/platform/unittest/external/CMakeLists.txt | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/bin/CMakeLists.txt b/src/bin/CMakeLists.txt index 535593502b..bc17d42e54 100644 --- a/src/bin/CMakeLists.txt +++ b/src/bin/CMakeLists.txt @@ -11,6 +11,7 @@ endif() if(BUILD_SHARED_LIBS) add_library(msquic SHARED ${SOURCES}) + add_library(msquic::msquic ALIAS msquic) target_include_directories(msquic PUBLIC $) target_link_libraries(msquic PRIVATE core msquic_platform inc warnings logging base_link main_binary_link_args) set_target_properties(msquic PROPERTIES OUTPUT_NAME ${QUIC_LIBRARY_NAME}) diff --git a/src/bin/msquic-config.cmake.in b/src/bin/msquic-config.cmake.in index e61e63feab..2696ae9bf1 100644 --- a/src/bin/msquic-config.cmake.in +++ b/src/bin/msquic-config.cmake.in @@ -2,8 +2,10 @@ include(CMakeFindDependencyMacro) include("${CMAKE_CURRENT_LIST_DIR}/msquic.cmake") -foreach(_t IN ITEMS msquic msquic_platform) - if(TARGET msquic::${_t} AND NOT TARGET ${_t}) - add_library(${_t} ALIAS msquic::${_t}) - endif() -endforeach() +# Legacy names +if(NOT TARGET msquic) + add_library(msquic ALIAS msquic::msquic) +endif() +if(NOT TARGET msquic_platform) + add_library(msquic_platform ALIAS msquic::platform) +endif() diff --git a/src/inc/CMakeLists.txt b/src/inc/CMakeLists.txt index 48edebd1e0..c1b8fd6c70 100644 --- a/src/inc/CMakeLists.txt +++ b/src/inc/CMakeLists.txt @@ -17,6 +17,7 @@ target_compile_features(inc INTERFACE cxx_std_17) target_compile_features(inc INTERFACE c_std_11) add_library(base_link INTERFACE) +add_library(msquic::base_link ALIAS base_link) if (HAS_GUARDCF) target_link_options(base_link INTERFACE /guard:cf /DYNAMICBASE) diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt index 997906d0cd..61c898a8af 100644 --- a/src/platform/CMakeLists.txt +++ b/src/platform/CMakeLists.txt @@ -60,6 +60,8 @@ else() endif() add_library(msquic_platform STATIC ${SOURCES}) +add_library(msquic::platform ALIAS msquic_platform) +set_target_properties(msquic_platform PROPERTIES EXPORT_NAME platform) if("${CX_PLATFORM}" STREQUAL "windows") target_link_libraries( diff --git a/src/platform/unittest/external/CMakeLists.txt b/src/platform/unittest/external/CMakeLists.txt index cfb1ccba9b..ab4b6e6488 100644 --- a/src/platform/unittest/external/CMakeLists.txt +++ b/src/platform/unittest/external/CMakeLists.txt @@ -32,5 +32,5 @@ set_target_properties(msquic::inc PROPERTIES INTERFACE_COMPILE_DEFINITIONS "${d add_executable(msquicplatformtest ${SOURCES}) target_include_directories(msquicplatformtest PRIVATE ${CMAKE_INSTALL_PREFIX}/include) -target_link_libraries(msquicplatformtest PRIVATE gtest msquic::msquic msquic::msquic_platform ws2_32 ntdll ncrypt crypt32 iphlpapi) +target_link_libraries(msquicplatformtest PRIVATE gtest msquic::msquic msquic::platform ws2_32 ntdll ncrypt crypt32 iphlpapi) target_compile_definitions(msquicplatformtest PRIVATE QUIC_EVENTS_STUB QUIC_LOGS_STUB _DISABLE_VECTOR_ANNOTATION _DISABLE_STRING_ANNOTATION)