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

llnl-units: Add 0.9.1 to conan center index #24459

Merged
merged 10 commits into from
Jul 18, 2024
Merged
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
4 changes: 4 additions & 0 deletions recipes/llnl-units/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"0.9.1":
url: "https://github.com/LLNL/units/archive/refs/tags/v0.9.1.tar.gz"
sha256: "7edb83613a07cf55873f22d61c0062e46db6f8cb27d137866858811ec2e1ad4f"
103 changes: 103 additions & 0 deletions recipes/llnl-units/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain
from conan.tools.files import copy, rm, rmdir, get


class UnitsConan(ConanFile):
name = "llnl-units"
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://units.readthedocs.io"
description = (
"A run-time C++ library for working with units "
"of measurement and conversions between them "
"and with string representations of units "
"and measurements"
)
topics = (
"units",
"dimensions",
"quantities",
"physical-units",
"dimensional-analysis",
"run-time",
)
settings = "os", "compiler", "build_type", "arch"
package_type = "library"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

@property
def _min_cppstd(self):
return 14

@property
def _compilers_minimum_version(self):
return {
"apple-clang": "10",
"clang": "7",
"gcc": "7",
"msvc": "191",
"Visual Studio": "15",
}

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

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

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

def generate(self):
tc = CMakeToolchain(self)
tc.preprocessor_definitions["UNITS_CMAKE_PROJECT_NAME"] = "LLNL-UNITS"
tc.preprocessor_definitions["UNITS_ENABLE_TESTS"] = "OFF"
tc.preprocessor_definitions["UNITS_BUILD_SHARED_LIBRARY"] = self.options.shared
tc.preprocessor_definitions[
"UNITS_BUILD_STATIC_LIBRARY"
] = not self.options.shared
tc.generate()

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

def package(self):
copy(
self,
"LICENSE",
self.source_folder,
os.path.join(self.package_folder, "licenses"),
)
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "share"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "lib"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.libs = ["units"]
namespace = self.conf.get("user.llnl-units:namespace", check_type=str)
base_type = self.conf.get("user.llnl-units:base_type", check_type=str, default="uint32_t")
self.cpp_info.defines = [f"UNITS_BASE_TYPE={base_type}"]
if namespace:
self.cpp_info.defines.append(f"UNITS_NAMESPACE={units_namespace}")

Check failure on line 100 in recipes/llnl-units/all/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Undefined variable 'units_namespace'

self.cpp_info.set_property("cmake_file_name", "units")
self.cpp_info.set_property("cmake_target_name", "units::units")
10 changes: 10 additions & 0 deletions recipes/llnl-units/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.15)

project(test_package LANGUAGES CXX)

find_package(units REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)

target_link_libraries(${PROJECT_NAME} PRIVATE units::units)
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
27 changes: 27 additions & 0 deletions recipes/llnl-units/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os


# It will become the standard on Conan 2.x
class TestPackageConan(ConanFile):
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 build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
20 changes: 20 additions & 0 deletions recipes/llnl-units/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <cstdlib>
#include <iostream>
#include "units/units.hpp"
using namespace units;

int main(void) {
auto new_unit=m/s;
auto another=new_unit*s;
bool test = another == m;
std::cout << test << std::endl;

measurement length1=45.0*m;
measurement length2=20.0*m;
measurement result=900.0*m*m;
measurement area=length1*length2;
bool test2 = area == result;
std::cout << test2 << std::endl;

return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/llnl-units/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"0.9.1":
folder: all
Loading