diff --git a/.github/workflows/build-reuse-win.yml b/.github/workflows/build-reuse-win.yml index 8cbab25857..20fd3f893f 100644 --- a/.github/workflows/build-reuse-win.yml +++ b/.github/workflows/build-reuse-win.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 80999f69e7..522118f86c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -89,6 +89,7 @@ option(QUIC_STATIC_LINK_CRT "Statically links the C runtime" ON) option(QUIC_STATIC_LINK_PARTIAL_CRT "Statically links the compiler-specific portion of the C runtime" ON) option(QUIC_UWP_BUILD "Build for UWP" OFF) option(QUIC_GAMECORE_BUILD "Build for GameCore" OFF) +option(QUIC_EXTERNAL_TOOLCHAIN "Enable if system libs and include paths are configured by CMake toolchain" OFF) option(QUIC_PGO "Enables profile guided optimizations" OFF) option(QUIC_LINUX_XDP_ENABLED "Enables XDP support" OFF) option(QUIC_SOURCE_LINK "Enables source linking on MSVC" ON) @@ -459,7 +460,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 + $ + $) add_dependencies(MsQuicEtw_Header MsQuicEtw_HeaderBuild) add_library(MsQuicEtw_Resource OBJECT ${QUIC_BUILD_DIR}/inc/MsQuicEtw.rc) @@ -477,7 +480,11 @@ if(WIN32) endif() if (QUIC_GAMECORE_BUILD) - list(APPEND QUIC_COMMON_DEFINES WINAPI_FAMILY=WINAPI_FAMILY_GAMES QUIC_GAMECORE_BUILD QUIC_RESTRICTED_BUILD) + list(APPEND QUIC_COMMON_DEFINES QUIC_GAMECORE_BUILD QUIC_RESTRICTED_BUILD) + endif() + + if (QUIC_GAMECORE_BUILD AND NOT QUIC_EXTERNAL_TOOLCHAIN) + list(APPEND QUIC_COMMON_DEFINES WINAPI_FAMILY=WINAPI_FAMILY_GAMES) set(CMAKE_CXX_STANDARD_LIBRARIES "") set(CMAKE_CXX_STANDARD_LIBRARIES_INIT "") set(CMAKE_C_STANDARD_LIBRARIES "") diff --git a/src/bin/CMakeLists.txt b/src/bin/CMakeLists.txt index 23768235e8..18048e3b72 100644 --- a/src/bin/CMakeLists.txt +++ b/src/bin/CMakeLists.txt @@ -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}) @@ -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") @@ -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) @@ -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() @@ -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() @@ -250,27 +250,18 @@ elseif (CX_PLATFORM STREQUAL "darwin") PROPERTIES LINK_FLAGS "-exported_symbols_list \"${CMAKE_CURRENT_SOURCE_DIR}/darwin/exports.txt\"") endif() -if(BUILD_SHARED_LIBS) - target_include_directories(msquic PUBLIC - $ - $) -else() - target_include_directories(msquic_static INTERFACE - $ - $) - target_include_directories(msquic INTERFACE - $ - $) +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() -set(PUBLIC_HEADERS - ../inc/msquic.h - ../inc/msquic_winuser.h - ../inc/msquic_posix.h - ../inc/quic_sal_stub.h) +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() diff --git a/src/core/unittest/CMakeLists.txt b/src/core/unittest/CMakeLists.txt index 4f811b475e..4e4170cf99 100644 --- a/src/core/unittest/CMakeLists.txt +++ b/src/core/unittest/CMakeLists.txt @@ -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) diff --git a/src/generated/CMakeLists.txt b/src/generated/CMakeLists.txt index 19c49f1bf3..93bd6cc9a2 100644 --- a/src/generated/CMakeLists.txt +++ b/src/generated/CMakeLists.txt @@ -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 + $ + $) + target_include_directories(logging_inc INTERFACE + $ + $) + target_include_directories(logging_inc INTERFACE + $ + $) FILE(GLOB LOGGING_FILES ${CMAKE_CURRENT_SOURCE_DIR}/linux/*.c) add_library(logging STATIC ${LOGGING_FILES}) diff --git a/src/inc/CMakeLists.txt b/src/inc/CMakeLists.txt index 94daef9a66..48edebd1e0 100644 --- a/src/inc/CMakeLists.txt +++ b/src/inc/CMakeLists.txt @@ -9,7 +9,9 @@ target_compile_options(inc INTERFACE ${QUIC_C_FLAGS}) target_compile_options(inc INTERFACE $<$:${QUIC_CXX_FLAGS}>) target_compile_definitions(inc INTERFACE ${QUIC_COMMON_DEFINES}) -target_include_directories(inc INTERFACE ${QUIC_INCLUDE_DIR}) +target_include_directories(inc INTERFACE + $ + $) target_compile_features(inc INTERFACE cxx_std_17) target_compile_features(inc INTERFACE c_std_11) @@ -40,10 +42,13 @@ if(WIN32) if(QUIC_UWP_BUILD) target_link_libraries(base_link INTERFACE OneCore ws2_32 ntdll) elseif(QUIC_GAMECORE_BUILD) - target_link_options(inc INTERFACE ${Console_LinkOptions}) - target_compile_options(inc INTERFACE ${Console_ArchOptions}) - target_link_directories(inc INTERFACE ${Console_EndpointLibRoot}) - target_link_libraries(base_link INTERFACE xgameplatform ntdll advapi32) + target_link_libraries(base_link INTERFACE ntdll advapi32) + if(NOT QUIC_EXTERNAL_TOOLCHAIN) + target_link_options(inc INTERFACE ${Console_LinkOptions}) + target_compile_options(inc INTERFACE ${Console_ArchOptions}) + target_link_directories(inc INTERFACE ${Console_EndpointLibRoot}) + target_link_libraries(base_link INTERFACE xgameplatform) + endif() else() target_link_libraries(base_link INTERFACE ws2_32 schannel ntdll bcrypt ncrypt crypt32 iphlpapi advapi32) endif() diff --git a/src/perf/bin/CMakeLists.txt b/src/perf/bin/CMakeLists.txt index 788f15bc7b..86fa457c66 100644 --- a/src/perf/bin/CMakeLists.txt +++ b/src/perf/bin/CMakeLists.txt @@ -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) diff --git a/src/platform/CMakeLists.txt b/src/platform/CMakeLists.txt index d79d16841d..4a573ae493 100644 --- a/src/platform/CMakeLists.txt +++ b/src/platform/CMakeLists.txt @@ -53,21 +53,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 @@ -82,7 +82,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 @@ -97,34 +97,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 onecore) + target_link_libraries(msquic_platform PUBLIC secur32) + if (NOT QUIC_GAMECORE_BUILD) + target_link_libraries(msquic_platform PUBLIC onecore) + endif() endif() diff --git a/src/platform/unittest/CMakeLists.txt b/src/platform/unittest/CMakeLists.txt index e514d6634a..997066bb10 100644 --- a/src/platform/unittest/CMakeLists.txt +++ b/src/platform/unittest/CMakeLists.txt @@ -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) diff --git a/src/platform/unittest/external/CMakeLists.txt b/src/platform/unittest/external/CMakeLists.txt new file mode 100644 index 0000000000..805b18ff40 --- /dev/null +++ b/src/platform/unittest/external/CMakeLists.txt @@ -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 wbemuuid 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) diff --git a/src/test/bin/CMakeLists.txt b/src/test/bin/CMakeLists.txt index 895d64d053..c4388894f5 100644 --- a/src/test/bin/CMakeLists.txt +++ b/src/test/bin/CMakeLists.txt @@ -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) diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt index 48519c06c1..14582b3d7a 100644 --- a/src/tools/CMakeLists.txt +++ b/src/tools/CMakeLists.txt @@ -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) diff --git a/src/tools/attack/CMakeLists.txt b/src/tools/attack/CMakeLists.txt index 23fcf87861..04ef2eb761 100644 --- a/src/tools/attack/CMakeLists.txt +++ b/src/tools/attack/CMakeLists.txt @@ -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) diff --git a/src/tools/pcp/CMakeLists.txt b/src/tools/pcp/CMakeLists.txt index 43761a8758..f9f6d6d50e 100644 --- a/src/tools/pcp/CMakeLists.txt +++ b/src/tools/pcp/CMakeLists.txt @@ -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) diff --git a/src/tools/recvfuzz/CMakeLists.txt b/src/tools/recvfuzz/CMakeLists.txt index 60af99758c..c8d56aead8 100644 --- a/src/tools/recvfuzz/CMakeLists.txt +++ b/src/tools/recvfuzz/CMakeLists.txt @@ -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() diff --git a/submodules/CMakeLists.txt b/submodules/CMakeLists.txt index a6c5929512..4bf8117629 100644 --- a/submodules/CMakeLists.txt +++ b/submodules/CMakeLists.txt @@ -157,8 +157,9 @@ if (WIN32) target_include_directories( OpenSSLQuic INTERFACE - $<$:${OPENSSL_DIR}/debug/include> - $<$>:${OPENSSL_DIR}/release/include> + $:${OPENSSL_DIR}/debug/include> + $<$>:${OPENSSL_DIR}/release/include>> + $ ) target_link_libraries( OpenSSLQuic @@ -327,7 +328,8 @@ else() target_include_directories( OpenSSLQuic INTERFACE - ${OPENSSL_DIR}/include + $ + $ ) target_link_libraries(