Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spectra: add v1.1.0, use cmake.install(), simplify test_package #26357

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions recipes/spectra/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
sources:
"1.1.0":
url: "https://github.com/yixuan/spectra/archive/refs/tags/v1.1.0.tar.gz"
sha256: "d29671e3d1b8036728933cadfddb05668a3cd6133331e91fc4535a9b85bedc79"
"1.0.1":
url: "https://github.com/yixuan/spectra/archive/refs/tags/v1.0.1.tar.gz"
sha256: "919e3fbc8c539a321fd5a0766966922b7637cc52eb50a969241a997c733789f3"
Expand Down
27 changes: 16 additions & 11 deletions recipes/spectra/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.files import copy, get
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.cmake.cmakedeps.cmakedeps import CMakeDeps
from conan.tools.files import copy, get, rmdir
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os
Expand Down Expand Up @@ -30,18 +32,27 @@ def package_id(self):

def validate(self):
if Version(self.version) >= "1.0.0":
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)
check_min_cppstd(self, 11)

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

def generate(self):
tc = CMakeToolchain(self)
tc.generate()
deps = CMakeDeps(self)
deps.generate()

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

def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, "*.h", src=os.path.join(self.source_folder, "include"), dst=os.path.join(self.package_folder, "include"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "spectra")
Expand All @@ -50,9 +61,3 @@ def package_info(self):
self.cpp_info.libdirs = []
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")

# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.filenames["cmake_find_package"] = "spectra"
self.cpp_info.filenames["cmake_find_package_multi"] = "spectra"
self.cpp_info.names["cmake_find_package"] = "Spectra"
self.cpp_info.names["cmake_find_package_multi"] = "Spectra"
7 changes: 1 addition & 6 deletions recipes/spectra/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.15)
project(test_package LANGUAGES CXX)

find_package(spectra REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PRIVATE Spectra::Spectra)
if(spectra_VERSION VERSION_LESS "1.0.0")
target_compile_definitions(${PROJECT_NAME} PRIVATE "SPECTRA_LESS_1_0_0")
else()
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_11)
endif()
5 changes: 2 additions & 3 deletions recipes/spectra/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

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

def layout(self):
cmake_layout(self)
Expand All @@ -22,5 +21,5 @@ def build(self):

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
37 changes: 1 addition & 36 deletions recipes/spectra/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
#include <Eigen/Core>
#include <Spectra/SymEigsSolver.h>

#include <iostream>

int main() {
// We are going to calculate the eigenvalues of M
Eigen::MatrixXd A = Eigen::MatrixXd::Random(10, 10);
Eigen::MatrixXd M = A + A.transpose();

// Construct matrix operation object using the wrapper class DenseSymMatProd
Spectra::DenseSymMatProd<double> op(M);

// Construct eigen solver object, requesting the largest three eigenvalues
#ifdef SPECTRA_LESS_1_0_0
Spectra::SymEigsSolver< double, Spectra::LARGEST_ALGE, Spectra::DenseSymMatProd<double> > eigs(&op, 3, 6);
#else
Spectra::SymEigsSolver<Spectra::DenseSymMatProd<double>> eigs(op, 3, 6);
#endif

// Initialize and compute
eigs.init();
#ifdef SPECTRA_LESS_1_0_0
int nconv = eigs.compute();
#else
int nconv = eigs.compute(Spectra::SortRule::LargestAlge);
#endif

// Retrieve results
Eigen::VectorXd evalues;
#ifdef SPECTRA_LESS_1_0_0
if (eigs.info() == Spectra::SUCCESSFUL) {
#else
if (eigs.info() == Spectra::CompInfo::Successful) {
#endif
evalues = eigs.eigenvalues();
}

std::cout << "Eigenvalues found:\n" << evalues << std::endl;

return 0;
Spectra::DenseSymMatProd<double> op(A);
}
2 changes: 2 additions & 0 deletions recipes/spectra/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"1.1.0":
folder: "all"
"1.0.1":
folder: "all"
"1.0.0":
Expand Down