mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-02-23 16:59:54 +08:00
Additional CMake usage.
This commit is contained in:
parent
a83c1bd851
commit
2de3388cf1
@ -8,7 +8,8 @@ ENABLE_TESTING()
|
||||
INCLUDE(CTest)
|
||||
|
||||
IF(MSVC)
|
||||
SET(USE_FOLDERS ON)
|
||||
SET(USE_FOLDERS OFF)
|
||||
#SET(CMAKE_LINKER_FLAGS ${CMAKE_LINKER_FLAGS} "/NODEFAULTLIBS:MSVCRT")
|
||||
ENDIF()
|
||||
|
||||
# CTest/CDash configuration
|
||||
@ -176,26 +177,23 @@ IF (USE_HDF5 OR ENABLE_NETCDF_4)
|
||||
SET(USE_HDF5 ON)
|
||||
SET(USE_NETCDF4 ON)
|
||||
|
||||
FIND_PACKAGE(HDF5 COMPONENTS C HL REQUIRED)
|
||||
FIND_PACKAGE(HDF5 COMPONENTS C HL)
|
||||
#FIND_LIBRARY(HDF5_LIBRARY NAMES hdf5)
|
||||
#FIND_LIBRARY(HDF5_HL_LIBRARY NAMES hdf5_hl)
|
||||
|
||||
#IF(NOT HDF5_LIBRARIES OR NOT HDF5_HL_LIBRARY)
|
||||
# MESSAGE(FATAL_ERROR "HDF5 Not Found.")
|
||||
#ENDIF()
|
||||
IF(NOT HDF5_FOUND)
|
||||
IF(NOT HDF5_FOUND AND (NOT HDF5_LIBRARIES AND NOT HDF5_INCLUDE_DIRS))
|
||||
MESSAGE(FATAL_ERROR "HDF5 Not Found.")
|
||||
ELSE()
|
||||
INCLUDE_DIRECTORIES(${HDF5_INCLUDE_DIRS})
|
||||
#MESSAGE(STATUS "HDF5_LIBRARY: ${HDF5_LIBRARY}")
|
||||
#MESSAGE(STATUS "HDF5_LIBRARIES: ${HDF5_LIBRARIES}")
|
||||
#MESSAGE(STATUS "HDF5_INCLUDE_DIRS: ${HDF5_INCLUDE_DIRS}")
|
||||
#MESSAGE(STATUS "HDF5_HL_LIBRARIES: ${HDF5_HL_LIBRARIES}")
|
||||
ENDIF()
|
||||
|
||||
#MESSAGE(STATUS "Found HDF5: ${HDF5_LIBRARIES}")
|
||||
#MESSAGE(STATUS "Found HDF5_HL: ${HDF5_HL_LIBRARY}")
|
||||
#SET(HDF5_LIBRARIES ${HDF5_LIBRARY} ${HDF5_HL_LIBRARY})
|
||||
|
||||
INCLUDE_DIRECTORIES(${HDF5_INCLUDE_DIR})
|
||||
|
||||
# Check to see if H5Z_SZIP exists in HDF5_Libraries. If so, we must use szip.
|
||||
|
@ -49,6 +49,13 @@ IF(ENABLE_PNETCDF AND PNETCDF)
|
||||
#TARGET_LINK_LIBRARIES(netcdf ${PNETCDF})
|
||||
ENDIF()
|
||||
TARGET_LINK_LIBRARIES(netcdf ${TLL_LIBS})
|
||||
|
||||
IF(MSVC)
|
||||
SET_TARGET_PROPERTIES(netcdf PROPERTIES
|
||||
LINK_FLAGS " /NODEFAULTLIBS:MSVCRT"
|
||||
)
|
||||
ENDIF()
|
||||
|
||||
INSTALL(TARGETS netcdf DESTINATION lib EXPORT netcdf-targets)
|
||||
INSTALL(EXPORT netcdf-targets DESTINATION ".")
|
||||
#include(CPack)
|
||||
|
@ -13,10 +13,6 @@ ENDIF()
|
||||
|
||||
SET(libsrc_SOURCES v1hpg.c putget.c attr.c nc3dispatch.c nc3internal.c var.c dim.c ncx.c lookup3.c ncio.c)
|
||||
|
||||
IF(MSVC)
|
||||
SET(libsrc_SOURCES ${libsrc_SOURCES} XGetopt.c)
|
||||
ENDIF()
|
||||
|
||||
IF (BUILD_DISKLESS)
|
||||
SET(libsrc_SOURCES ${libsrc_SOURCES} memio.c)
|
||||
|
||||
|
@ -3,6 +3,7 @@ SET(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
INCLUDE_DIRECTORIES(".")
|
||||
|
||||
remove_definitions(-DDLL_EXPORT)
|
||||
remove_definitions(-DDLL_NETCDF)
|
||||
|
||||
FILE(GLOB COPY_FILES ${CMAKE_BINARY_DIR}/ncgen/*.nc ${CMAKE_BINARY_DIR}/nc_test4/*.nc ${CMAKE_CURRENT_SOURCE_DIR}/*.ncml ${CMAKE_CURRENT_SOURCE_DIR}/*.nc ${CMAKE_CURRENT_SOURCE_DIR}/*.cdl ${CMAKE_CURRENT_SOURCE_DIR}/*.sh ${CMAKE_CURRENT_SOURCE_DIR}/cdl4 ${CMAKE_CURRENT_SOURCE_DIR}/expected4 )
|
||||
FILE(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE)
|
||||
@ -23,6 +24,12 @@ ADD_CUSTOM_COMMAND(
|
||||
SET(ncdump_FILES ncdump.c vardata.c dumplib.c indent.c nctime0.c utils.c nciter.c)
|
||||
SET(nccopy_FILES nccopy.c nciter.c chunkspec.c utils.c dimmap.c)
|
||||
|
||||
IF(MSVC)
|
||||
SET(ncdump_FILES ${ncdump_FILES} XGetopt.c)
|
||||
SET(nccopy_FILES ${nccopy_FILES} XGetopt.c)
|
||||
ENDIF()
|
||||
|
||||
|
||||
|
||||
|
||||
ADD_EXECUTABLE(ncdump ${ncdump_FILES})
|
||||
|
214
ncdump/XGetopt.c
Normal file
214
ncdump/XGetopt.c
Normal file
@ -0,0 +1,214 @@
|
||||
// XGetopt.cpp Version 1.2
|
||||
//
|
||||
// Author: Hans Dietrich
|
||||
// hdietrich2@hotmail.com
|
||||
//
|
||||
// Description:
|
||||
// XGetopt.cpp implements getopt(), a function to parse command lines.
|
||||
//
|
||||
// History
|
||||
// Version 1.2 - 2003 May 17
|
||||
// - Added Unicode support
|
||||
//
|
||||
// Version 1.1 - 2002 March 10
|
||||
// - Added example to XGetopt.cpp module header
|
||||
//
|
||||
// This software is released into the public domain.
|
||||
// You are free to use it in any way you like.
|
||||
//
|
||||
// This software is provided "as is" with no expressed
|
||||
// or implied warranty. I accept no liability for any
|
||||
// damage or loss of business that this software may cause.
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// if you are not using precompiled headers then include these lines:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
#include "XGetopt.h"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// X G e t o p t . c p p
|
||||
//
|
||||
//
|
||||
// NAME
|
||||
// getopt -- parse command line options
|
||||
//
|
||||
// SYNOPSIS
|
||||
// int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
|
||||
//
|
||||
// extern TCHAR *optarg;
|
||||
// extern int optind;
|
||||
//
|
||||
// DESCRIPTION
|
||||
// The getopt() function parses the command line arguments. Its
|
||||
// arguments argc and argv are the argument count and array as
|
||||
// passed into the application on program invocation. In the case
|
||||
// of Visual C++ programs, argc and argv are available via the
|
||||
// variables __argc and __argv (double underscores), respectively.
|
||||
// getopt returns the next option letter in argv that matches a
|
||||
// letter in optstring. (Note: Unicode programs should use
|
||||
// __targv instead of __argv. Also, all character and string
|
||||
// literals should be enclosed in _T( ) ).
|
||||
//
|
||||
// optstring is a string of recognized option letters; if a letter
|
||||
// is followed by a colon, the option is expected to have an argument
|
||||
// that may or may not be separated from it by white space. optarg
|
||||
// is set to point to the start of the option argument on return from
|
||||
// getopt.
|
||||
//
|
||||
// Option letters may be combined, e.g., "-ab" is equivalent to
|
||||
// "-a -b". Option letters are case sensitive.
|
||||
//
|
||||
// getopt places in the external variable optind the argv index
|
||||
// of the next argument to be processed. optind is initialized
|
||||
// to 0 before the first call to getopt.
|
||||
//
|
||||
// When all options have been processed (i.e., up to the first
|
||||
// non-option argument), getopt returns EOF, optarg will point
|
||||
// to the argument, and optind will be set to the argv index of
|
||||
// the argument. If there are no non-option arguments, optarg
|
||||
// will be set to NULL.
|
||||
//
|
||||
// The special option "--" may be used to delimit the end of the
|
||||
// options; EOF will be returned, and "--" (and everything after it)
|
||||
// will be skipped.
|
||||
//
|
||||
// RETURN VALUE
|
||||
// For option letters contained in the string optstring, getopt
|
||||
// will return the option letter. getopt returns a question mark (?)
|
||||
// when it encounters an option letter not included in optstring.
|
||||
// EOF is returned when processing is finished.
|
||||
//
|
||||
// BUGS
|
||||
// 1) Long options are not supported.
|
||||
// 2) The GNU double-colon extension is not supported.
|
||||
// 3) The environment variable POSIXLY_CORRECT is not supported.
|
||||
// 4) The + syntax is not supported.
|
||||
// 5) The automatic permutation of arguments is not supported.
|
||||
// 6) This implementation of getopt() returns EOF if an error is
|
||||
// encountered, instead of -1 as the latest standard requires.
|
||||
//
|
||||
// EXAMPLE
|
||||
// BOOL CMyApp::ProcessCommandLine(int argc, TCHAR *argv[])
|
||||
// {
|
||||
// int c;
|
||||
//
|
||||
// while ((c = getopt(argc, argv, _T("aBn:"))) != EOF)
|
||||
// {
|
||||
// switch (c)
|
||||
// {
|
||||
// case _T('a'):
|
||||
// TRACE(_T("option a\n"));
|
||||
// //
|
||||
// // set some flag here
|
||||
// //
|
||||
// break;
|
||||
//
|
||||
// case _T('B'):
|
||||
// TRACE( _T("option B\n"));
|
||||
// //
|
||||
// // set some other flag here
|
||||
// //
|
||||
// break;
|
||||
//
|
||||
// case _T('n'):
|
||||
// TRACE(_T("option n: value=%d\n"), atoi(optarg));
|
||||
// //
|
||||
// // do something with value here
|
||||
// //
|
||||
// break;
|
||||
//
|
||||
// case _T('?'):
|
||||
// TRACE(_T("ERROR: illegal option %s\n"), argv[optind-1]);
|
||||
// return FALSE;
|
||||
// break;
|
||||
//
|
||||
// default:
|
||||
// TRACE(_T("WARNING: no handler for option %c\n"), c);
|
||||
// return FALSE;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// //
|
||||
// // check for non-option args here
|
||||
// //
|
||||
// return TRUE;
|
||||
// }
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
TCHAR *optarg; // global argument pointer
|
||||
int optind = 0; // global argv index
|
||||
|
||||
int getopt(int argc, TCHAR *argv[], TCHAR *optstring)
|
||||
{
|
||||
static TCHAR *next = NULL;
|
||||
TCHAR c;
|
||||
TCHAR *cp = malloc(sizeof(TCHAR)*1024);
|
||||
|
||||
if (optind == 0)
|
||||
next = NULL;
|
||||
|
||||
optarg = NULL;
|
||||
|
||||
if (next == NULL || *next == _T('\0'))
|
||||
{
|
||||
if (optind == 0)
|
||||
optind++;
|
||||
|
||||
if (optind >= argc || argv[optind][0] != _T('-') || argv[optind][1] == _T('\0'))
|
||||
{
|
||||
optarg = NULL;
|
||||
if (optind < argc)
|
||||
optarg = argv[optind];
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (_tcscmp(argv[optind], _T("--")) == 0)
|
||||
{
|
||||
optind++;
|
||||
optarg = NULL;
|
||||
if (optind < argc)
|
||||
optarg = argv[optind];
|
||||
return EOF;
|
||||
}
|
||||
|
||||
next = argv[optind];
|
||||
next++; // skip past -
|
||||
optind++;
|
||||
}
|
||||
|
||||
c = *next++;
|
||||
*cp = _tcschr(optstring, c);
|
||||
|
||||
if (cp == NULL || c == _T(':'))
|
||||
return _T('?');
|
||||
|
||||
cp++;
|
||||
if (*cp == _T(':'))
|
||||
{
|
||||
if (*next != _T('\0'))
|
||||
{
|
||||
optarg = next;
|
||||
next = NULL;
|
||||
}
|
||||
else if (optind < argc)
|
||||
{
|
||||
optarg = argv[optind];
|
||||
optind++;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _T('?');
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
@ -25,6 +25,7 @@
|
||||
#include "XGetopt.h"
|
||||
#define snprintf _snprintf
|
||||
int opterr;
|
||||
int optind;
|
||||
#endif
|
||||
|
||||
/* default bytes of memory we are willing to allocate for variable
|
||||
|
@ -16,6 +16,7 @@ Research/Unidata. See \ref copyright file for more info. */
|
||||
#include "XGetopt.h"
|
||||
#define snprintf _snprintf
|
||||
int opterr;
|
||||
int optind;
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
|
Loading…
Reference in New Issue
Block a user