Skip to content

Commit

Permalink
modernize more for conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm committed Jan 16, 2023
1 parent 812bd61 commit 84eded1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 49 deletions.
43 changes: 22 additions & 21 deletions recipes/libsvm/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import stdcpp_library
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import get, copy

from conan.tools.microsoft import is_msvc, is_msvc_static_runtime
import os

required_conan_version = ">=1.52.0"
required_conan_version = ">=1.54.0"


class libsvmConan(ConanFile):
name = "libsvm"
Expand All @@ -17,40 +19,35 @@ class libsvmConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False]
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True
"fPIC": True,
}

def export_sources(self):
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC

def validate(self):
if (
self.settings.compiler == "Visual Studio" and
"MT" in self.settings.compiler.runtime and
self.options.shared
):
raise ConanInvalidConfiguration(
f"{self.name} can not be built as shared library + runtime {self.settings.compiler.runtime}."
)
self.options.rm_safe("fPIC")

def layout(self):
cmake_layout(self, src_folder="src")

def export_sources(self):
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
def validate(self):
if self.options.shared and is_msvc(self) and is_msvc_static_runtime(self):
raise ConanInvalidConfiguration(
f"{self.ref} can not be built as shared library with Visual Studio and static runtime"
)

def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
Expand All @@ -69,5 +66,9 @@ def package(self):

def package_info(self):
self.cpp_info.libs = ["svm"]
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs = ["m"]
if not self.options.shared:
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
libcxx = stdcpp_library(self)
if libcxx:
self.cpp_info.system_libs.append(libcxx)
4 changes: 2 additions & 2 deletions recipes/libsvm/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest CXX)
project(test_package LANGUAGES C)

find_package(libsvm CONFIG REQUIRED)

add_executable(test_package test_package.cpp)
add_executable(test_package test_package.c)
target_link_libraries(test_package PRIVATE libsvm::libsvm)
8 changes: 4 additions & 4 deletions recipes/libsvm/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import os

class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
Expand Down
19 changes: 19 additions & 0 deletions recipes/libsvm/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <svm/svm.h>

#include <stdio.h>
#include <stdlib.h>

struct svm_parameter param;

int main(int argc, char **argv)
{
param.svm_type = C_SVC;
param.kernel_type = PRECOMPUTED;

//Allocate some dummy data
param.weight = (double*)malloc(10 * sizeof(double));
svm_destroy_param(&param);

printf("libsvm version %d test_package OK \n", LIBSVM_VERSION);
return 0;
}
17 changes: 0 additions & 17 deletions recipes/libsvm/all/test_package/test_package.cpp

This file was deleted.

8 changes: 3 additions & 5 deletions recipes/libsvm/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(PackageTest CXX)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(libsvm CONFIG REQUIRED)

add_executable(test_package ../test_package/test_package.cpp)
target_link_libraries(test_package PRIVATE libsvm::libsvm)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)

0 comments on commit 84eded1

Please sign in to comment.