Skip to content

Commit

Permalink
export platform (#4574)
Browse files Browse the repository at this point in the history
  • Loading branch information
talregev authored Nov 7, 2024
1 parent 9587f74 commit a275d74
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 39 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/build-reuse-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ jobs:
if: inputs.build == '-Test'
shell: pwsh
run: scripts/build.ps1 -Config ${{ inputs.config }} -Platform ${{ inputs.plat }} -Arch ${{ inputs.arch }} -Tls ${{ inputs.tls }} -DisablePerf -DynamicCRT ${{ inputs.sanitize }}
- name: Build External Platform Test
if: inputs.build == '-Test' && inputs.sanitize != '-Sanitize'
shell: pwsh
run: |
cmake --install build\${{ inputs.plat }}\${{ inputs.arch }}_${{ inputs.tls }} --config ${{ inputs.config }}
cmake src/platform/unittest/external -G "Visual Studio 17 2022" -A ${{ inputs.arch }} -B build_external "-DCMAKE_INSTALL_PREFIX:PATH=C:/Program Files/msquic" -DQUIC_TLS=${{ inputs.tls }}
cmake --build build_external --config ${{ inputs.config }}
- name: Build For Perf
if: inputs.build == '-Perf'
shell: pwsh
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,9 @@ if(WIN32)
set_property(TARGET MsQuicEtw_HeaderBuild PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}helpers")

add_library(MsQuicEtw_Header INTERFACE)
target_include_directories(MsQuicEtw_Header INTERFACE ${QUIC_BUILD_DIR}/inc)
target_include_directories(MsQuicEtw_Header INTERFACE
$<BUILD_INTERFACE:${QUIC_BUILD_DIR}/inc>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
add_dependencies(MsQuicEtw_Header MsQuicEtw_HeaderBuild)

add_library(MsQuicEtw_Resource OBJECT ${QUIC_BUILD_DIR}/inc/MsQuicEtw.rc)
Expand Down
20 changes: 14 additions & 6 deletions src/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif()

if(BUILD_SHARED_LIBS)
add_library(msquic SHARED ${SOURCES})
target_link_libraries(msquic PRIVATE core platform inc warnings logging base_link main_binary_link_args)
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})
if (NOT WIN32)
set_target_properties(msquic PROPERTIES SOVERSION ${QUIC_MAJOR_VERSION} VERSION ${QUIC_FULL_VERSION})
Expand All @@ -21,7 +21,7 @@ if(BUILD_SHARED_LIBS)
endif()
else()
add_library(msquic_static STATIC static/empty.c)
target_link_libraries(msquic_static PRIVATE core platform inc logging main_binary_link_args)
target_link_libraries(msquic_static PRIVATE core msquic_platform inc logging main_binary_link_args)
target_compile_definitions(msquic_static PUBLIC QUIC_BUILD_STATIC)
set_property(TARGET msquic_static PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}libraries")

Expand Down Expand Up @@ -150,7 +150,7 @@ else()
COMMAND libtool -static -o \"${QUIC_STATIC_LIBRARY}\" @${QUIC_DEPS_FILE}
DEPENDS ${QUIC_DEPS_FILE}
DEPENDS core
DEPENDS platform
DEPENDS msquic_platform
DEPENDS msquic_static
)
elseif(WIN32)
Expand Down Expand Up @@ -181,7 +181,7 @@ else()
COMMAND ${CMAKE_COMMAND} -E copy "${QUIC_STATIC_LIBRARY}" "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}"
DEPENDS ${QUIC_DEPS_FILE}
DEPENDS core
DEPENDS platform
DEPENDS msquic_platform
DEPENDS msquic_static
)
else()
Expand All @@ -205,7 +205,7 @@ else()
COMMAND ${CMAKE_AR} -M < ${QUIC_DEPS_FILE}
DEPENDS ${QUIC_DEPS_FILE}
DEPENDS core
DEPENDS platform
DEPENDS msquic_platform
DEPENDS msquic_static
)
endif()
Expand Down Expand Up @@ -254,8 +254,16 @@ include(GNUInstallDirs)

