]> git.seodisparate.com - UDPConnection/commitdiff
Add conan related files and adapt CMakeLists.txt
authorStephen Seo <seo.disparate@gmail.com>
Fri, 12 Jul 2024 07:34:27 +0000 (16:34 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Sat, 13 Jul 2024 02:43:01 +0000 (11:43 +0900)
This is put in a new "conan" branch. Changes to the conan build process
will only occur on this branch.

.gitignore
CMakeLists.txt
conanfile.py [new file with mode: 0644]
test_package/CMakeLists.txt [new file with mode: 0644]
test_package/conanfile.py [new file with mode: 0644]
test_package/src/test.cpp [new file with mode: 0644]

index 3957bdb7ca93ccbdc4e4098e19b67849c66470d1..6ce0270a6c92b03a0d4c4ebfbb8daa33b03e405a 100644 (file)
@@ -4,3 +4,5 @@ compile_commands.json
 *.o
 doxygen_out/
 /tags
+
+CMakeUserPresets.json
index 4ed0671aef3babc5861f27d48fb3ea90a64da67f..3b226facd9a0bda5ef51c59fc27c161e6c77073b 100644 (file)
@@ -37,26 +37,9 @@ if(WIN32)
     endif()
 endif()
 
-if(UDPC_DISABLE_LIBSODIUM)
-    message(STATUS "libsodium disabled")
-elseif(DEFINED M_LIBSODIUM_LIBRARIES AND DEFINED M_LIBSODIUM_INCLUDE_DIRS)
-    message(STATUS "libsodium manual paths detected, using them")
-    target_compile_definitions(UDPC PUBLIC UDPC_LIBSODIUM_ENABLED)
-    target_link_libraries(UDPC PUBLIC ${M_LIBSODIUM_LIBRARIES})
-    target_include_directories(UDPC PUBLIC ${M_LIBSODIUM_INCLUDE_DIRS})
-else()
-    find_package(PkgConfig REQUIRED)
-    pkg_check_modules(LIBSODIUM QUIET libsodium)
-    if(LIBSODIUM_FOUND)
-        target_compile_definitions(UDPC PUBLIC UDPC_LIBSODIUM_ENABLED)
-        target_link_libraries(UDPC PUBLIC ${LIBSODIUM_LIBRARIES})
-        target_include_directories(UDPC PUBLIC ${LIBSODIUM_INCLUDE_DIRS})
-        target_compile_options(UDPC PUBLIC ${LIBSODIUM_CFLAGS_OTHER})
-        message(STATUS "libsodium enabled")
-    else()
-        message(STATUS "libsodium not found, UDPC will be compiled without libsodium support")
-    endif()
-endif()
+find_package(libsodium REQUIRED)
+target_compile_definitions(UDPC PUBLIC UDPC_LIBSODIUM_ENABLED)
+target_link_libraries(UDPC PUBLIC libsodium::libsodium)
 
 if(CMAKE_BUILD_TYPE MATCHES "Debug")
     set(UDPC_UnitTest_SOURCES
diff --git a/conanfile.py b/conanfile.py
new file mode 100644 (file)
index 0000000..3f293ba
--- /dev/null
@@ -0,0 +1,57 @@
+from conan import ConanFile
+from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
+import os
+
+
+class udpcRecipe(ConanFile):
+    name = "udpc"
+    version = "1.0"
+    package_type = "library"
+
+    # Optional metadata
+    license = "MIT"
+    author = "Stephen Seo stephen@seodisparate.com"
+    url = "https://git.seodisparate.com/stephenseo/UDPConnection"
+    description = "Implements a connection over UDP"
+    topics = ("UDPC", "UDP", "Network", "Network Connection")
+
+    # Binary configuration
+    settings = "os", "compiler", "build_type", "arch"
+    options = {"shared": [True, False], "fPIC": [True, False]}
+    default_options = {"shared": False, "fPIC": True}
+
+    # Sources are located in the same place as this recipe, copy them to the recipe
+    exports_sources = "CMakeLists.txt", "src/*"
+
+    def config_options(self):
+        if self.settings.os == "Windows":
+            self.options.rm_safe("fPIC")
+
+    def configure(self):
+        if self.options.shared:
+            self.options.rm_safe("fPIC")
+
+    def layout(self):
+        cmake_layout(self)
+
+    def requirements(self):
+        self.requires("libsodium/cci.20220430")
+
+    def generate(self):
+        deps = CMakeDeps(self)
+        deps.generate()
+        tc = CMakeToolchain(self)
+        tc.generate()
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def package(self):
+        cmake = CMake(self)
+        cmake.install()
+
+    def package_info(self):
+        self.cpp_info.libs = ["UDPC"]
+
diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt
new file mode 100644 (file)
index 0000000..ec4e9b7
--- /dev/null
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.15)
+project(PackageTest CXX)
+
+find_package(udpc CONFIG REQUIRED)
+
+add_executable(example src/test.cpp)
+target_link_libraries(example udpc::udpc)
diff --git a/test_package/conanfile.py b/test_package/conanfile.py
new file mode 100644 (file)
index 0000000..8ed1eda
--- /dev/null
@@ -0,0 +1,26 @@
+import os
+
+from conan import ConanFile
+from conan.tools.cmake import CMake, cmake_layout
+from conan.tools.build import can_run
+
+
+class udpcTestConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "CMakeDeps", "CMakeToolchain"
+
+    def requirements(self):
+        self.requires(self.tested_reference_str)
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def layout(self):
+        cmake_layout(self)
+
+    def test(self):
+        if can_run(self):
+            cmd = os.path.join(self.cpp.build.bindir, "example")
+            self.run(cmd, env="conanrun")
diff --git a/test_package/src/test.cpp b/test_package/src/test.cpp
new file mode 100644 (file)
index 0000000..e16f74b
--- /dev/null
@@ -0,0 +1,10 @@
+#include "UDPC.h"
+
+int main() {
+    auto ctx = UDPC_init(UDPC_create_id_easy("127.0.0.1", 0), 1, 1);
+    if (UDPC_is_valid_context(ctx) == 0) {
+        return 1;
+    }
+    UDPC_destroy(ctx);
+    return 0;
+}