1- from conans import ConanFile , tools
2- from conan .tools .cmake import CMake , CMakeToolchain , cmake_layout
1+ from conan import ConanFile
2+ from conan .tools .build import can_run , check_min_cppstd
3+ from conan .tools .cmake import CMake , cmake_layout
4+ from conan .tools .files import copy , update_conandata
5+ from conan .tools .scm import Git
36
4-
5- from os import path
7+ import os
68
79
810class MathConan (ConanFile ):
@@ -15,19 +17,71 @@ class MathConan(ConanFile):
1517 url = "https://github.com/Adnn/math"
1618 description = "A mathematic library implementation, first concentrating on linear algrebra."
1719 topics = ("math" , "linear algebra" , "geometry" , "graphics" ,)
20+
1821 settings = ("os" , "compiler" , "build_type" , "arch" )
19- options = {
20- "shared" : [True , False ],
21- "build_tests" : [True , False ],
22- }
23- default_options = {
24- "shared" : False ,
25- "build_tests" : False ,
26- }
27-
28- build_policy = "missing"
22+ options = {}
23+ default_options = {}
24+
2925 generators = "CMakeDeps" , "CMakeToolchain"
26+ revision_mode = "scm"
27+
28+
29+ def validate (self ):
30+ if self .settings .compiler .get_safe ("cppstd" ):
31+ check_min_cppstd (self , "20" )
32+
33+
34+ # Note: We expect the profile to require it in a specific version
35+ # but having it here makes it simpler for external users.
36+ def build_requirements (self ):
37+ self .tool_requires ("cmake/[>=3.23]" )
38+
39+
40+ def layout (self ):
41+ # The root of the project is one level above
42+ self .folders .root = ".."
43+ cmake_layout (self )
44+
45+
46+ def export (self ):
47+ git = Git (self , self .recipe_folder )
48+ # Save the url and commit in conandata.yml
49+ # Unsafe atm since it is missing the repository argument,
50+ # so we save the coordinates manually
51+ #git.coordinates_to_conandata()
52+ url , commit = git .get_url_and_commit (repository = True )
53+ update_conandata (self , {"scm" : {"url" : url , "commit" : commit }})
54+
55+
56+ def source (self ):
57+ # recover the url and commit from conandata.yml, use them to get sources
58+ git = Git (self )
59+ git .checkout_from_conandata_coordinates ()
60+ git .run ("submodule update --init" )
61+
62+
63+ def build (self ):
64+ cmake = CMake (self )
65+ cmake .configure ()
66+ cmake .build ()
67+ if can_run (self ):
68+ cmake .test ()
69+
70+
71+ def package (self ):
72+ cmake = CMake (self )
73+ cmake .install ()
74+ copy (self , "LICENSE" , src = self .source_folder , dst = os .path .join (self .package_folder , "licenses" ))
75+
3076
77+ def package_info (self ):
78+ # Let's bite the bullet and repeate ourselve with a complete cpp_info,
79+ # waiting for sufficent Common Package Specification support in Conan an CMake.
80+ ## Disable the config package that would otherwise be generated by CMakeDeps
81+ #self.cpp_info.set_property("cmake_find_mode", "none")
82+ ## Find CMake-generated package config when consuming the (installed) conan package
83+ #self.cpp_info.builddirs = [os.path.join("lib", "cmake")]
3184
32- python_requires = "shred_conan_base/0.0.5@adnn/stable"
33- python_requires_extend = "shred_conan_base.ShredBaseConanFile"
85+ self .cpp_info .set_property ("cmake_find_mode" , "config" )
86+ self .cpp_info .components ["math" ].set_property ("cmake_target_name" , "ad::math" )
87+ self .cpp_info .components ["math" ].includedirs = ["include/math" ]
0 commit comments