"Fossies" - the Fresh Open Source Software Archive

Member "cfitsio-4.0.0/CMakeLists.txt" (20 May 2021, 10714 Bytes) of package /linux/misc/cfitsio-4.0.0.tar.gz:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "CMakeLists.txt": 3.49_vs_4.0.0.

    1 #==============================================================================
    2 # CFITSIO CMakeLists.txt
    3 #==============================================================================
    4 
    5 # Ensure that build directory is not the source directory:
    6 IF(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR})
    7 	message(FATAL_ERROR
    8 		"Please create a separate directory for building CFITSIO."
    9 		)
   10 ENDIF()
   11 
   12 CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
   13 
   14 # Suppress warning about WIN32 no longer being defined on Cygwin:
   15 SET(CMAKE_LEGACY_CYGWIN_WIN32 0)
   16 
   17 PROJECT(CFITSIO
   18 	DESCRIPTION "Library of C and Fortran subroutines for reading and writing data files in FITS data format."
   19 	LANGUAGES C CXX
   20 	)
   21 
   22 # Define project version
   23 SET(${PROJECT_NAME}_MAJOR_VERSION 4)
   24 SET(${PROJECT_NAME}_MINOR_VERSION 0)
   25 SET(${PROJECT_NAME}_MICRO_VERSION 0)
   26 SET(${PROJECT_NAME}_VERSION ${${PROJECT_NAME}_MAJOR_VERSION}.${${PROJECT_NAME}_MINOR_VERSION}.${${PROJECT_NAME}_MICRO_VERSION})
   27 SET(LIB_NAME cfitsio)
   28 
   29 # Allow @rpath token in target install name on Macs.
   30 # See "cmake --help-policy CMP0042" for more information.
   31 IF(POLICY CMP0042)
   32   CMAKE_POLICY(SET CMP0042 NEW)
   33 ENDIF()
   34 
   35 INCLUDE(CheckLibraryExists)
   36 INCLUDE(CheckFunctionExists)
   37 INCLUDE(CheckSymbolExists)
   38 INCLUDE(CheckCSourceCompiles)
   39 
   40 #==============================================================================
   41 # Build options:
   42 #==============================================================================
   43 
   44 # Allow the developer to select if Dynamic or Static libraries are built
   45 OPTION(BUILD_SHARED_LIBS "Build Shared Libraries" ON)
   46 
   47 # Allow curl dependency to be disabled with "-DUSE_CURL=OFF":
   48 OPTION(USE_CURL "USE_CURL" ON)
   49 
   50 OPTION(USE_PTHREADS "Thread-safe build (using pthreads)" OFF)
   51 
   52 OPTION(TESTS "Build test programs Testprog and cookbook" OFF)
   53 
   54 OPTION(UTILS "Build FPack, Funpack, and Fitscopy executables" OFF)
   55 
   56 OPTION(CFITSIO_USE_SSE2 "Enable use of instructions in the SSE2 extended instruction set" OFF)
   57 
   58 OPTION(CFITSIO_USE_SSSE3 "Enable use of instructions in the SSSE3 extended instruction set" OFF)
   59 
   60 IF(NOT WIN32)
   61     OPTION(CFITSIO_USE_BZIP2 "Enable bzip2 support" OFF)
   62 ENDIF()
   63 
   64 #==============================================================================
   65 
   66 FIND_PACKAGE(ZLIB REQUIRED)
   67 
   68 IF(BUILD_SHARED_LIBS)
   69   SET (LIB_TYPE SHARED)
   70 ELSE()
   71   SET (LIB_TYPE STATIC)
   72 ENDIF(BUILD_SHARED_LIBS)
   73 
   74 IF(NOT MSVC)
   75    # Find curl library, for HTTPS support:
   76    IF(USE_CURL)
   77       FIND_PACKAGE(CURL)
   78       IF(CURL_FOUND)
   79          ADD_DEFINITIONS(-DCFITSIO_HAVE_CURL)
   80       ENDIF()
   81    ENDIF()
   82 ENDIF(NOT MSVC)
   83 
   84 IF(USE_PTHREADS)
   85    FIND_PACKAGE(Threads REQUIRED)
   86    ADD_DEFINITIONS(-D_REENTRANT)
   87 ENDIF(USE_PTHREADS)
   88 
   89 IF(CFITSIO_USE_BZIP2)
   90    FIND_PACKAGE(BZip2 REQUIRED)
   91    ADD_DEFINITIONS(-DHAVE_BZIP2=1)
   92 ENDIF(CFITSIO_USE_BZIP2)
   93 
   94 # Math library (not available in MSVC or MINGW)
   95 IF(MSVC OR MINGW)
   96    SET(M_LIB "")
   97 ELSE()
   98    FIND_LIBRARY(M_LIB m)
   99 ENDIF()
  100 
  101 # Support for remote file drivers is not implemented for native Windows:
  102 IF (NOT MSVC)
  103 
  104     # Find library needed for gethostbyname:
  105     CHECK_FUNCTION_EXISTS("gethostbyname" CMAKE_HAVE_GETHOSTBYNAME)
  106     IF (NOT CMAKE_HAVE_GETHOSTBYNAME)
  107         CHECK_LIBRARY_EXISTS("nsl" "gethostbyname" "" CMAKE_HAVE_GETHOSTBYNAME)
  108     ENDIF ()
  109 
  110     # Find library needed for connect:
  111     CHECK_FUNCTION_EXISTS("connect" CMAKE_HAVE_CONNECT)
  112     IF (NOT CMAKE_HAVE_CONNECT)
  113         CHECK_LIBRARY_EXISTS("socket" "connect" "" CMAKE_HAVE_CONNECT)
  114     ENDIF ()
  115 
  116     # Define HAVE_NET_SERVICES if gethostbyname & connect were found:
  117     IF (CMAKE_HAVE_GETHOSTBYNAME AND CMAKE_HAVE_CONNECT)
  118         ADD_DEFINITIONS(-DHAVE_NET_SERVICES)
  119         CHECK_SYMBOL_EXISTS(fmemopen "stdio.h" HAVE_FMEMOPEN)
  120         IF(HAVE_FMEMOPEN)
  121             ADD_DEFINITIONS(-DHAVE_FMEMOPEN)
  122         ENDIF()
  123     ENDIF()
  124 
  125 ENDIF()
  126 
  127 IF(MSVC OR BORLAND)
  128     # Define
  129     ADD_DEFINITIONS(-D_CRT_SECURE_NO_DEPRECATE)
  130     # Need an empty unistd.h in MSVC for flex-generated eval_l.c:
  131     FILE(WRITE ${CMAKE_SOURCE_DIR}/unistd.h "")
  132     INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR})
  133 ENDIF()
  134 
  135 IF(BORLAND)
  136     # Suppress spurious Borland compiler warnings about "Suspicious
  137     # pointer arithmetic", "Possibly incorrect assignment", and
  138     # "Comparing signed and unsigned values".
  139     ADD_DEFINITIONS(-w-spa)
  140     ADD_DEFINITIONS(-w-pia)
  141     ADD_DEFINITIONS(-w-csu)
  142 ENDIF()
  143 
  144 IF(CFITSIO_USE_SSE2)
  145     IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
  146        "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
  147        "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
  148         ADD_COMPILE_OPTIONS(-msse2)
  149     ENDIF()
  150     IF(MSVC)
  151         ADD_DEFINITIONS(-D__SSE2__=1)
  152     ENDIF()
  153 ENDIF()
  154 
  155 IF(CFITSIO_USE_SSSE3)
  156     IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR
  157        "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
  158        "${CMAKE_CXX_COMPILER_ID}" STREQUAL "AppleClang")
  159         ADD_COMPILE_OPTIONS(-mssse3)
  160     ENDIF()
  161     IF(MSVC)
  162         ADD_DEFINITIONS(-D__SSE2__=1 -D__SSSE3__=1)
  163     ENDIF()
  164 ENDIF()
  165 
  166 # Test for the unix ftruncate function
  167 CHECK_SYMBOL_EXISTS(ftruncate "unistd.h" HAVE_FTRUNCATE)
  168 IF(HAVE_FTRUNCATE)
  169     ADD_DEFINITIONS(-DHAVE_UNISTD_H -DHAVE_FTRUNCATE)
  170 ENDIF()
  171 
  172 # Check is System V IPC is supported on this machine
  173 CHECK_C_SOURCE_COMPILES("
  174 #include <sys/ipc.h>
  175 #include <sys/shm.h>
  176 #include <sys/sem.h>
  177 int main() {
  178   shmat(0,0,0);
  179   shmdt(0);
  180   shmget(0, 0, 0);
  181   semget(0, 0, 0);
  182   return 0;
  183 }" HAVE_SHMEM_SERVICES)
  184 IF(HAVE_SHMEM_SERVICES)
  185     ADD_DEFINITIONS(-DHAVE_SHMEM_SERVICES)
  186 
  187     # Some systems define flock_t, for others we have to define it ourselves
  188     CHECK_C_SOURCE_COMPILES("
  189     #include <sys/flock.h>
  190     int main() {
  191       flock_t filler;
  192       return 0;
  193     }" HAVE_FLOCK_T)
  194     IF(HAVE_FLOCK_T)
  195         ADD_DEFINITIONS(-DHAVE_FLOCK_T)
  196     ENDIF()
  197 
  198     # Check union semun
  199     CHECK_C_SOURCE_COMPILES("
  200     #include <sys/ipc.h>
  201     #include <sys/shm.h>
  202     #include <sys/sem.h>
  203     int main() {
  204       union semun filler;
  205       return 0;
  206     }" HAVE_UNION_SEMUN)
  207     IF(HAVE_UNION_SEMUN)
  208         ADD_DEFINITIONS(-DHAVE_UNION_SEMUN)
  209     ENDIF()
  210 ENDIF()
  211 
  212 IF(WIN32 AND BUILD_SHARED_LIBS)
  213     ADD_DEFINITIONS(-Dcfitsio_EXPORTS)
  214 ENDIF()
  215 
  216 #==============================================================================
  217 # CFITSIO source code:
  218 #==============================================================================
  219 
  220 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
  221 set (LIB_DESTINATION "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}")
  222 set (INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include/")
  223 set (BIN_DESTINATION "${CMAKE_INSTALL_PREFIX}/bin")
  224 
  225 SET(H_FILES fitsio.h fitsio2.h longnam.h)
  226 
  227 SET(SRC_FILES
  228     buffers.c cfileio.c checksum.c
  229     drvrfile.c drvrmem.c drvrnet.c drvrsmem.c
  230     editcol.c edithdu.c eval_f.c eval_l.c eval_y.c
  231     f77_wrap1.c f77_wrap2.c f77_wrap3.c f77_wrap4.c
  232     fits_hcompress.c fits_hdecompress.c fitscore.c
  233     getcol.c getcolb.c getcold.c getcole.c getcoli.c getcolj.c getcolk.c
  234     getcoll.c getcols.c getcolsb.c getcolui.c getcoluj.c getcoluk.c
  235     getkey.c group.c grparser.c histo.c imcompress.c iraffits.c modkey.c
  236     pliocomp.c
  237     putcol.c putcolb.c putcold.c putcole.c putcoli.c putcolj.c putcolk.c
  238     putcoll.c putcols.c putcolsb.c putcolu.c putcolui.c putcoluj.c putcoluk.c
  239     putkey.c quantize.c region.c ricecomp.c scalnull.c simplerng.c swapproc.c
  240     wcssub.c wcsutil.c zcompress.c zuncompress.c
  241 )
  242 
  243 # For future modifications:
  244 
  245 # drvrsmem.c is only usable if HAVE_SHMEM_SERVICES is defined:
  246 #drvrsmem.c
  247 
  248 # drvrgsiftp.c is only usable if HAVE_NET_SERVICES & HAVE_GSIFTP are defined:
  249 #drvrgsiftp.c
  250 
  251 #==============================================================================
  252 # Add libraries:
  253 #==============================================================================
  254 ADD_LIBRARY(${LIB_NAME} ${LIB_TYPE} ${H_FILES} ${SRC_FILES})
  255 # Math:
  256 TARGET_LINK_LIBRARIES(${LIB_NAME} ${M_LIB})
  257 # zlib:
  258 IF (ZLIB_FOUND)
  259     TARGET_INCLUDE_DIRECTORIES(${LIB_NAME} PUBLIC ${ZLIB_INCLUDE_DIR})
  260     TARGET_LINK_LIBRARIES(${LIB_NAME} ${ZLIB_LIBRARIES})
  261 ENDIF(ZLIB_FOUND)
  262 # cURL:
  263 IF (CURL_FOUND)
  264     TARGET_INCLUDE_DIRECTORIES(${LIB_NAME} PUBLIC ${CURL_INCLUDE_DIRS})
  265     TARGET_LINK_LIBRARIES(${LIB_NAME} ${CURL_LIBRARIES})
  266 ENDIF(CURL_FOUND)
  267 # PThreads:
  268 IF (THREADS_FOUND)
  269     TARGET_LINK_LIBRARIES(${LIB_NAME} Threads::Threads)
  270 ENDIF(THREADS_FOUND)
  271 # BZip2:
  272 IF (BZIP2_FOUND)
  273     TARGET_INCLUDE_DIRECTORIES(${LIB_NAME} PUBLIC ${BZIP2_INCLUDE_DIRS})
  274     TARGET_LINK_LIBRARIES(${LIB_NAME} ${BZIP2_LIBRARIES})
  275 ENDIF(BZIP2_FOUND)
  276 
  277 SET_TARGET_PROPERTIES(${LIB_NAME} PROPERTIES VERSION ${${PROJECT_NAME}_VERSION} SOVERSION ${${PROJECT_NAME}_MAJOR_VERSION})
  278 install(TARGETS ${LIB_NAME} DESTINATION ${LIB_DESTINATION})
  279 install(TARGETS ${LIB_NAME}
  280                             RUNTIME DESTINATION bin
  281                             LIBRARY DESTINATION lib
  282                             ARCHIVE DESTINATION lib)
  283 install(FILES ${H_FILES} DESTINATION ${INCLUDE_INSTALL_DIR} COMPONENT Devel)
  284 
  285 #==============================================================================
  286 # Optional test programs:
  287 #==============================================================================
  288 IF (TESTS)
  289 
  290     ENABLE_TESTING()
  291 
  292     ADD_EXECUTABLE(TestProg testprog.c)
  293     TARGET_LINK_LIBRARIES(TestProg ${LIB_NAME})
  294     ADD_TEST(TestProg TestProg)
  295     # Copy testprog.tpt to build directory to allow quick test
  296     # of ./TestProg (or .\Release\TestProg.exe in MSVC):
  297     FILE(COPY ${CMAKE_SOURCE_DIR}/testprog.tpt DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
  298 
  299     ADD_EXECUTABLE(cookbook cookbook.c)
  300     TARGET_LINK_LIBRARIES(cookbook ${LIB_NAME})
  301     ADD_TEST(cookbook cookbook)
  302 
  303 ENDIF(TESTS)
  304 
  305 #==============================================================================
  306 # Optional utilities:
  307 #==============================================================================
  308 IF (UTILS)
  309 
  310     ADD_EXECUTABLE(FPack fpack.c fpackutil.c)
  311     TARGET_LINK_LIBRARIES(FPack ${LIB_NAME})
  312 
  313     ADD_EXECUTABLE(Funpack funpack.c fpackutil.c)
  314     TARGET_LINK_LIBRARIES(Funpack ${LIB_NAME})
  315 
  316     ADD_EXECUTABLE(Fitscopy fitscopy.c)
  317     TARGET_LINK_LIBRARIES(Fitscopy ${LIB_NAME})
  318 
  319     # To expand the command line arguments in Windows, see:
  320     # http://msdn.microsoft.com/en-us/library/8bch7bkk.aspx
  321     if(MSVC)
  322       set_target_properties(FPack Funpack PROPERTIES LINK_FLAGS "setargv.obj")
  323     endif(MSVC)
  324 
  325     install(TARGETS FPack Funpack Fitscopy RUNTIME DESTINATION bin)
  326 
  327 ENDIF(UTILS)
  328 
  329 #==============================================================================
  330 # cfitsio.pc
  331 #==============================================================================
  332 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cfitsio.pc.cmake ${CMAKE_CURRENT_BINARY_DIR}/cfitsio.pc @ONLY)
  333 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cfitsio.pc DESTINATION lib/pkgconfig/)