From f5dc8df8945d7f5785956523795d7e75419ded4e Mon Sep 17 00:00:00 2001 From: Ayoub Kaanich Date: Tue, 9 Jul 2024 10:56:14 +0200 Subject: [PATCH] upgrade conan (#20) * fix build error * Upgrade conan * Fix build * Check versions * Fix case * Use conan to install --------- Co-authored-by: rawia.moalla --- .github/workflows/cmake.yml | 18 +++++++-------- apps/CMakeLists.txt | 30 +++++++++--------------- apps/app.cpp | 4 ++-- conanfile.py | 46 +++++++++++++++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 31 deletions(-) create mode 100644 conanfile.py diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 5f0587d..2274355 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -15,23 +15,21 @@ jobs: include: - os: windows-latest - os: ubuntu-latest - - os: macos-11 + - os: macos-12 steps: - uses: actions/checkout@v4 - uses: actions/setup-python@v4 - - run: pip3 install wheel conan==1.61.0 + - run: | + pip3 install wheel conan==2.5.0 + conan --version + cmake --version - - name: Create Build Environment - run: cmake -E make_directory build - - - name: Configure CMake - working-directory: build - run: cmake .. -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + - name: Create conan profile + run: conan profile detect - name: Build - working-directory: build - run: cmake --build . --config ${{env.BUILD_TYPE}} + run: conan build . --build missing -s:a=build_type=${{env.BUILD_TYPE}} - name: Test working-directory: build diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 95c9caa..ebe19f3 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -1,25 +1,10 @@ -cmake_minimum_required(VERSION 3.9) - -list(APPEND CMAKE_PREFIX_PATH ${CMAKE_CURRENT_BINARY_DIR}) - -if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake") - file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/0.18.1/conan.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/conan.cmake") -endif() - -include(${CMAKE_CURRENT_BINARY_DIR}/conan.cmake) - -conan_cmake_run( - REQUIRES pcapplusplus/22.05 - GENERATORS CMakeDeps - BUILD missing -) +cmake_minimum_required(VERSION 3.17) add_executable(tecmp_app "app.cpp") -find_package(pcapplusplus REQUIRED CONFIG) +find_package(PcapPlusPlus REQUIRED) -target_link_libraries(tecmp_app PRIVATE tecmp_library pcapplusplus::pcapplusplus) -target_compile_features(tecmp_app PRIVATE cxx_std_17) +target_link_libraries(tecmp_app PUBLIC tecmp_library PcapPlusPlus::PcapPlusPlus) +target_compile_features(tecmp_app PUBLIC cxx_std_17) add_test( NAME "tecmp_app.test" @@ -27,3 +12,10 @@ add_test( "${CMAKE_CURRENT_LIST_DIR}/../traces/input_eth.pcap" "${CMAKE_CURRENT_LIST_DIR}/../traces/output_eth.pcap" ) + +install( + TARGETS tecmp_app DESTINATION "." + RUNTIME DESTINATION bin + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib +) diff --git a/apps/app.cpp b/apps/app.cpp index b53a306..e5eae95 100644 --- a/apps/app.cpp +++ b/apps/app.cpp @@ -6,7 +6,7 @@ #include #include #include -#include "PcapFileDevice.h" +#include "pcapplusplus/PcapFileDevice.h" #include using namespace pcpp; @@ -86,7 +86,7 @@ int main(int argc, char* argv[]) { res = tecmp_next(p.getRawData(), p.getRawDataLen(), &iterator, &header, &data); } } - + } reader->close(); writer.close(); diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..be3aabf --- /dev/null +++ b/conanfile.py @@ -0,0 +1,46 @@ +from conan import ConanFile +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps + + +class TecmpAppRecipe(ConanFile): + name = "tecmp_app" + version = "0.1" + package_type = "application" + + # Optional metadata + license = "" + author = " " + url = "" + description = "" + topics = ("", "", "") + + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + + # Sources are located in the same place as this recipe, copy them to the recipe + exports_sources = "CMakeLists.txt", "src/*" + + package_folder = "../dist" + + def requirements(self): + self.requires("pcapplusplus/23.09") + + def layout(self): + cmake_layout(self) + + def generate(self): + deps = CMakeDeps(self) + deps.generate() + tc = CMakeToolchain(self) + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + cmake.install() + + def package(self): + cmake = CMake(self) + cmake.install() +