1 set(TNG_ROOT_SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR})
2 file(RELATIVE_PATH TNG_ROOT_BINARY_DIR ${CMAKE_SOURCE_DIR} ${TNG_ROOT_SOURCE_DIR})
3 if ("${TNG_ROOT_BINARY_DIR}" MATCHES "^\.\.")
4 set(TNG_ROOT_BINARY_DIR tng)
6 set(TNG_ROOT_BINARY_DIR ${CMAKE_BINARY_DIR}/${TNG_ROOT_BINARY_DIR})
8 function (TNG_GENERATE_VERSION_H)
9 set(TNG_MAJOR_VERSION "1")
10 set(TNG_MINOR_VERSION "8")
11 set(TNG_VERSION_PATCH_LEVEL "0")
12 set(TNG_IO_VERSION "${TNG_MAJOR_VERSION}.${TNG_MINOR_VERSION}.${TNG_VERSION_PATCH_LEVEL}")
13 set(TNG_API_VERSION "8")
14 configure_file(${TNG_ROOT_SOURCE_DIR}/include/tng/version.h.in
15 ${TNG_ROOT_BINARY_DIR}/include/tng/version.h)
17 set(TNG_MAJOR_VERSION ${TNG_MAJOR_VERSION} PARENT_SCOPE)
18 set(TNG_IO_VERSION ${TNG_IO_VERSION} PARENT_SCOPE)
21 include(TestBigEndian)
22 test_big_endian(TNG_INTEGER_BIG_ENDIAN)
23 include(CheckIncludeFile)
24 check_include_file(inttypes.h TNG_HAVE_INTTYPES_H)
25 include(CMakeParseArguments)
27 function(add_tng_io_library NAME)
28 tng_generate_version_h()
30 set(_tng_compression_sources
31 bwlzh.c bwt.c coder.c dict.c fixpoint.c huffman.c huffmem.c
32 lz77.c merge_sort.c mtf.c rle.c tng_compress.c vals16.c
33 warnmalloc.c widemuldiv.c xtc2.c xtc3.c)
34 set(_tng_io_sources tng_io.c md5.c)
36 foreach(_file ${_tng_compression_sources})
37 list(APPEND _sources ${TNG_ROOT_SOURCE_DIR}/src/compression/${_file})
39 foreach(_file ${_tng_io_sources})
40 list(APPEND _sources ${TNG_ROOT_SOURCE_DIR}/src/lib/${_file})
43 list(APPEND _sources ${TNG_ROOT_SOURCE_DIR}/src/lib/tng_io_fortran.c)
46 set(_options OBJECT OWN_ZLIB)
47 cmake_parse_arguments(ARG "${_options}" "" "" ${ARGN})
49 set(_build_target ${NAME})
50 set(_link_type PRIVATE)
52 set(_build_target tng_io_obj)
53 set(_link_type INTERFACE)
54 add_library(${_build_target} OBJECT ${_sources})
55 # PIC is only on by default for SHARED libraries, but in case the
56 # object library is going to get used in such a library, the objects
57 # should be compiled with PIC as well.
58 if (BUILD_SHARED_LIBS)
59 set_target_properties(${_build_target} PROPERTIES POSITION_INDEPENDENT_CODE ON)
61 add_library(${NAME} INTERFACE)
62 target_sources(${NAME} INTERFACE $<TARGET_OBJECTS:tng_io_obj>)
64 add_library(${NAME} ${_sources})
65 set_target_properties(${NAME} PROPERTIES
66 VERSION ${TNG_IO_VERSION}
67 SOVERSION ${TNG_MAJOR_VERSION})
68 target_include_directories(${NAME} INTERFACE $<INSTALL_INTERFACE:include>)
70 target_include_directories(${_build_target} PRIVATE
71 $<BUILD_INTERFACE:${TNG_ROOT_SOURCE_DIR}/include>
72 $<BUILD_INTERFACE:${TNG_ROOT_BINARY_DIR}/include>)
73 target_include_directories(${NAME} INTERFACE
74 $<BUILD_INTERFACE:${TNG_ROOT_SOURCE_DIR}/include>
75 $<BUILD_INTERFACE:${TNG_ROOT_BINARY_DIR}/include>)
78 target_link_libraries(${NAME} ${_link_type} m)
82 set(_zlib_dir ${TNG_ROOT_SOURCE_DIR}/external/zlib)
84 # Add minimal necessary number of TNG source files
85 foreach(_file adler32.c compress.c crc32.c deflate.c inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c)
86 list(APPEND _zlib_sources ${_zlib_dir}/${_file})
88 add_library(tng_io_zlib OBJECT ${_zlib_sources})
89 if (BUILD_SHARED_LIBS)
90 set_target_properties(tng_io_zlib PROPERTIES POSITION_INDEPENDENT_CODE ON)
92 target_include_directories(tng_io_zlib PUBLIC ${_zlib_dir})
93 target_include_directories(${_build_target} PRIVATE ${_zlib_dir})
94 target_sources(${NAME} ${_link_type} $<TARGET_OBJECTS:tng_io_zlib>)
96 target_link_libraries(${NAME} ${_link_type} ZLIB::ZLIB)
99 if (TNG_HAVE_INTTYPES_H)
100 target_compile_definitions(${NAME} INTERFACE USE_STD_INTTYPES_H)
101 set_property(SOURCE ${TNG_ROOT_SOURCE_DIR}/src/lib/tng_io.c
102 APPEND PROPERTY COMPILE_DEFINITIONS USE_STD_INTTYPES_H)
104 if (TNG_INTEGER_BIG_ENDIAN)
105 set_property(SOURCE ${TNG_ROOT_SOURCE_DIR}/src/lib/md5.c
106 APPEND PROPERTY COMPILE_DEFINITIONS TNG_INTEGER_BIG_ENDIAN)