@@ -101,10 +101,14 @@ endif()
101101
102102include_directories (${PROJECT_INCLUDE_DIR} )
103103
104- # Mark every translation unit that is compiled into the tsfile library so that
105- # TSFILE_API (see utils/util_define.h) resolves to an export-side (empty)
106- # decoration here, and to __declspec(dllimport) for external consumers.
107- add_definitions (-DTSFILE_BUILDING )
104+ # Configure TSFILE_API (see utils/util_define.h) for every translation unit
105+ # compiled into the tsfile library. Shared builds export data symbols, while
106+ # static builds do not use DLL import/export decorations.
107+ if (TSFILE_BUILD_SHARED)
108+ add_definitions (-DTSFILE_BUILDING )
109+ else ()
110+ add_definitions (-DTSFILE_STATIC )
111+ endif ()
108112
109113if (ENABLE_ANTLR4)
110114 add_subdirectory (parser )
@@ -150,7 +154,14 @@ target_link_libraries(common_obj ${COMPRESSION_LIBS})
150154target_link_libraries (read_obj ${COMPRESSION_LIBS} )
151155target_link_libraries (write_obj ${COMPRESSION_LIBS} )
152156
153- add_library (tsfile SHARED )
157+ if (TSFILE_BUILD_SHARED)
158+ add_library (tsfile SHARED )
159+ else ()
160+ add_library (tsfile STATIC )
161+ # Consumers of the CMake target must see TSFILE_API without DLL import
162+ # decoration when linking the static library on MSVC.
163+ target_compile_definitions (tsfile INTERFACE TSFILE_STATIC )
164+ endif ()
154165
155166if (${COV_ENABLED} )
156167 message ("Enable code cov..." )
@@ -177,14 +188,16 @@ endif()
177188
178189add_dependencies (tsfile utils_obj encoding_obj )
179190
180- set (LIBTSFILE_PROJECT_VERSION ${TsFile_CPP_VERSION} )
181- set (LIBTSFILE_SO_VERSION ${TsFile_CPP_VERSION} )
182- set_target_properties (tsfile PROPERTIES VERSION ${LIBTSFILE_PROJECT_VERSION} )
183- set_target_properties (tsfile PROPERTIES SOVERSION ${LIBTSFILE_SO_VERSION} )
191+ if (TSFILE_BUILD_SHARED)
192+ set (LIBTSFILE_PROJECT_VERSION ${TsFile_CPP_VERSION} )
193+ set (LIBTSFILE_SO_VERSION ${TsFile_CPP_VERSION} )
194+ set_target_properties (tsfile PROPERTIES VERSION ${LIBTSFILE_PROJECT_VERSION} )
195+ set_target_properties (tsfile PROPERTIES SOVERSION ${LIBTSFILE_SO_VERSION} )
196+ endif ()
184197
185- # On Windows a SHARED library produces a .dll ( RUNTIME) plus an import .lib
186- # (ARCHIVE); on Unix it produces a .so (LIBRARY) . Cover all three so the
187- # install step works for every platform .
198+ # A shared library is a RUNTIME plus an import ARCHIVE on Windows and a LIBRARY
199+ # on Unix. A static library is an ARCHIVE on every platform . Cover all three so
200+ # the install step works for either library type .
188201install (TARGETS tsfile
189202 RUNTIME DESTINATION ${LIBRARY_OUTPUT_PATH }
190203 LIBRARY DESTINATION ${LIBRARY_OUTPUT_PATH }
0 commit comments