diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a674f89..5ea1aa6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -2,35 +2,6 @@ stages: - build - deploy -bionic-build: - stage: build - image: pllee4/ubuntu-ci:18.04 - variables: - GIT_SUBMODULE_STRATEGY: recursive - before_script: - - apt-get install -y libeigen3-dev - script: - - mkdir build && cd build - - cmake .. - - cmake --build . - -bionic-staging: - stage: deploy - only: - - master - image: pllee4/ubuntu-ci:18.04 - variables: - GIT_SUBMODULE_STRATEGY: recursive - before_script: - - apt-get install -y libeigen3-dev - - conan remote add gitlab https://gitlab.com/api/v4/packages/conan - script: - # build conan package - - conan create . pinloon+public+algorithm/devel - - CONAN_LOGIN_USERNAME=ci_user CONAN_PASSWORD=${CI_JOB_TOKEN} conan upload algorithm/0.3.1@pinloon+public+algorithm/devel --all --remote=gitlab - dependencies: - - bionic-build - focal-build: stage: build image: pllee4/ubuntu-ci:20.04 @@ -52,10 +23,12 @@ focal-staging: GIT_SUBMODULE_STRATEGY: recursive before_script: - apt-get install -y libeigen3-dev - - conan remote add gitlab https://gitlab.com/api/v4/packages/conan + # Conan 2 only works with the project-level registry, not the instance-level one + - conan remote add gitlab ${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/conan script: # build conan package - - conan create . pinloon+public+algorithm/devel - - CONAN_LOGIN_USERNAME=ci_user CONAN_PASSWORD=${CI_JOB_TOKEN} conan upload algorithm/0.3.1@pinloon+public+algorithm/devel --all --remote=gitlab + - conan profile detect + - conan create . --user=pinloon+public+algorithm --channel=devel --build=missing + - CONAN_LOGIN_USERNAME=ci_user CONAN_PASSWORD=${CI_JOB_TOKEN} conan upload "algorithm/*@pinloon+public+algorithm/devel" --remote=gitlab -c dependencies: - focal-build \ No newline at end of file diff --git a/conanfile.py b/conanfile.py index 86b661f..3216f76 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,5 +1,7 @@ from conan import ConanFile from conan.tools.cmake import CMakeToolchain, CMakeDeps, CMake, cmake_layout +from conan.tools.files import collect_libs + class AlgorithmConan(ConanFile): name = "algorithm" @@ -8,22 +10,50 @@ class AlgorithmConan(ConanFile): author = "Pin Loon Lee" url = "https://github.com/pllee4/algorithm" description = "Algorithm" + # CMakeLists.txt hardcodes STATIC, so there is no shared variant to offer + package_type = "static-library" + + # Binary configuration settings = "os", "compiler", "build_type", "arch" - options = {"shared": [True, False]} - default_options = {"shared": False} - generators = "CMakeToolchain", "CMakeDeps" - exports_sources = "*" + options = {"fPIC": [True, False]} + default_options = {"fPIC": True} + + # Sources are located in the same place as this recipe, copy them to the recipe + # cmake/ holds algorithmConfig.cmake.in, third_party/ only satisfies the googletest check + exports_sources = "CMakeLists.txt", "cmake/*", "src/*", "include/*", "third_party/*" + + def config_options(self): + if self.settings.os == "Windows": + self.options.rm_safe("fPIC") + + def requirements(self): + # Public headers include , and algorithmConfig.cmake calls find_package(Eigen3) + self.requires("eigen/3.4.0", transitive_headers=True) def layout(self): - self.cpp.package.includedirs = ["include"] - self.cpp.package.libs = ["algorithm"] + cmake_layout(self) - def build(self, variables=["-DALGO_PACK=true"]): + def generate(self): + deps = CMakeDeps(self) + deps.generate() + tc = CMakeToolchain(self) + # Skip tests and coverage flags when packaging + tc.cache_variables["ALGO_PACK"] = True + tc.generate() + + def build(self): cmake = CMake(self) cmake.configure() cmake.build() - + def package(self): cmake = CMake(self) - cmake.configure() - cmake.install() \ No newline at end of file + cmake.install() + + def package_info(self): + # CMakeDeps writes algorithm-config.cmake into the consumer's install folder, + # so a consumer only needs that folder on CMAKE_PREFIX_PATH + self.cpp_info.set_property("cmake_file_name", "algorithm") + self.cpp_info.set_property("cmake_target_name", "pllee4::algorithm") + # Picks up whatever archives CMake installed, instead of hardcoding them + self.cpp_info.libs = collect_libs(self) \ No newline at end of file