-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* working recipe, shared not working though * fixed shared build * fixed system libs and added fslio option * added license, removed comments and disabled tests * fixed homepage and removed unused stuff * incorperated requested changes * forgot one change... * added msvc shared being unsupported to validate * Force static-library for Windows * Revert "Force static-library for Windows" This reverts commit d23de31. * Update recipes/nifti_clib/all/conanfile.py Co-authored-by: Uilian Ries <uilianries@gmail.com> --------- Co-authored-by: Rubén Rincón Blanco <git@rinconblanco.es> Co-authored-by: Uilian Ries <uilianries@gmail.com>
- Loading branch information
1 parent
653cc79
commit 1292b47
Showing
6 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
sources: | ||
"3.0.0": | ||
url: "https://github.com/NIFTI-Imaging/nifti_clib/archive/refs/tags/v3.0.0.tar.gz" | ||
sha256: "fe6cb1076974df01844f3f4dab1aa844953b3bc1d679126c652975158573d03d" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout | ||
from conan.tools.files import copy, get, rm, rmdir | ||
from conan.tools.microsoft import is_msvc, is_msvc_static_runtime | ||
import os | ||
|
||
|
||
required_conan_version = ">=1.53.0" | ||
|
||
|
||
class NiftiClibConan(ConanFile): | ||
name = "nifti_clib" | ||
description = "C libraries for NIFTI support" | ||
license = "LicenseRef-LICENSE" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://github.com/NIFTI-Imaging/nifti_clib" | ||
topics = ("image") | ||
package_type = "library" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"shared": [True, False], | ||
"fPIC": [True, False], | ||
"use_nifti2": [True, False], | ||
"use_cifti": [True, False], | ||
"use_fslio": [True, False] | ||
} | ||
default_options = { | ||
"shared": False, | ||
"fPIC": True, | ||
"use_nifti2": True, | ||
"use_cifti": False, # seems to be beta? | ||
"use_fslio": False # Note in CMakeLists.txt: "If OFF, The copyright of this code is questionable for inclusion with nifti." | ||
} | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def validate(self): | ||
if is_msvc(self) and self.options.shared: | ||
# not supported due to not having dllexport definitions | ||
raise ConanInvalidConfiguration(f"{self.ref} does not support -o {self.ref}:shared=True with MSVC compiler.") | ||
if not self.options.use_nifti2 and self.options.use_cifti: | ||
raise ConanInvalidConfiguration(f"{self.ref} -o '&:use_cifti=True' requires -o '&:use_nifti2=True'") | ||
|
||
def configure(self): | ||
if self.options.shared: | ||
self.options.rm_safe("fPIC") | ||
self.settings.rm_safe("compiler.cppstd") | ||
self.settings.rm_safe("compiler.libcxx") | ||
|
||
def layout(self): | ||
cmake_layout(self, src_folder="src") | ||
|
||
def requirements(self): | ||
self.requires("zlib/[>=1.2.11 <2]") | ||
if self.options.use_cifti: | ||
self.requires("expat/[>=2.6.2 <3]") | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], strip_root=True) | ||
|
||
def generate(self): | ||
tc = CMakeToolchain(self) | ||
tc.variables["NIFTI_INSTALL_NO_DOCS"] = True | ||
tc.variables["USE_NIFTI2_CODE"] = self.options.use_nifti2 | ||
tc.variables["USE_CIFTI_CODE"] = self.options.use_cifti | ||
tc.variables["USE_FSL_CODE"] = self.options.use_fslio | ||
tc.variables["NIFTI_BUILD_TESTING"] = False # disable building tests | ||
if is_msvc(self): | ||
tc.variables["USE_MSVC_RUNTIME_LIBRARY_DLL"] = not is_msvc_static_runtime(self) | ||
tc.preprocessor_definitions["_CRT_SECURE_NO_WARNINGS"] = 1 | ||
tc.generate() | ||
tc = CMakeDeps(self) | ||
tc.generate() | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def package(self): | ||
copy(self, "LICENSE", self.source_folder, os.path.join(self.package_folder, "licenses")) | ||
cmake = CMake(self) | ||
cmake.install() | ||
|
||
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) | ||
rmdir(self, os.path.join(self.package_folder, "lib", "cmake")) | ||
rmdir(self, os.path.join(self.package_folder, "share")) | ||
rm(self, "*.la", os.path.join(self.package_folder, "lib")) | ||
rm(self, "*.pdb", os.path.join(self.package_folder, "lib")) | ||
rm(self, "*.pdb", os.path.join(self.package_folder, "bin")) | ||
|
||
def package_info(self): | ||
self.cpp_info.set_property("cmake_file_name", "nifti") | ||
self.cpp_info.set_property("cmake_target_name", "NIFTI::NIFTI") | ||
self.cpp_info.set_property("pkg_config_name", "nifti") | ||
self.cpp_info.includedirs += [ os.path.join("include", "nifti") ] | ||
|
||
sys_libs = [] | ||
if self.settings.os in ["Linux", "FreeBSD"]: | ||
sys_libs += ["m"] | ||
|
||
self.cpp_info.required_components = ["ZLIB::ZLIB"] | ||
if self.options.use_cifti: | ||
self.cpp_info.required_components += ["EXPAT::EXPAT"] | ||
|
||
self.cpp_info.components["znz"].libs = ["znz"] | ||
self.cpp_info.components["znz"].set_property("pkg_config_name", "znz") | ||
self.cpp_info.components["znz"].set_property("cmake_target_name", "NIFTI::znz") | ||
self.cpp_info.components["znz"].includedirs += [os.path.join("include", "nifti")] | ||
self.cpp_info.components["znz"].system_libs += sys_libs | ||
|
||
# inside the niftilib folder | ||
self.cpp_info.components["niftiio"].libs = ["niftiio"] | ||
self.cpp_info.components["niftiio"].set_property("pkg_config_name", "niftiio") | ||
self.cpp_info.components["niftiio"].set_property("cmake_target_name", "NIFTI::niftiio") | ||
self.cpp_info.components["niftiio"].includedirs += [os.path.join("include", "nifti")] | ||
self.cpp_info.components["niftiio"].system_libs += sys_libs | ||
|
||
self.cpp_info.components["nifticdf"].libs = ["nifticdf"] | ||
self.cpp_info.components["nifticdf"].requires = ["niftiio"] | ||
self.cpp_info.components["nifticdf"].set_property("pkg_config_name", "nifticdf") | ||
self.cpp_info.components["nifticdf"].set_property("cmake_target_name", "NIFTI::nifticdf") | ||
self.cpp_info.components["nifticdf"].includedirs += [os.path.join("include", "nifti")] | ||
self.cpp_info.components["nifticdf"].system_libs += sys_libs | ||
|
||
if self.options.use_nifti2: | ||
self.cpp_info.components["nifti2"].libs = ["nifti2"] | ||
self.cpp_info.components["nifti2"].requires = ["znz"] | ||
self.cpp_info.components["nifti2"].set_property("pkg_config_name", "nifti2") | ||
self.cpp_info.components["nifti2"].set_property("cmake_target_name", "NIFTI::nifti2") | ||
self.cpp_info.components["nifti2"].includedirs += [os.path.join("include", "nifti")] | ||
self.cpp_info.components["nifti2"].system_libs += sys_libs | ||
|
||
if self.options.use_cifti: | ||
self.cpp_info.components["cifti"].libs = ["cifti"] | ||
self.cpp_info.components["cifti"].requires = ["nifti2"] | ||
self.cpp_info.components["cifti"].set_property("pkg_config_name", "cifti") | ||
self.cpp_info.components["cifti"].set_property("cmake_target_name", "NIFTI::cifti") | ||
self.cpp_info.components["cifti"].includedirs += [os.path.join("include", "nifti")] | ||
self.cpp_info.components["cifti"].system_libs += sys_libs | ||
|
||
if self.options.use_fslio: | ||
self.cpp_info.components["fslio"].libs = ["fslio"] | ||
self.cpp_info.components["fslio"].requires = ["nifti2"] | ||
self.cpp_info.components["fslio"].set_property("pkg_config_name", "fslio") | ||
self.cpp_info.components["fslio"].set_property("cmake_target_name", "NIFTI::fslio") | ||
self.cpp_info.components["fslio"].includedirs += [os.path.join("include", "nifti")] | ||
self.cpp_info.components["fslio"].system_libs += sys_libs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
|
||
project(test_package LANGUAGES C) | ||
|
||
find_package(NIFTI 3 REQUIRED CONFIG) | ||
|
||
add_executable(${PROJECT_NAME} test_package.c) | ||
|
||
target_link_libraries(${PROJECT_NAME} PRIVATE NIFTI::nifticdf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from conan import ConanFile | ||
from conan.tools.build import can_run | ||
from conan.tools.cmake import cmake_layout, CMake | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv" | ||
test_type = "explicit" | ||
|
||
def requirements(self): | ||
self.requires(self.tested_reference_str) | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
cmake = CMake(self) | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindir, "test_package") | ||
self.run(bin_path, env="conanrun") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include "nifticdf.h" | ||
|
||
// taken from nifti_clib/real_easy/minimal_example_of_downstream_usage | ||
int main(void) { | ||
double input= 7.0; | ||
const double output = alnrel(&input); | ||
|
||
return (output > 0.0) ? EXIT_SUCCESS: EXIT_FAILURE ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
versions: | ||
# Newer versions at the top | ||
"3.0.0": | ||
folder: all |