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

add cfitsio/3.470 #1121

Merged
merged 4 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions recipes/cfitsio/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1.2)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory("source_subfolder")
10 changes: 10 additions & 0 deletions recipes/cfitsio/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
"3.470":
url: "https://heasarc.gsfc.nasa.gov/FTP/software/fitsio/c/cfitsio-3.47.tar.gz"
sha256: "985606e058403c073a68d95be74e9696f0ded9414520784457a1d4cba8cca7e2"
patches:
"3.470":
- patch_file: "patches/windows-use-strtok_s.patch"
base_path: "source_subfolder"
- patch_file: "patches/fix-cmake.patch"
base_path: "source_subfolder"
109 changes: 109 additions & 0 deletions recipes/cfitsio/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import glob
import os

from conans import ConanFile, CMake, tools

class CfitsioConan(ConanFile):
name = "cfitsio"
description = "C library for reading and writing data files in FITS " \
"(Flexible Image Transport System) data format"
license = "ISC"
topics = ("conan", "cfitsio", "fits", "image", "nasa", "astronomy", "astrophysics", "space")
homepage = "https://heasarc.gsfc.nasa.gov/fitsio/"
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],
"threadsafe": [True, False],
"simd_intrinsics": [None, "sse2", "ssse3"],
SpaceIm marked this conversation as resolved.
Show resolved Hide resolved
"with_bzip2": [True, False],
"with_curl": [True, False]
}
default_options = {
"shared": False,
"fPIC": True,
"threadsafe": False,
"simd_intrinsics": None,
"with_bzip2": False,
"with_curl": False
}

_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):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
if self.settings.os == "Windows":
del self.options.with_bzip2
del self.options.with_curl

def requirements(self):
self.requires.add("zlib/1.2.11")
if self.options.threadsafe and self.settings.os == "Windows" and \
(not self.settings.compiler == "gcc" or self.settings.compiler.threads == "win32"):
self.requires.add("pthreads4w/3.0.0")
if self.options.get_safe("with_bzip2"):
self.requires.add("bzip2/1.0.8")
if self.options.get_safe("with_curl"):
self.requires.add("libcurl/7.68.0")

def source(self):
tools.get(**self.conan_data["sources"][self.version])
url = self.conan_data["sources"][self.version]["url"]
extracted_dir = os.path.basename(url).replace(".tar.gz", "").replace(".zip", "")
os.rename(extracted_dir, self._source_subfolder)

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
cmake.build()

def _patch_sources(self):
for patch in self.conan_data["patches"][self.version]:
tools.patch(**patch)
# Remove embedded zlib files
for zlib_file in glob.glob(os.path.join(self._source_subfolder, "zlib", "*")):
if not zlib_file.endswith(("zcompress.c", "zuncompress.c")):
os.remove(zlib_file)

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["USE_PTHREADS"] = self.options.threadsafe
self._cmake.definitions["CFITSIO_USE_SSE2"] = self.options.simd_intrinsics == "sse2"
self._cmake.definitions["CFITSIO_USE_SSSE3"] = self.options.simd_intrinsics == "ssse3"
if self.settings.os != "Windows":
self._cmake.definitions["CFITSIO_USE_BZIP2"] = self.options.with_bzip2
self._cmake.definitions["CFITSIO_USE_CURL"] = self.options.with_curl
SpaceIm marked this conversation as resolved.
Show resolved Hide resolved
self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake

