Skip to content

Commit

Permalink
(#14294) qpoases: conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceIm authored Nov 28, 2022
1 parent 2822fb5 commit 5300373
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 57 deletions.
7 changes: 0 additions & 7 deletions recipes/qpoases/all/CMakeLists.txt

This file was deleted.

61 changes: 27 additions & 34 deletions recipes/qpoases/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,59 +1,52 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get
import os
from conans import ConanFile, CMake, tools

required_conan_version = ">=1.46.0"


class ConanRecipe(ConanFile):
name = "qpoases"

description = "Open-source C++ implementation of the recently proposed online active set strategy."
topics = ("conan", "container", "parametric", "quadratic", "programming")

topics = ("container", "parametric", "quadratic", "programming")
homepage = "https://github.com/coin-or/qpOASES"
url = "https://github.com/conan-io/conan-center-index"

license = "LGPL-2.1"

exports_sources = ["CMakeLists.txt"]
generators = "cmake"

settings = "os", "arch", "compiler", "build_type"
options = {"fPIC": [True, False]}
default_options = {"fPIC": True}

_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"
options = {
"fPIC": [True, False],
}
default_options = {
"fPIC": True,
}

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

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

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = "qpOASES-releases-" + self.version
os.rename(extracted_dir, self._source_subfolder)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["QPOASES_BUILD_EXAMPLES"] = False
self._cmake.configure()
return self._cmake
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["QPOASES_BUILD_EXAMPLES"] = False
tc.generate()

def build(self):
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "qpOASES"
self.cpp_info.names["cmake_find_package_multi"] = "qpOASES"

self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.libs = ["qpOASES"]
14 changes: 4 additions & 10 deletions recipes/qpoases/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package CXX)
project(test_package LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
find_package(qpoases REQUIRED CONFIG)

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

find_package(qpOASES REQUIRED)

add_executable(test_package test_package.cpp)

target_link_libraries(test_package PRIVATE qpOASES::qpOASES)
add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE qpoases::qpoases)
21 changes: 15 additions & 6 deletions recipes/qpoases/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os

from conans import ConanFile, CMake, tools

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

def layout(self):
cmake_layout(self)

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

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
8 changes: 8 additions & 0 deletions recipes/qpoases/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
17 changes: 17 additions & 0 deletions recipes/qpoases/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

0 comments on commit 5300373

Please sign in to comment.