Skip to content

Commit

Permalink
Add GMTL - Generic Math Template Library recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
psyinf committed Oct 21, 2022
1 parent a7ee4fb commit ea9a504
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 0 deletions.
8 changes: 8 additions & 0 deletions recipes/gmtl/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
sources:
# Newer versions at the top
"0.7.1":
url: [
"https://github.com/psyinf/gmtl/archive/refs/tags/0.7.1.tar.gz",
]
sha256: "abaf1fcbc70ed0e72b313c0a1e526117ccf889edf732b994221f82151c4a8fbe"

76 changes: 76 additions & 0 deletions recipes/gmtl/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy
from conan.tools.build import check_min_cppstd
from conan.tools.scm import Version
from conan.tools.layout import basic_layout
import os


required_conan_version = ">=1.52.0"


class PackageConan(ConanFile):
name = "gmtl"
description = "Generic Math Template Library"
# Use short name only, conform to SPDX License List: https://spdx.org/licenses/
# In case not listed there, use "LicenseRef-<license-file-name>"
license = "LGPL"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://ggt.sourceforge.net/html/main.html"
# no "conan" and project name in topics. Use topics from the upstream listed on GH
# Keep 'hearder-only' as topic
topics = ("linear-algebra", "collision", "vector", "matrix", "template", "math", "header-only")
settings = "os", "arch", "compiler", "build_type" # even for header only
no_copy_source = True # do not copy sources to build folder for header only projects, unless, need to apply patches

# no exports_sources attribute, but export_sources(self) method instead
# this allows finer grain exportation of patches per version
def export_sources(self):
export_conandata_patches(self)

def layout(self):
# src_folder must use the same source folder name the project
basic_layout(self, src_folder="gmtl")

def requirements(self):
# prefer self.requires method instead of requires attribute
return

# same package ID for any package
def package_id(self):
self.info.clear()

def validate(self):
# compiler subsettings are not available when building with self.info.clear()
return

# if another tool than the compiler or CMake is required to build the project (pkgconf, bison, flex etc)
def build_requirements(self):
return

def source(self):
# download source package and extract to source folder
get(self, **self.conan_data["sources"][self.version], destination=self.source_folder, strip_root=True)

# not mandatory when there is no patch, but will suppress warning message about missing build() method
def build(self):
# The attribute no_copy_source should not be used when applying patches in build
apply_conandata_patches(self)

# copy all files to the package folder
def package(self):
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(
self,
pattern="*.h",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "."),
)

def package_info(self):
# folders not used for header-only
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []


12 changes: 12 additions & 0 deletions recipes/gmtl/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.8)

project(test_package C) # if the project is pure C
project(test_package CXX) # if the project uses c++

find_package(gmtl REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
# don't link to ${CONAN_LIBS} or CONAN_PKG::package
target_link_libraries(${PROJECT_NAME} PRIVATE gmtl::gmtl)
# In case the target project need a specific C++ standard
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
27 changes: 27 additions & 0 deletions recipes/gmtl/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.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
16 changes: 16 additions & 0 deletions recipes/gmtl/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <cstdlib>
#include <iostream>
#include "gmtl/gmtl.h"


int main(void) {

gmtl::Vec4f homogeneousVec;
gmtl::Vec4f homogeneousVec2;
gmtl::Matrix44f mat;

homogeneousVec2 = mat * homogeneousVec;

gmtl::xform(homogeneousVec2, mat, homogeneousVec);
return EXIT_SUCCESS;
}
16 changes: 16 additions & 0 deletions recipes/gmtl/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 3.8)

project(test_package C) # if the project is pure C
project(test_package CXX) # if the project uses c++

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

find_package(gmtl REQUIRED CONFIG)

# Re-use the same source file from test_package folder
add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
# don't link to ${CONAN_LIBS} or CONAN_PKG::package
target_link_libraries(${PROJECT_NAME} PRIVATE gmtl::gmtl)
# in case the target project requires a C++ standard
target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_14)
19 changes: 19 additions & 0 deletions recipes/gmtl/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake
from conan.tools.build import cross_building
import os


# legacy validation with Conan 1.x
class TestPackageV1Conan(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 cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
4 changes: 4 additions & 0 deletions recipes/gmtl/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
versions:
# Newer versions at the top
"0.7.1":
folder: all

0 comments on commit ea9a504

Please sign in to comment.