file(GLOB PUBLIC_HEADERS "../inc/*.h" "../inc/*.hpp")

if(QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "openssl3")
list(APPEND OTHER_TARGETS OpenSSL OpenSSLQuic)
endif()

if(WIN32)
list(APPEND OTHER_TARGETS MsQuicEtw_Header)
endif()

if(BUILD_SHARED_LIBS)
install(TARGETS msquic EXPORT msquic DESTINATION lib)
install(TARGETS msquic msquic_platform inc logging_inc warnings main_binary_link_args ${OTHER_TARGETS} EXPORT msquic DESTINATION lib)
else()
install(FILES ${QUIC_STATIC_LIBRARY} DESTINATION lib)
endif()
Expand Down
2 changes: 1 addition & 1 deletion src/core/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ set_property(TARGET msquiccoretest APPEND PROPERTY BUILD_RPATH "$ORIGIN")
target_link_libraries(msquiccoretest msquic)

if (BUILD_SHARED_LIBS)
target_link_libraries(msquiccoretest core platform)
target_link_libraries(msquiccoretest core msquic_platform)
endif()

target_link_libraries(msquiccoretest inc gtest warnings logging base_link)
Expand Down
12 changes: 9 additions & 3 deletions src/generated/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ if(QUIC_ENABLE_LOGGING)
target_link_libraries(logging PRIVATE inc)

