From 674816a01d10a5ea50cef86c8492b942dcb46752 Mon Sep 17 00:00:00 2001 From: Tim Wojtulewicz Date: Thu, 18 Jan 2024 18:02:29 -0700 Subject: [PATCH] Switch all of the conan configuration to vcpkg --- .gitmodules | 3 +++ CMakeLists.txt | 35 ++++++++++++++++---------------- auxil/vcpkg | 1 + ci/windows/Dockerfile | 2 -- ci/windows/build.cmd | 2 +- ci/windows/conanfile_windows.txt | 8 -------- cmake | 2 +- vcpkg.json | 9 ++++++++ 8 files changed, 33 insertions(+), 29 deletions(-) create mode 160000 auxil/vcpkg delete mode 100644 ci/windows/conanfile_windows.txt create mode 100644 vcpkg.json diff --git a/.gitmodules b/.gitmodules index fefd52ec42..0a59ef67da 100644 --- a/.gitmodules +++ b/.gitmodules @@ -73,3 +73,6 @@ [submodule "auxil/zeekjs"] path = auxil/zeekjs url = https://github.com/corelight/zeekjs.git +[submodule "auxil/vcpkg"] + path = auxil/vcpkg + url = https://github.com/microsoft/vcpkg diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b5281dd5f..3952de8e96 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,17 @@ cmake_minimum_required(VERSION 3.15.0 FATAL_ERROR) if (WIN32) # Enable usage of CMAKE_MSVC_RUNTIME_LIBRARY variable cmake_policy(SET CMP0091 NEW) + + # I tried to just use CMAKE_SOURCE_DIR and CMAKE_CURRENT_SOURCE_DIR + # but it's not setting the path correctly and so the toolchain + # variable doesn't get passed down to submodules like libkqueue + # correctly. Instead get the absolute path to the vcpkg.cmake file + # and use that. + get_filename_component(_toolchain ./auxil/vcpkg/scripts/buildsystems/vcpkg.cmake ABSOLUTE) + + # This needs to happen before the project() call below so that it + # doesn't need to be manually passed on the command line. + set(CMAKE_TOOLCHAIN_FILE ${_toolchain} CACHE STRING "Vcpkg toolchain file") endif () project(Zeek C CXX) @@ -119,33 +130,23 @@ if (MSVC) set(OPENSSL_USE_STATIC_LIBS true) set(OPENSSL_MSVC_STATIC_RT true) - if (ZEEK_STANDALONE) - include(${CMAKE_SOURCE_DIR}/cmake/conan.cmake) - conan_cmake_autodetect(settings) - # Install packages from conanfile - conan_cmake_install(PATH_OR_REFERENCE ${CMAKE_SOURCE_DIR}/ci/windows/conanfile_windows.txt - BUILD missing SETTINGS ${settings}) - endif () - - # Set LibPCAP to point to libpcap binaries. + # Set PCAP_ROOT_DIR to point at the installation from vcpkg. A later call + # to FindPCAP.cmake will fill in the rest of the necessary variables. if (NOT PCAP_ROOT_DIR) - find_package(libpcap) - set(PCAP_ROOT_DIR "${libpcap_LIB_DIRS}/../") - set(PCAP_INCLUDE_DIR ${libpcap_INCLUDES}) - set(PCAP_LIBRARY ${libpcap_LIBS}) + set(PCAP_ROOT_DIR "${VCPKG_INSTALLED_DIR}") endif () set(LIBPCAP_PCAP_COMPILE_NOPCAP_HAS_ERROR_PARAMETER false) - # Set ZLib to point at the right variable. + # Find zlib installed by vcpkg. find_package(ZLIB) - set(ZLIB_LIBRARY ${ZLIB_LIBRARIES}) + set(ZLIB_LIBRARY ZLIB::ZLIB) - # Set CAres + # Find c-ares installed by vcpkg. find_package(c-ares) set(HAVE_CARES true) # Disable FindCAres cmake file include_directories(BEFORE ${c-ares_INCLUDE_DIRS}) - set(zeekdeps ${zeekdeps} ${c-ares_LIBRARIES}) + set(zeekdeps ${zeekdeps} c-ares::cares) add_definitions(-DCARES_STATICLIB) add_subdirectory(auxil/libunistd) diff --git a/auxil/vcpkg b/auxil/vcpkg new file mode 160000 index 0000000000..38d1652f15 --- /dev/null +++ b/auxil/vcpkg @@ -0,0 +1 @@ +Subproject commit 38d1652f152d36481f2f4e8a85c0f1e14f3769f7 diff --git a/ci/windows/Dockerfile b/ci/windows/Dockerfile index e4f3da7947..0117345f05 100644 --- a/ci/windows/Dockerfile +++ b/ci/windows/Dockerfile @@ -16,8 +16,6 @@ RUN [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePoin # Install prerequisites RUN choco install -y --no-progress visualstudio2019buildtools --version=16.11.11.0 RUN choco install -y --no-progress visualstudio2019-workload-vctools --version=1.0.0 --package-parameters '--add Microsoft.VisualStudio.Component.VC.ATLMFC' -# Pin conan to 1.58.0 until conan.cmake is updated to support 2.0 -RUN choco install -y --no-progress conan --version=1.58.0 RUN choco install -y --no-progress sed RUN choco install -y --no-progress winflexbison3 RUN choco install -y --no-progress msysgit diff --git a/ci/windows/build.cmd b/ci/windows/build.cmd index b64396a417..c9b38d4b3f 100644 --- a/ci/windows/build.cmd +++ b/ci/windows/build.cmd @@ -7,5 +7,5 @@ call "c:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliar mkdir build cd build -cmake.exe .. -DCMAKE_BUILD_TYPE=release -DENABLE_ZEEK_UNIT_TESTS=yes -G Ninja +cmake.exe .. -DCMAKE_BUILD_TYPE=release -DVCPKG_TARGET_TRIPLET="x64-windows-static" -DENABLE_ZEEK_UNIT_TESTS=yes -G Ninja cmake.exe --build . diff --git a/ci/windows/conanfile_windows.txt b/ci/windows/conanfile_windows.txt deleted file mode 100644 index 951bca0bdf..0000000000 --- a/ci/windows/conanfile_windows.txt +++ /dev/null @@ -1,8 +0,0 @@ -[requires] -zlib/1.2.11 -libpcap/1.10.1 -c-ares/1.21.0 - -[generators] -cmake_find_package -cmake diff --git a/cmake b/cmake index 01fcb68300..217865f599 160000 --- a/cmake +++ b/cmake @@ -1 +1 @@ -Subproject commit 01fcb683005e3c3a71ae867aa983b772a77e32d1 +Subproject commit 217865f599234029ae8eaecc5ee025fe0658688e diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000000..e680e87aca --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,9 @@ +{ + "name": "main", + "version-string": "latest", + "dependencies": [ + "c-ares", + "libpcap", + "zlib" + ] +}