########
# CDF-C#
########

set(CDFLIB_H)
set(CDFLIB_C)
set(CSHARP_INCLUDE_PATH ${CMAKE_CURRENT_SOURCE_DIR})

set(CDFLIB_PUBLIC_H ${CDF_SOURCE_DIR}/src/include/cdfrev.h
                    ${CDF_SOURCE_DIR}/src/include/cdfmd5.h
	${CDF_SOURCE_DIR}/src/include/cdfconfig.h ${CDF_SOURCE_DIR}/src/include/cdfdist.h 
	${CDF_SOURCE_DIR}/src/include/cdflib64.h ${CDF_SOURCE_DIR}/src/include/cdflib.h
	${CDF_SOURCE_DIR}/src/include/cdftt2000.h ${CDF_SOURCE_DIR}/src/include/cdffsi.h)
list(APPEND CDFLIB_H cdf.h resource.h)
list(APPEND CDFLIB_H ${CDFLIB_PUBLIC_H})

set(SRC_LIB ${CDF_SOURCE_DIR}/src/lib)

list(APPEND CDFLIB_C cdfstdi.c
	${SRC_LIB}/cdfalloc64.c ${SRC_LIB}/cdfalloc.c 
	${SRC_LIB}/cdfcks.c ${SRC_LIB}/cdfclo64.c ${SRC_LIB}/cdfclo.c
	${SRC_LIB}/cdfcon64.c ${SRC_LIB}/cdfcon.c 
	${SRC_LIB}/cdfcre64.c ${SRC_LIB}/cdfcre.c ${SRC_LIB}/cdfcsi.c
	${SRC_LIB}/cdfdel64.c ${SRC_LIB}/cdfdel.c 
	${SRC_LIB}/cdfed.c ${SRC_LIB}/cdffii.c ${SRC_LIB}/cdffsi2.c
	${SRC_LIB}/cdffsi3.c ${SRC_LIB}/cdffsi.c ${SRC_LIB}/cdfget64.c 
	${SRC_LIB}/cdfget.c ${SRC_LIB}/cdfgzip64.c
	${SRC_LIB}/cdfgzip.c ${SRC_LIB}/cdfhuff64.c ${SRC_LIB}/cdfhuff.c 
	${SRC_LIB}/cdfhyper64.c ${SRC_LIB}/cdfhyper.c
	${SRC_LIB}/cdflib.c ${SRC_LIB}/cdfmd5.c ${SRC_LIB}/cdfmem.c 
	${SRC_LIB}/cdfmisc1_64.c ${SRC_LIB}/cdfmisc1.c
	${SRC_LIB}/cdfmisc2_64.c ${SRC_LIB}/cdfmisc2.c 
	${SRC_LIB}/cdfmisc3_64.c ${SRC_LIB}/cdfmisc3.c ${SRC_LIB}/cdfope.c
	${SRC_LIB}/cdfput1_64.c ${SRC_LIB}/cdfput1.c 
	${SRC_LIB}/cdfput2_64.c ${SRC_LIB}/cdfput2.c ${SRC_LIB}/cdfread64.c
	${SRC_LIB}/cdfread.c ${SRC_LIB}/cdfrle64.c ${SRC_LIB}/cdfrle.c 
	${SRC_LIB}/cdfsav.c ${SRC_LIB}/cdfsel64.c
	${SRC_LIB}/cdfsel.c ${SRC_LIB}/cdfstr.c ${SRC_LIB}/cdftext.c 
	${SRC_LIB}/cdftt2000.c ${SRC_LIB}/cdftt2000f.c
	${SRC_LIB}/cdfvalidator64.c ${SRC_LIB}/cdfvalidator.c 
	${SRC_LIB}/cdfvalid.c ${SRC_LIB}/cdfwrite64.c ${SRC_LIB}/cdfwrite.c
	${SRC_LIB}/dirutils.c ${SRC_LIB}/epochu.c ${SRC_LIB}/epochuf.c 
	${SRC_LIB}/libmain.c ${SRC_LIB}/vstream64.c
	${SRC_LIB}/vstream.c)

set(Csharp_CORE ${CDFLIB_C} ${CDFLIB_H} ${CDF_SOURCE_DIR}/win32/csharp/dllcdfcsharp.rc)

add_library(CDF_Csharp_CORE OBJECT ${Csharp_CORE})
set_target_properties(CDF_Csharp_CORE PROPERTIES POSITION_INDEPENDENT_CODE ON)
if(TOZLIB-NG)
  target_link_libraries(CDF_Csharp_CORE PRIVATE zlib-ng)
else()
  target_link_libraries(CDF_Csharp_CORE PRIVATE zlib-orig)
endif()

check_c_compiler_flag("-Wno-stringop-overflow" SUPPORTS_NO_STRINGOP_OVERFLOW)
if(SUPPORTS_NO_STRINGOP_OVERFLOW)
  target_compile_options(CDF_Csharp_CORE PRIVATE -Wno-stringop-overflow)
endif()

if(TOZLIB-NG)
  target_compile_definitions(CDF_Csharp_CORE PRIVATE USRDLL DLLCDF_EXPORT BUILDINGforDLL ZLIB_COMPAT _FILE_OFFSET_BITS=64 _LARGEFILE64_SOURCE=1 _LARGEFILE_SOURCE MALLOC_CHECK_=0)
  include_directories(${CDF_SOURCE_DIR}/src/lib/zlib-ng)
else()
  target_compile_definitions(CDF_Csharp_CORE PRIVATE USRDLL DLLCDF_EXPORT BUILDINGforDLL Z_PREFIX _FILE_OFFSET_BITS=64 _LARGEFILE64_SOURCE=1 _LARGEFILE_SOURCE MALLOC_CHECK_=0)
  include_directories(${CDF_SOURCE_DIR}/src/lib/zlib)
endif()

target_include_directories(CDF_Csharp_CORE PUBLIC ${CSHARP_INCLUDE_PATH})
target_include_directories(CDF_Csharp_CORE PUBLIC ${CDF_SOURCE_DIR}/src/include)

