Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Gromac's Tng lib #2218

Merged
merged 14 commits into from
Dec 30, 2020
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
GavinNL marked this conversation as resolved.
Show resolved Hide resolved
self._cmake.definitions["TNG_BUILD_EXAMPLES"] = False
self._cmake.definitions["TNG_BUILD_TEST"] = False
self._cmake.configure(build_folder=self._build_subfolder)

This comment was marked as outdated.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this problem is caused by these lines in BuildTNG.cmake:

CMAKE_SOURCE_DIR and CMAKE_BUILD_DIR should be PROJECT_SOURCE_DIR and PROJECT_BINARY_DIR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured it would be an issue with the project's cmake file. Not sure what I should do about it, should we apply a patch? My preference is to not edit the original if I can avoid it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change would be equivalent to your move of sources.
The advantage of patching is that, when upstream fixes this problem, the patch can simply be dropped without modifying the recipe.

Copy link
Contributor

@madebr madebr Jul 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested it locally.
This patch avoids any special actions in the _configure_cmake function:

--- 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")

I think upstream would be happy to apply this.
Because right now, it could not be included as a subproject.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I added it as a patch.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've opened an issue with the patch at gromacs/tng#1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if anyone is even bothering to look at the issues in the original project. I don't think that library has changed in many years

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's up to them to accept or not...

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"]
GavinNL marked this conversation as resolved.
Show resolved Hide resolved
GavinNL marked this conversation as resolved.
Show resolved Hide resolved
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we like to have much move minimal test_packages... I idea it to make sure the conan packing went well no so much the library is functional.

could you please try to reduce this to a few lines? example instantiate a few objects?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used an example piece of code from the library to create the test_package.c, figured it would be a good way to test it.

I will reduce it.

{
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