def package(self):
self.copy("License.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.libs = tools.collect_libs(self)
self.cpp_info.includedirs.append(os.path.join("include", "cfitsio"))
if self.settings.os == "Linux":
self.cpp_info.system_libs.append("m")
if self.options.threadsafe:
self.cpp_info.system_libs.append("pthread")
223 changes: 223 additions & 0 deletions recipes/cfitsio/all/patches/fix-cmake.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -4,7 +4,7 @@
SET(CMAKE_LEGACY_CYGWIN_WIN32 0)

PROJECT(CFITSIO)
-CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
+CMAKE_MINIMUM_REQUIRED(VERSION 3.1)

# Allow @rpath token in target install name on Macs.
# See "cmake --help-policy CMP0042" for more information.
@@ -12,12 +12,14 @@ IF(POLICY CMP0042)
CMAKE_POLICY(SET CMP0042 NEW)
ENDIF()

-INCLUDE (${CMAKE_ROOT}/Modules/CheckLibraryExists.cmake)
-INCLUDE (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
+INCLUDE(CheckSymbolExists)
+INCLUDE(CheckCSourceCompiles)

# Allow the developer to select if Dynamic or Static libraries are built
OPTION (BUILD_SHARED_LIBS "Build Shared Libraries" ON)
OPTION (USE_PTHREADS "Thread-safe build (using pthreads)" OFF)
+OPTION(CFITSIO_USE_SSE2 "Enable use of instructions in the SSE2 extended instruction set" OFF)
+OPTION(CFITSIO_USE_SSSE3 "Enable use of instructions in the SSSE3 extended instruction set" OFF)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
set (LIB_DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
@@ -55,11 +57,19 @@ IF (BUILD_SHARED_LIBS)
ENDIF (BUILD_SHARED_LIBS)


-FILE(GLOB H_FILES "*.h")
+SET(H_FILES fitsio.h longnam.h)
+
+SET(LINK_LIBS "")

IF (USE_PTHREADS)
- FIND_PACKAGE(pthreads REQUIRED)
- INCLUDE_DIRECTORIES(${PTHREADS_INCLUDE_DIR})
+ SET(CMAKE_THREAD_PREFER_PTHREAD TRUE)
+ SET(THREADS_PREFER_PTHREAD_FLAG TRUE)
+ FIND_PACKAGE(Threads REQUIRED)
+ IF(CMAKE_USE_PTHREADS_INIT)
+ LIST(APPEND LINK_LIBS "Threads::Threads")
+ ELSE()
+ LIST(APPEND LINK_LIBS "CONAN_PKG::pthreads4w")
+ ENDIF()
ADD_DEFINITIONS(-D_REENTRANT)
ENDIF()

@@ -71,35 +81,27 @@ ELSE()
ENDIF()

# Support for remote file drivers is not implemented for native Windows:
-IF (NOT MSVC)
- # Find library needed for gethostbyname:
- CHECK_FUNCTION_EXISTS("gethostbyname" CMAKE_HAVE_GETHOSTBYNAME)
- IF(NOT CMAKE_HAVE_GETHOSTBYNAME)
- CHECK_LIBRARY_EXISTS("nsl" "gethostbyname" "" CMAKE_HAVE_GETHOSTBYNAME)
- ENDIF()
-
- # Find library needed for connect:
- CHECK_FUNCTION_EXISTS("connect" CMAKE_HAVE_CONNECT)
- IF(NOT CMAKE_HAVE_CONNECT)
- CHECK_LIBRARY_EXISTS("socket" "connect" "" CMAKE_HAVE_CONNECT)
- ENDIF()
-
- # Define HAVE_NET_SERVICES if gethostbyname & connect were found:
- IF (CMAKE_HAVE_GETHOSTBYNAME AND CMAKE_HAVE_CONNECT)
- ADD_DEFINITIONS(-DHAVE_NET_SERVICES)
- ENDIF ()
-
- # Find curl library, for HTTPS support:
- FIND_PACKAGE(CURL)
- IF (CURL_FOUND)
- INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIR})
+IF (NOT WIN32)
+ OPTION(CFITSIO_USE_CURL "Enable remote file i/o support" OFF)
+ IF(CFITSIO_USE_CURL)
+ CHECK_SYMBOL_EXISTS(gethostbyname "netdb.h" CMAKE_HAVE_GETHOSTBYNAME)
+ CHECK_SYMBOL_EXISTS(connect "sys/types.h;sys/socket.h" CMAKE_HAVE_CONNECT)
+ IF (CMAKE_HAVE_GETHOSTBYNAME AND CMAKE_HAVE_CONNECT)
+ ADD_DEFINITIONS(-DHAVE_NET_SERVICES)
+ CHECK_SYMBOL_EXISTS(fmemopen "stdio.h" HAVE_FMEMOPEN)
+ IF(HAVE_FMEMOPEN)
+ ADD_DEFINITIONS(-DHAVE_FMEMOPEN)
+ ENDIF()
+ ENDIF ()
+
+ LIST(APPEND LINK_LIBS "CONAN_PKG::libcurl")
ADD_DEFINITIONS(-DCFITSIO_HAVE_CURL)
ENDIF()
ENDIF()

SET(SRC_FILES
buffers.c cfileio.c checksum.c
- drvrfile.c drvrmem.c drvrnet.c
+ drvrfile.c drvrmem.c drvrnet.c drvrsmem.c
editcol.c edithdu.c eval_f.c eval_l.c eval_y.c
f77_wrap1.c f77_wrap2.c f77_wrap3.c f77_wrap4.c
fits_hcompress.c fits_hdecompress.c fitscore.c
@@ -123,27 +125,100 @@ SET(SRC_FILES

# Only include zlib source files if we are building a shared library.
# Users will need to link their executable with zlib independently.
-IF (BUILD_SHARED_LIBS)
- set(SRC_FILES ${SRC_FILES}
- zlib/adler32.c zlib/crc32.c zlib/deflate.c zlib/infback.c
- zlib/inffast.c zlib/inflate.c zlib/inftrees.c zlib/trees.c
- zlib/uncompr.c zlib/zutil.c
- )
+LIST(APPEND LINK_LIBS "CONAN_PKG::zlib")
+
+IF(CFITSIO_USE_SSE2)
+ IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
+ "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
+ "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
+ ADD_COMPILE_OPTIONS(-msse2)
+ ENDIF()
+ IF(MSVC)
+ ADD_DEFINITIONS(-D__SSE2__=1)
+ ENDIF()
+ENDIF()
+
+IF(CFITSIO_USE_SSSE3)
+ IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
+ "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
+ "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
+ ADD_COMPILE_OPTIONS(-mssse3)
+ ENDIF()
+ IF(MSVC)
+ ADD_DEFINITIONS(-D__SSE2__=1 -D__SSSE3__=1)
+ ENDIF()
+ENDIF()
+
+IF(NOT WIN32)
+ OPTION(CFITSIO_USE_BZIP2 "Enable bzip2 support" OFF)
+ IF(CFITSIO_USE_BZIP2)
+ LIST(APPEND LINK_LIBS "CONAN_PKG::bzip2")
+ ADD_DEFINITIONS(-DHAVE_BZIP2=1)
+ ENDIF()
+ENDIF()
+
+# Test for the unix ftruncate function
+CHECK_SYMBOL_EXISTS(ftruncate "unistd.h" HAVE_FTRUNCATE)
+IF(HAVE_FTRUNCATE)
+ ADD_DEFINITIONS(-DHAVE_FTRUNCATE)
+ENDIF()
+
+# Check is System V IPC is supported on this machine
+CHECK_C_SOURCE_COMPILES("
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/sem.h>
+int main() {
+ shmat(0,0,0);
+ shmdt(0);
+ shmget(0, 0, 0);
+ semget(0, 0, 0);
+ return 0;
+}" HAVE_SHMEM_SERVICES)
+IF(HAVE_SHMEM_SERVICES)
+ ADD_DEFINITIONS(-DHAVE_SHMEM_SERVICES)
+
+ # Some systems define flock_t, for others we have to define it ourselves
+ CHECK_C_SOURCE_COMPILES("
+ #include <sys/flock.h>
+ int main() {
+ flock_t filler;
+ return 0;
+ }" HAVE_FLOCK_T)
+ IF(HAVE_FLOCK_T)
+ ADD_DEFINITIONS(-DHAVE_FLOCK_T)
+ ENDIF()
+
+ # Check union semun
+ CHECK_C_SOURCE_COMPILES("
+ #include <sys/ipc.h>
+ #include <sys/shm.h>
+ #include <sys/sem.h>
+ int main() {
+ union semun filler;
+ return 0;
+ }" HAVE_UNION_SEMUN)
+ IF(HAVE_UNION_SEMUN)
+ ADD_DEFINITIONS(-DHAVE_UNION_SEMUN)
+ ENDIF()
+ENDIF()
+
+IF(WIN32 AND BUILD_SHARED_LIBS)
+ ADD_DEFINITIONS(-Dcfitsio_EXPORTS)
ENDIF()

ADD_LIBRARY(${LIB_NAME} ${LIB_TYPE} ${H_FILES} ${SRC_FILES})
-TARGET_LINK_LIBRARIES(${LIB_NAME} ${PTHREADS_LIBRARY} ${M_LIB} ${CURL_LIBRARIES})
+TARGET_LINK_LIBRARIES(${LIB_NAME} ${LINK_LIBS} ${M_LIB})

SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${${PROJECT_NAME}_VERSION} SOVERSION ${${PROJECT_NAME}_MAJOR_VERSION})
-install(TARGETS ${LIB_NAME} DESTINATION ${LIB_DESTINATION})
install(TARGETS ${LIB_NAME}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib)
-install(FILES ${H_FILES} DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel)
+install(FILES ${H_FILES} DESTINATION ${INCLUDE_INSTALL_DIR}/cfitsio COMPONENT Devel)

-# Only build test code and executables if building a shared library:
-IF (BUILD_SHARED_LIBS)
+# Do not build test code and executables:
+IF (FALSE)

ENABLE_TESTING()

@@ -173,7 +248,7 @@ IF (BUILD_SHARED_LIBS)
set_target_properties(FPack Funpack PROPERTIES LINK_FLAGS "setargv.obj")
endif(MSVC)

-ENDIF(BUILD_SHARED_LIBS)
+ENDIF()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cfitsio.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/cfitsio.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cfitsio.pc DESTINATION lib/pkgconfig/)
14 changes: 14 additions & 0 deletions recipes/cfitsio/all/patches/windows-use-strtok_s.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--- a/fitsio2.h
+++ b/fitsio2.h
@@ -26,7 +26,11 @@ extern int Fitsio_Pthread_Status;
#define FFUNLOCK1(lockname) (Fitsio_Pthread_Status = pthread_mutex_unlock(&lockname))
#define FFLOCK FFLOCK1(Fitsio_Lock)
#define FFUNLOCK FFUNLOCK1(Fitsio_Lock)
+#ifdef _WIN32
+#define ffstrtok(str, tok, save) strtok_s(str, tok, save)
+#else
#define ffstrtok(str, tok, save) strtok_r(str, tok, save)
+#endif

#else
#define FFLOCK
8 changes: 8 additions & 0 deletions recipes/cfitsio/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 2.8.11)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
18 changes: 18 additions & 0 deletions recipes/cfitsio/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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):
fits_name = os.path.join(self.source_folder, "file011.fits")
bin_path = os.path.join("bin", "test_package")
self.run("\"{0}\" \"{1}\"".format(bin_path, fits_name), run_environment=True)
Binary file added recipes/cfitsio/all/test_package/file011.fits
Binary file not shown.
Loading