From 59044298eaf4b5de1150a4280097e6e524a63faa Mon Sep 17 00:00:00 2001 From: Florent Leclercq Date: Tue, 21 Mar 2023 20:53:51 +0100 Subject: [PATCH] packaged using conan create, added test_package --- README.md | 30 +++++++++++++---- conanfile.py | 58 +++++++++++++++++++++------------ include/elemmire.h | 10 ++++++ meson.build | 7 ++-- src/elemmire.c | 19 +++++++++++ src/main.c | 18 ++-------- test_package/conanfile.py | 41 +++++++++++++++++++++++ test_package/meson.build | 6 ++++ test_package/src/test_package.c | 19 +++++++++++ 9 files changed, 162 insertions(+), 46 deletions(-) create mode 100644 include/elemmire.h create mode 100644 src/elemmire.c create mode 100644 test_package/conanfile.py create mode 100644 test_package/meson.build create mode 100644 test_package/src/test_package.c diff --git a/README.md b/README.md index 2b72209..7dccf41 100644 --- a/README.md +++ b/README.md @@ -10,14 +10,30 @@ conda install -c conda-forge conan ``` conan profile detect --force ``` -* Install dependencies with conan +* To build the library locally: + * Install dependencies with conan + ``` + conan install . --build=missing + ``` + or for the debug version: + ``` + conan install . --build=missing --profile=debug + ``` + * Build with meson + ``` + cd build-realease + conan build .. + ``` + or for the debug version: + ``` + cd build-debug + conan build .. --profile=debug + ``` +* To create the package (i.e. build and install it in the conan cache ``~/.conan2``) ``` -conan install . --build=missing -conan install . --build=missing --profile=debug +conan create . --build=missing ``` -* Build with meson +or for the debug version: ``` -cd build -conan build . -conan build . --profile=debug +conan create . --build=missing --profile=debug ``` diff --git a/conanfile.py b/conanfile.py index e88ebcf..6bc5a27 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,30 +1,46 @@ +import os.path from conan import ConanFile from conan.tools.meson import Meson +from conan.tools.layout import basic_layout class ElemmireRecipe(ConanFile): - name = "Elemmire" - version = "0.1" - settings = "os", "compiler", "build_type", "arch" - generators = "PkgConfigDeps", "MesonToolchain" - exports_sources = "src/*" + name = "elemmire" + version = "0.1" - def requirements(self): - self.requires("fftw/[~3.3]") + # Optional metadata + license = "CECILL-2.1/GPL-3.0" + author = "The Aquila Consortium" + url = "https://bitbucket.org/aquila-consortium/elemmire" + description = "The Elemmire library" + topics = ("cosmology", "data analysis") - def build_requirements(self): - self.tool_requires("meson/[~1.0]") + # Binary configuration + generators = "PkgConfigDeps", "MesonToolchain" + settings = "os", "compiler", "build_type", "arch" + options = {"shared": [True, False], "fPIC": [True, False]} + default_options = {"shared": False, "fPIC": True} - def layout(self): - import os.path - from conan.tools.layout import basic_layout - basic_layout(self) - self.folders.build = os.path.join(self.folders.build, "meson") + # Location of sources + exports_sources = "meson.build", "include/*", "src/*" - def build(self): - meson = Meson(self) - meson.configure() - meson.build() + def requirements(self): + self.requires("fftw/[>=3.3.8]") - def package(self): - meson = Meson(self) - meson.install() + def build_requirements(self): + self.tool_requires("meson/[~1.0]") + + def layout(self): + basic_layout(self) + self.folders.build = os.path.join(self.folders.build, "meson") + + def build(self): + meson = Meson(self) + meson.configure() + meson.build() + + def package(self): + meson = Meson(self) + meson.install() + + def package_info(self): + self.cpp_info.libs = ["elemmire"] diff --git a/include/elemmire.h b/include/elemmire.h new file mode 100644 index 0000000..f8bb918 --- /dev/null +++ b/include/elemmire.h @@ -0,0 +1,10 @@ +#pragma once + + +#ifdef _WIN32 + #define ELEMMIRE_EXPORT __declspec(dllexport) +#else + #define ELEMMIRE_EXPORT +#endif + +ELEMMIRE_EXPORT int elemmire(int argc, char **argv) ; diff --git a/meson.build b/meson.build index 726a717..d79a024 100644 --- a/meson.build +++ b/meson.build @@ -2,7 +2,10 @@ project('Elemmire', 'c', version : '0.1', default_options : ['warning_level=3']) -fftw = dependency('fftw3', version : '3.3.9') -exe = executable('Elemmire', 'src/main.c', dependencies: fftw) +fftw = dependency('fftw3', version : '>=3.3.8') +incdir = include_directories('include') +lib = static_library('elemmire', 'src/elemmire.c', install: true, dependencies: fftw, include_directories: incdir) +exe = executable('elemmire', 'src/main.c', 'src/elemmire.c', dependencies: fftw, include_directories: incdir) +headers = install_headers('include/elemmire.h') test('basic', exe) diff --git a/src/elemmire.c b/src/elemmire.c new file mode 100644 index 0000000..7f85670 --- /dev/null +++ b/src/elemmire.c @@ -0,0 +1,19 @@ +#include +#include + +#define PROJECT_NAME "Elemmire" + +int elemmire(int argc, char **argv) { + if(argc != 1) { + printf("%s takes no arguments.\n", argv[0]); + return 1; + } + printf("This is project %s.\n", PROJECT_NAME); + + #ifdef NDEBUG + printf("%s has been compiled in 'Release' configuration.\n", PROJECT_NAME); + #else + printf("%s has been compiled in 'Debug' configuration.\n", PROJECT_NAME); + #endif + return 0; +} diff --git a/src/main.c b/src/main.c index a03cbc4..e3e08a0 100644 --- a/src/main.c +++ b/src/main.c @@ -1,19 +1,5 @@ -#include -#include - -#define PROJECT_NAME "Elemmire" +#include int main(int argc, char **argv) { - if(argc != 1) { - printf("%s takes no arguments.\n", argv[0]); - return 1; - } - printf("This is project %s.\n", PROJECT_NAME); - - #ifdef NDEBUG - printf("Release configuration!\n"); - #else - printf("Debug configuration!\n"); - #endif - return 0; + return elemmire(argc, argv); } diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 0000000..305cc05 --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,41 @@ +import os.path +from conan import ConanFile +from conan.tools.meson import Meson +from conan.tools.layout import basic_layout +from conan.tools.build import can_run + +class ElemmirePackageTestRecipe(ConanFile): + # Optional metadata + license = "CECILL-2.1/GPL-3.0" + author = "The Aquila Consortium" + url = "https://bitbucket.org/aquila-consortium/elemmire" + description = "The Elemmire library" + topics = ("cosmology", "data analysis") + + # Binary configuration + generators = "PkgConfigDeps", "MesonToolchain" + settings = "os", "compiler", "build_type", "arch" + + # Location of sources + exports_sources = "meson.build", "src/*" + + def requirements(self): + self.requires(self.tested_reference_str) + self.requires("fftw/[>=3.3.8]") + + def build_requirements(self): + self.tool_requires("meson/[~1.0]") + + def build(self): + meson = Meson(self) + meson.configure() + meson.build() + + def layout(self): + basic_layout(self) + self.folders.build = os.path.join(self.folders.build, "meson") + + def test(self): + if can_run(self): + cmd = os.path.join(self.cpp.build.bindir, "elemmire_test_package") + self.run(cmd, env="conanrun") diff --git a/test_package/meson.build b/test_package/meson.build new file mode 100644 index 0000000..6b60d62 --- /dev/null +++ b/test_package/meson.build @@ -0,0 +1,6 @@ +project('Elemmire', 'c', + version : '0.1', + default_options : ['warning_level=3']) + +fftw = dependency('fftw3', version : '>=3.3.8') +exe = executable('elemmire_test_package', 'src/test_package.c', dependencies: fftw) diff --git a/test_package/src/test_package.c b/test_package/src/test_package.c new file mode 100644 index 0000000..2f92e77 --- /dev/null +++ b/test_package/src/test_package.c @@ -0,0 +1,19 @@ +#include +#include + +#define PROJECT_NAME "Elemmire" + +int main(int argc, char **argv) { + if(argc != 1) { + printf("%s takes no arguments.\n", argv[0]); + return 1; + } + printf("This is the test_package executable of project %s.\n", PROJECT_NAME); + + #ifdef NDEBUG + printf("%s has been compiled in 'Release' configuration.\n", PROJECT_NAME); + #else + printf("%s has been compiled in 'Debug' configuration.\n", PROJECT_NAME); + #endif + return 0; +}