elseif(QUIC_LOGGING_TYPE STREQUAL "lttng")
target_include_directories(logging_inc INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/common)
target_include_directories(logging_inc INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/linux)
target_include_directories(logging_inc INTERFACE ${LTTNGUST_INCLUDE_DIRS})
target_include_directories(logging_inc INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/common>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_include_directories(logging_inc INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/linux>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
target_include_directories(logging_inc INTERFACE
$<BUILD_INTERFACE:${LTTNGUST_INCLUDE_DIRS}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

FILE(GLOB LOGGING_FILES ${CMAKE_CURRENT_SOURCE_DIR}/linux/*.c)
add_library(logging STATIC ${LOGGING_FILES})
Expand Down
2 changes: 1 addition & 1 deletion src/perf/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ set_property(TARGET secnetperf PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}perf")
target_link_libraries(secnetperf inc warnings perflib msquic)

if (BUILD_SHARED_LIBS)
target_link_libraries(secnetperf platform)
target_link_libraries(secnetperf msquic_platform)
endif()

target_link_libraries(secnetperf logging base_link)
34 changes: 17 additions & 17 deletions src/platform/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,21 @@ else()
message(FATAL_ERROR "TLS Provider not configured")
endif()

add_library(platform STATIC ${SOURCES})
add_library(msquic_platform STATIC ${SOURCES})

if("${CX_PLATFORM}" STREQUAL "windows")
target_link_libraries(
platform
msquic_platform
PUBLIC
wbemuuid)
target_link_libraries(platform PUBLIC winmm)
target_link_libraries(msquic_platform PUBLIC winmm)
elseif(QUIC_LINUX_XDP_ENABLED)
find_library(NL_LIB nl-3)
find_library(NL_ROUTE_LIB nl-route-3)
find_library(XDP_LIB libxdp.so)
find_library(BPF_LIB libbpf.so)
target_include_directories(platform PRIVATE /usr/include/xdp)
target_include_directories(platform PRIVATE /usr/include/bpf)
target_include_directories(msquic_platform PRIVATE /usr/include/xdp)
target_include_directories(msquic_platform PRIVATE /usr/include/bpf)
set(XDP_PROG_INCLUDE_DIR "-I/usr/include/bpf")

# building XDP program
Expand All @@ -88,7 +88,7 @@ elseif(QUIC_LINUX_XDP_ENABLED)
DEPENDS ${PROJECT_SOURCE_DIR}/src/platform/datapath_raw_xdp_linux_kern.c
)
add_custom_target(xdp_program DEPENDS ${QUIC_OUTPUT_DIR}/datapath_raw_xdp_kern.o)
add_dependencies(platform xdp_program)
add_dependencies(msquic_platform xdp_program)

if (NOT BUILD_SHARED_LIBS)
find_library(ELF_LIB elf) # for static
Expand All @@ -103,37 +103,37 @@ elseif(QUIC_LINUX_XDP_ENABLED)
string(REPLACE ".so" ".a" BPF_LIB ${BPF_LIB})
endif()

target_link_libraries(platform PUBLIC ${XDP_LIB} ${BPF_LIB} ${NL_LIB} ${NL_ROUTE_LIB} ${ELF_LIB} ${Z_LIB} ${ZSTD_LIB})
target_link_libraries(msquic_platform PUBLIC ${XDP_LIB} ${BPF_LIB} ${NL_LIB} ${NL_ROUTE_LIB} ${ELF_LIB} ${Z_LIB} ${ZSTD_LIB})
endif()

target_link_libraries(platform PUBLIC inc)
target_link_libraries(platform PRIVATE warnings main_binary_link_args)
target_link_libraries(msquic_platform PUBLIC inc)
target_link_libraries(msquic_platform PRIVATE warnings main_binary_link_args)

set_property(TARGET platform PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}libraries")
set_property(TARGET msquic_platform PROPERTY FOLDER "${QUIC_FOLDER_PREFIX}libraries")

if ("${CX_PLATFORM}" STREQUAL "windows")
target_include_directories(
platform
msquic_platform
PRIVATE
${EXTRA_PLATFORM_INCLUDE_DIRECTORIES}
${PROJECT_SOURCE_DIR}/submodules/xdp-for-windows/published/external)
elseif(QUIC_LINUX_XDP_ENABLED)
include_directories(/usr/include/libnl3)
target_include_directories(platform PRIVATE ${EXTRA_PLATFORM_INCLUDE_DIRECTORIES})
target_include_directories(msquic_platform PRIVATE ${EXTRA_PLATFORM_INCLUDE_DIRECTORIES})
endif()

if (MSVC AND (QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "schannel") AND NOT QUIC_ENABLE_SANITIZERS)
target_compile_options(platform PRIVATE /analyze)
target_compile_options(msquic_platform PRIVATE /analyze)
endif()

if(QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "openssl3")
target_link_libraries(platform PUBLIC OpenSSL)
target_link_libraries(msquic_platform PUBLIC OpenSSL)
if (CX_PLATFORM STREQUAL "darwin")
target_link_libraries(platform PUBLIC "-framework CoreFoundation" "-framework Security")
target_link_libraries(msquic_platform PUBLIC "-framework CoreFoundation" "-framework Security")
endif()
elseif(QUIC_TLS STREQUAL "schannel")
target_link_libraries(platform PUBLIC secur32)
target_link_libraries(msquic_platform PUBLIC secur32)
if (NOT QUIC_GAMECORE_BUILD)
target_link_libraries(platform PUBLIC onecore)
target_link_libraries(msquic_platform PUBLIC onecore)
endif()
endif()
2 changes: 1 addition & 1 deletion src/platform/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ set_property(TARGET msquicplatformtest APPEND PROPERTY BUILD_RPATH "$ORIGIN")
target_link_libraries(msquicplatformtest msquic)

if (BUILD_SHARED_LIBS)
target_link_libraries(msquicplatformtest platform)
target_link_libraries(msquicplatformtest msquic_platform)
endif()

target_link_libraries(msquicplatformtest inc gtest warnings logging base_link)
Expand Down
38 changes: 38 additions & 0 deletions src/platform/unittest/external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

cmake_minimum_required(VERSION 3.16)

project(msquic_platform_external)

find_package(msquic REQUIRED)
find_library(MSPLATFORM_LIBRARIES
NAMES msquic_platform)

message(STATUS "CMAKE_INSTALL_PREFIX: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "MSPLATFORM_LIBRARIES: ${MSPLATFORM_LIBRARIES}")

include(FetchContent)
FetchContent_Declare(
googletest
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../submodules/googletest
)
FetchContent_MakeAvailable(googletest)

set(SOURCES
../main.cpp
../CryptTest.cpp
../DataPathTest.cpp
../PlatformTest.cpp
# ../StorageTest.cpp
../TlsTest.cpp
)

if(QUIC_TLS STREQUAL "openssl" OR QUIC_TLS STREQUAL "openssl3")
list(APPEND OTHER_TERGETS OpenSSL)
endif()

add_executable(msquicplatformtest ${SOURCES})
target_include_directories(msquicplatformtest PRIVATE ${CMAKE_INSTALL_PREFIX}/include)
target_link_libraries(msquicplatformtest PRIVATE msquic ${MSPLATFORM_LIBRARIES} ${OTHER_TERGETS} gtest ws2_32 schannel ntdll bcrypt ncrypt crypt32 iphlpapi advapi32 secur32 userenv onecore winmm clang_rt.asan_dbg_dynamic-x86_64 clang_rt.asan_dynamic-x86_64)
target_compile_definitions(msquicplatformtest PRIVATE QUIC_EVENTS_STUB QUIC_LOGS_STUB _DISABLE_VECTOR_ANNOTATION _DISABLE_STRING_ANNOTATION)
2 changes: 1 addition & 1 deletion src/test/bin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ set_property(TARGET msquictest APPEND PROPERTY BUILD_RPATH "$ORIGIN")
target_link_libraries(msquictest msquic testlib)

if (BUILD_SHARED_LIBS)
target_link_libraries(msquictest platform)
target_link_libraries(msquictest msquic_platform)
endif()

target_link_libraries(msquictest inc gtest logging base_link)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function(add_quic_tool)
target_link_libraries(${targetname} inc warnings msquic)

if (BUILD_SHARED_LIBS)
target_link_libraries(${targetname} platform)
target_link_libraries(${targetname} msquic_platform)
endif()

target_link_libraries(${targetname} logging base_link)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/attack/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ target_include_directories(quicattack PRIVATE ${PROJECT_SOURCE_DIR}/src/core)
target_link_libraries(quicattack)

if (BUILD_SHARED_LIBS)
target_link_libraries(quicattack core platform)
target_link_libraries(quicattack core msquic_platform)
endif()

target_link_libraries(quicattack logging)
4 changes: 2 additions & 2 deletions src/tools/pcp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ set(SOURCES
add_quic_tool(quicpcp ${SOURCES})

target_include_directories(quicpcp PRIVATE ${PROJECT_SOURCE_DIR}/src/core)
# OK to include platform a second time, will not cause multiple link issues
target_link_libraries(quicpcp core platform)
# OK to include msquic_platform a second time, will not cause multiple link issues
target_link_libraries(quicpcp core msquic_platform)
2 changes: 1 addition & 1 deletion src/tools/recvfuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ endif()
add_quic_tool(recvfuzz recvfuzz.cpp)
target_include_directories(recvfuzz PRIVATE ${PROJECT_SOURCE_DIR}/src/core)
if (BUILD_SHARED_LIBS)
target_link_libraries(recvfuzz core msquic platform)
target_link_libraries(recvfuzz core msquic msquic_platform)
endif()
8 changes: 5 additions & 3 deletions submodules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,9 @@ if (WIN32)
target_include_directories(
OpenSSLQuic
INTERFACE
$<$<CONFIG:Debug>:${OPENSSL_DIR}/debug/include>
$<$<NOT:$<CONFIG:Debug>>:${OPENSSL_DIR}/release/include>
$<BUILD_INTERFACE:$<$<CONFIG:Debug>:${OPENSSL_DIR}/debug/include>
$<$<NOT:$<CONFIG:Debug>>:${OPENSSL_DIR}/release/include>>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(
OpenSSLQuic
Expand Down Expand Up @@ -327,7 +328,8 @@ else()
target_include_directories(
OpenSSLQuic
INTERFACE
${OPENSSL_DIR}/include
$<BUILD_INTERFACE:${OPENSSL_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_link_libraries(
Expand Down

0 comments on commit a275d74

Please sign in to comment.