From d8c53b38444072324b5f364a753c6fcde026e7bb Mon Sep 17 00:00:00 2001 From: Gavin Date: Wed, 30 Dec 2020 16:01:42 -0500 Subject: [PATCH] (#2218) Added Gromac's Tng lib * Added Gromac's TNG library * Fixed conan-center package requirements * Updated the test_package example - using an example provided by tng as the test_package - added a tng file * Apply suggestions from code review Co-authored-by: Anonymous Maarten * Apply suggestions from code review Co-authored-by: Anonymous Maarten * Update recipes/tng/all/conanfile.py Co-authored-by: Anonymous Maarten * Added patch to fix upstream's CMakeList.txt file * Apply suggestions from code review Co-authored-by: Uilian Ries * Updated minimum cmake version to 3.1 * Added patch to fix windows shared builds * Sources now pulled from Gitlab instead of Github * test_package is now smaller * Added FreeBSD * Fixed homepage -> gitlab Co-authored-by: Anonymous Maarten Co-authored-by: Uilian Ries --- recipes/tng/all/CMakeLists.txt | 7 ++ recipes/tng/all/conandata.yml | 10 +++ recipes/tng/all/conanfile.py | 82 +++++++++++++++++++ recipes/tng/all/patches/0001-BuildTNG.patch | 14 ++++ recipes/tng/all/patches/0002-CMakeLists.patch | 14 ++++ recipes/tng/all/test_package/CMakeLists.txt | 8 ++ recipes/tng/all/test_package/conanfile.py | 15 ++++ recipes/tng/all/test_package/example.c | 31 +++++++ recipes/tng/config.yml | 3 + 9 files changed, 184 insertions(+) create mode 100644 recipes/tng/all/CMakeLists.txt create mode 100644 recipes/tng/all/conandata.yml create mode 100644 recipes/tng/all/conanfile.py create mode 100644 recipes/tng/all/patches/0001-BuildTNG.patch create mode 100644 recipes/tng/all/patches/0002-CMakeLists.patch create mode 100644 recipes/tng/all/test_package/CMakeLists.txt create mode 100644 recipes/tng/all/test_package/conanfile.py create mode 100644 recipes/tng/all/test_package/example.c create mode 100644 recipes/tng/config.yml diff --git a/recipes/tng/all/CMakeLists.txt b/recipes/tng/all/CMakeLists.txt new file mode 100644 index 0000000000000..c986d294c7547 --- /dev/null +++ b/recipes/tng/all/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.1) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory("source_subfolder") diff --git a/recipes/tng/all/conandata.yml b/recipes/tng/all/conandata.yml new file mode 100644 index 0000000000000..8ab8469db669a --- /dev/null +++ b/recipes/tng/all/conandata.yml @@ -0,0 +1,10 @@ +sources: + "1.8.2": + url: "https://gitlab.com/gromacs/tng/-/archive/v1.8.2/tng-v1.8.2.tar.gz" + sha256: "7010eb68e586efe23dd553b306ac1a4eea6a4b9028b32a3408744d9e4ae4205e" +patches: + "1.8.2": + - base_path: "source_subfolder" + patch_file: "patches/0001-BuildTNG.patch" + - base_path: "source_subfolder" + patch_file: "patches/0002-CMakeLists.patch" diff --git a/recipes/tng/all/conanfile.py b/recipes/tng/all/conanfile.py new file mode 100644 index 0000000000000..ff859afc6db98 --- /dev/null +++ b/recipes/tng/all/conanfile.py @@ -0,0 +1,82 @@ +from conans import ConanFile, tools, CMake +import os +import glob + + +class tngConan(ConanFile): + name = "tng" + description = "External GROMACS library for loading tng files." + license = "BSD-3-Clause" + topics = ("conan", "tng", "gromacs") + homepage = "https://gitlab.com/gromacs/tng/" + url = "https://github.com/conan-io/conan-center-index" + exports_sources = ["CMakeLists.txt", "patches/*"] + generators = "cmake" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False] + } + default_options = { + "shared": False, + "fPIC": True + } + + requires = ( + "zlib/1.2.11" + ) + + _cmake = None + + @property + def _source_subfolder(self): + return "source_subfolder" + + @property + def _build_subfolder(self): + return "build_subfolder" + + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC + + def configure(self): + if self.options.shared: + del self.options.fPIC + del self.settings.compiler.libcxx + del self.settings.compiler.cppstd + + def source(self): + tools.get(**self.conan_data["sources"][self.version]) + url = self.conan_data["sources"][self.version]["url"] + extracted_dir = self.name + "-v" + self.version + os.rename(extracted_dir, self._source_subfolder) + + def build(self): + for patch in self.conan_data["patches"][self.version]: + tools.patch(**patch) + cmake = self._configure_cmake() + cmake.build() + + def _configure_cmake(self): + if self._cmake: + return self._cmake + self._cmake = CMake(self) + self._cmake.definitions["TNG_BUILD_OWN_ZLIB"] = False + self._cmake.definitions["TNG_BUILD_EXAMPLES"] = False + self._cmake.definitions["TNG_BUILD_TEST"] = False + self._cmake.configure(build_folder=self._build_subfolder) + return self._cmake + + def package(self): + self.copy("COPYING", dst="licenses", src=self._source_subfolder) + cmake = self._configure_cmake() + cmake.install() + tools.rmdir(os.path.join(self.package_folder, "lib", "cmake")) + + def package_info(self): + self.cpp_info.libs = ["tng_io"] + if self.settings.os in ("Linux", "FreeBSD"): + self.cpp_info.system_libs = ["m"] + self.cpp_info.names["cmake_find_package"] = "tng_io" + self.cpp_info.names["cmake_find_package_multi"] = "tng_io" diff --git a/recipes/tng/all/patches/0001-BuildTNG.patch b/recipes/tng/all/patches/0001-BuildTNG.patch new file mode 100644 index 0000000000000..01fbe6401a53b --- /dev/null +++ b/recipes/tng/all/patches/0001-BuildTNG.patch @@ -0,0 +1,14 @@ +--- BuildTNG.cmake ++++ BuildTNG.cmake +@@ -1,9 +1,9 @@ + set(TNG_ROOT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}) +-file(RELATIVE_PATH TNG_ROOT_BINARY_DIR ${CMAKE_SOURCE_DIR} ${TNG_ROOT_SOURCE_DIR}) ++file(RELATIVE_PATH TNG_ROOT_BINARY_DIR ${PROJECT_SOURCE_DIR} ${TNG_ROOT_SOURCE_DIR}) + if ("${TNG_ROOT_BINARY_DIR}" MATCHES "^\.\.") + set(TNG_ROOT_BINARY_DIR tng) + endif() +-set(TNG_ROOT_BINARY_DIR ${CMAKE_BINARY_DIR}/${TNG_ROOT_BINARY_DIR}) ++set(TNG_ROOT_BINARY_DIR ${PROJECT_BINARY_DIR}/${TNG_ROOT_BINARY_DIR}) + + set(TNG_MAJOR_VERSION "1") + set(TNG_MINOR_VERSION "8") diff --git a/recipes/tng/all/patches/0002-CMakeLists.patch b/recipes/tng/all/patches/0002-CMakeLists.patch new file mode 100644 index 0000000000000..b2fd6394cad25 --- /dev/null +++ b/recipes/tng/all/patches/0002-CMakeLists.patch @@ -0,0 +1,14 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index bc6f8fd..602630e 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -47,7 +47,8 @@ configure_file( src/lib/tng_io-configVersion.cmake.in + install(TARGETS tng_io + EXPORT tng_io + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}") ++ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" ++ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + + install(EXPORT tng_io FILE tng_io.cmake + NAMESPACE tng_io:: diff --git a/recipes/tng/all/test_package/CMakeLists.txt b/recipes/tng/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..39577ef2fd99f --- /dev/null +++ b/recipes/tng/all/test_package/CMakeLists.txt @@ -0,0 +1,8 @@ +cmake_minimum_required(VERSION 3.1) +project(test_package) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_executable(${PROJECT_NAME} example.c) +target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) diff --git a/recipes/tng/all/test_package/conanfile.py b/recipes/tng/all/test_package/conanfile.py new file mode 100644 index 0000000000000..be0682b4fbace --- /dev/null +++ b/recipes/tng/all/test_package/conanfile.py @@ -0,0 +1,15 @@ +import os +from conans import ConanFile, CMake, tools + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def test(self): + if not tools.cross_building(self.settings): + self.run( os.path.join("bin", "test_package"), run_environment=True ) diff --git a/recipes/tng/all/test_package/example.c b/recipes/tng/all/test_package/example.c new file mode 100644 index 0000000000000..4011fcb512236 --- /dev/null +++ b/recipes/tng/all/test_package/example.c @@ -0,0 +1,31 @@ +/* This code is part of the tng binary trajectory format. + * + * Written by Magnus Lundborg + * Copyright (c) 2012-2013, The GROMACS development team. + * check out http://www.gromacs.org for more information. + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the Revised BSD License. + */ + +#include "tng/tng_io.h" + +#ifdef USE_STD_INTTYPES_H +#include +#endif + +#include +#include + +int main(int argc, char **argv) +{ + tng_trajectory_t traj; + if(tng_trajectory_init(&traj) != TNG_SUCCESS) + { + tng_trajectory_destroy(&traj); + exit(1); + } + tng_trajectory_destroy(&traj); + return 0; +} diff --git a/recipes/tng/config.yml b/recipes/tng/config.yml new file mode 100644 index 0000000000000..cf85ed78b488c --- /dev/null +++ b/recipes/tng/config.yml @@ -0,0 +1,3 @@ +versions: + "1.8.2": + folder: all