Add conan related files and adapt CMakeLists.txt
This is put in a new "conan" branch. Changes to the conan build process will only occur on this branch.
This commit is contained in:
parent
bc6c1e4ca1
commit
35db9faeeb
6 changed files with 105 additions and 20 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,3 +4,5 @@ compile_commands.json
|
||||||
*.o
|
*.o
|
||||||
doxygen_out/
|
doxygen_out/
|
||||||
/tags
|
/tags
|
||||||
|
|
||||||
|
CMakeUserPresets.json
|
||||||
|
|
|
@ -37,26 +37,9 @@ if(WIN32)
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(UDPC_DISABLE_LIBSODIUM)
|
find_package(libsodium REQUIRED)
|
||||||
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_compile_definitions(UDPC PUBLIC UDPC_LIBSODIUM_ENABLED)
|
||||||
target_link_libraries(UDPC PUBLIC ${M_LIBSODIUM_LIBRARIES})
|
target_link_libraries(UDPC PUBLIC libsodium::libsodium)
|
||||||
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()
|
|
||||||
|
|
||||||
if(CMAKE_BUILD_TYPE MATCHES "Debug")
|
if(CMAKE_BUILD_TYPE MATCHES "Debug")
|
||||||
set(UDPC_UnitTest_SOURCES
|
set(UDPC_UnitTest_SOURCES
|
||||||
|
|
57
conanfile.py
Normal file
57
conanfile.py
Normal file
|
@ -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"]
|
||||||
|
|
7
test_package/CMakeLists.txt
Normal file
7
test_package/CMakeLists.txt
Normal file
|
@ -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)
|
26
test_package/conanfile.py
Normal file
26
test_package/conanfile.py
Normal file
|
@ -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")
|
10
test_package/src/test.cpp
Normal file
10
test_package/src/test.cpp
Normal file
|
@ -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;
|
||||||
|
}
|
Loading…
Reference in a new issue