Skip to content

Commit

Permalink
(#2218) Added Gromac's Tng lib
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Apply suggestions from code review

Co-authored-by: Anonymous Maarten <[email protected]>

* Update recipes/tng/all/conanfile.py

Co-authored-by: Anonymous Maarten <[email protected]>

* Added patch to fix upstream's CMakeList.txt file

* Apply suggestions from code review

Co-authored-by: Uilian Ries <[email protected]>

* 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 <[email protected]>
Co-authored-by: Uilian Ries <[email protected]>
  • Loading branch information
3 people authored Dec 30, 2020
1 parent 0301daf commit d8c53b3
Show file tree
Hide file tree
Showing 9 changed files with 184 additions and 0 deletions.
7 changes: 7 additions & 0 deletions recipes/tng/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
10 changes: 10 additions & 0 deletions recipes/tng/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -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"
82 changes: 82 additions & 0 deletions recipes/tng/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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"
14 changes: 14 additions & 0 deletions recipes/tng/all/patches/0001-BuildTNG.patch
Original file line number Diff line number Diff line change
@@ -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")
14 changes: 14 additions & 0 deletions recipes/tng/all/patches/0002-CMakeLists.patch
Original file line number Diff line number Diff line change
@@ -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::
8 changes: 8 additions & 0 deletions recipes/tng/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
15 changes: 15 additions & 0 deletions recipes/tng/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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 )
31 changes: 31 additions & 0 deletions recipes/tng/all/test_package/example.c
Original file line number Diff line number Diff line change
@@ -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 <inttypes.h>
#endif

#include <stdlib.h>
#include <stdio.h>

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;
}
3 changes: 3 additions & 0 deletions recipes/tng/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.8.2":
folder: all

0 comments on commit d8c53b3

Please sign in to comment.