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 set(TNG_MAJOR_VERSION "1")
9 set(TNG_MINOR_VERSION "8")
10 set(TNG_VERSION_PATCH_LEVEL "1")
11 set(TNG_IO_VERSION "${TNG_MAJOR_VERSION}.${TNG_MINOR_VERSION}.${TNG_VERSION_PATCH_LEVEL}")
13 function (TNG_GENERATE_VERSION_H)
14 set(TNG_API_VERSION "8")
15 configure_file(${TNG_ROOT_SOURCE_DIR}/include/tng/version.h.in
16 ${TNG_ROOT_BINARY_DIR}/include/tng/version.h)
18 set(TNG_MAJOR_VERSION ${TNG_MAJOR_VERSION} PARENT_SCOPE)
19 set(TNG_IO_VERSION ${TNG_IO_VERSION} PARENT_SCOPE)
22 include(TestBigEndian)
23 test_big_endian(TNG_INTEGER_BIG_ENDIAN)
24 include(CheckIncludeFile)
25 check_include_file(inttypes.h TNG_HAVE_INTTYPES_H)
26 include(CMakeParseArguments)
28 function(add_tng_io_library NAME)
29 tng_generate_version_h()
31 set(_tng_compression_sources
32 bwlzh.c bwt.c coder.c dict.c fixpoint.c huffman.c huffmem.c
33 lz77.c merge_sort.c mtf.c rle.c tng_compress.c vals16.c
34 warnmalloc.c widemuldiv.c xtc2.c xtc3.c)
35 set(_tng_io_sources tng_io.c md5.c)
37 foreach(_file ${_tng_compression_sources})
38 list(APPEND _sources ${TNG_ROOT_SOURCE_DIR}/src/compression/${_file})
40 foreach(_file ${_tng_io_sources})
41 list(APPEND _sources ${TNG_ROOT_SOURCE_DIR}/src/lib/${_file})
44 list(APPEND _sources ${TNG_ROOT_SOURCE_DIR}/src/lib/tng_io_fortran.c)
47 set(_options OBJECT OWN_ZLIB)
48 cmake_parse_arguments(ARG "${_options}" "" "" ${ARGN})
50 set(_build_target ${NAME})
51 set(_link_type PRIVATE)
53 set(_build_target tng_io_obj)
54 set(_link_type INTERFACE)
55 add_library(${_build_target} OBJECT ${_sources})
56 # PIC is only on by default for SHARED libraries, but in case the
57 # object library is going to get used in such a library, the objects
58 # should be compiled with PIC as well.
59 if (BUILD_SHARED_LIBS)
60 set_target_properties(${_build_target} PROPERTIES POSITION_INDEPENDENT_CODE ON)
62 add_library(${NAME} INTERFACE)
63 target_sources(${NAME} INTERFACE $<TARGET_OBJECTS:tng_io_obj>)
65 add_library(${NAME} ${_sources})
66 set_target_properties(${NAME} PROPERTIES
67 VERSION ${TNG_IO_VERSION}
68 SOVERSION ${TNG_MAJOR_VERSION})
69 target_include_directories(${NAME} INTERFACE $<INSTALL_INTERFACE:include>)
71 target_include_directories(${_build_target} PRIVATE
72 $<BUILD_INTERFACE:${TNG_ROOT_SOURCE_DIR}/include>
73 $<BUILD_INTERFACE:${TNG_ROOT_BINARY_DIR}/include>)
74 target_include_directories(${NAME} INTERFACE
75 $<BUILD_INTERFACE:${TNG_ROOT_SOURCE_DIR}/include>
76 $<BUILD_INTERFACE:${TNG_ROOT_BINARY_DIR}/include>)
79 target_link_libraries(${NAME} ${_link_type} m)
83 set(_zlib_dir ${TNG_ROOT_SOURCE_DIR}/external/zlib)
85 # Add minimal necessary number of TNG source files
86 foreach(_file adler32.c compress.c crc32.c deflate.c inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c)
87 list(APPEND _zlib_sources ${_zlib_dir}/${_file})
89 add_library(tng_io_zlib OBJECT ${_zlib_sources})
90 if (BUILD_SHARED_LIBS)
91 set_target_properties(tng_io_zlib PROPERTIES POSITION_INDEPENDENT_CODE ON)
93 target_include_directories(tng_io_zlib PUBLIC ${_zlib_dir})
94 target_include_directories(${_build_target} PRIVATE ${_zlib_dir})
95 target_sources(${NAME} ${_link_type} $<TARGET_OBJECTS:tng_io_zlib>)
97 target_link_libraries(${NAME} ${_link_type} ZLIB::ZLIB)
100 if (TNG_HAVE_INTTYPES_H)
101 target_compile_definitions(${NAME} INTERFACE USE_STD_INTTYPES_H)
102 set_property(SOURCE ${TNG_ROOT_SOURCE_DIR}/src/lib/tng_io.c
103 APPEND PROPERTY COMPILE_DEFINITIONS USE_STD_INTTYPES_H)
105 if (TNG_INTEGER_BIG_ENDIAN)
106 set_property(SOURCE ${TNG_ROOT_SOURCE_DIR}/src/lib/md5.c
107 APPEND PROPERTY COMPILE_DEFINITIONS TNG_INTEGER_BIG_ENDIAN)