@@ -32,10 +32,15 @@ endif ()
3232set (TsFile_CPP_VERSION 2.2.1.dev)
3333
3434if (MSVC )
35- # MSVC has no /std:c++11 flag; pin the closest supported standard mode.
35+ # MSVC does not provide a /std:c++11 flag; C++11 is its implicit baseline.
36+ # The lowest explicitly settable standard is /std:c++14. Without this flag,
37+ # the default varies by VS version (VS2017+ defaults to C++14 mode with some
38+ # C++17 extensions), so we pin it explicitly for reproducibility.
3639 set (CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} /W3 /utf-8 /EHsc /bigobj /Zc:__cplusplus /std:c++14" )
3740 add_definitions (-DNOMINMAX -D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_WARNINGS
3841 -D_SCL_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS )
42+ # Export all symbols of the tsfile shared library automatically so that
43+ # consumers do not need __declspec(dllexport) annotations.
3944 set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
4045else ()
4146 set (CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -Wall" )
@@ -46,6 +51,8 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
4651endif ()
4752
4853message ("cmake using: USE_CPP11=${USE_CPP11} " )
54+ # MSVC has no /std:c++11; CMake maps this to the closest supported standard
55+ # (C++14 default on MSVC), which compiles the C++11 codebase fine.
4956set (CMAKE_CXX_STANDARD 11)
5057set (CMAKE_CXX_STANDARD_REQUIRED OFF )
5158if (NOT MSVC )
@@ -73,6 +80,13 @@ if (${COV_ENABLED})
7380 message ("add_definitions -DCOV_ENABLED=1" )
7481endif ()
7582
83+ option (ENABLE_MEM_STAT "Enable memory status" ON )
84+
85+ if (ENABLE_MEM_STAT)
86+ add_definitions (-DENABLE_MEM_STAT )
87+ message ("add_definitions -DENABLE_MEM_STAT" )
88+ endif ()
89+
7690
7791if (NOT CMAKE_BUILD_TYPE )
7892 set (CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE )
@@ -91,25 +105,46 @@ else ()
91105endif ()
92106
93107message ("CMAKE BUILD TYPE " ${CMAKE_BUILD_TYPE } )
94- if (NOT MSVC )
95- if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
96- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG } -O0 -g" )
97- elseif (CMAKE_BUILD_TYPE STREQUAL "Release" )
98- # -flto + MinGW gcc + statically-linked antlr4_static produces
99- # unresolved-reference errors at link time (LTO intermediate objects
100- # can't see the .a's vtable thunks). -march=native is also a poor
101- # default for CI binaries shipped to other machines. Keep both on
102- # Linux/macOS where the optimization actually pays off.
103- if (MINGW OR WIN32 )
104- set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE } -O3" )
105- else ()
106- set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE } -O3 -march=native -flto" )
108+ # Keep optimization policy external by default (caller/toolchain/CMake defaults).
109+ set (TSFILE_OPTIMIZATION_FLAGS ""
110+ CACHE STRING
111+ "Optional extra optimization flags for tsfile-cpp (e.g. -O3). Empty means inherit caller defaults." )
112+ if (TSFILE_OPTIMIZATION_FLAGS)
113+ # Apply after CMake defaults for each config so explicit optimization can
114+ # override default -O flags in Release/RelWithDebInfo/Debug/MinSizeRel.
115+ set (CMAKE_CXX_FLAGS_DEBUG
116+ "${CMAKE_CXX_FLAGS_DEBUG } ${TSFILE_OPTIMIZATION_FLAGS} " )
117+ set (CMAKE_CXX_FLAGS_RELEASE
118+ "${CMAKE_CXX_FLAGS_RELEASE } ${TSFILE_OPTIMIZATION_FLAGS} " )
119+ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO
120+ "${CMAKE_CXX_FLAGS_RELWITHDEBINFO } ${TSFILE_OPTIMIZATION_FLAGS} " )
121+ set (CMAKE_CXX_FLAGS_MINSIZEREL
122+ "${CMAKE_CXX_FLAGS_MINSIZEREL } ${TSFILE_OPTIMIZATION_FLAGS} " )
123+ message ("cmake using: TSFILE_OPTIMIZATION_FLAGS=${TSFILE_OPTIMIZATION_FLAGS} " )
124+ else ()
125+ message ("cmake using: TSFILE_OPTIMIZATION_FLAGS=<inherit>" )
126+ # MSVC provides sensible per-configuration optimization flags by default; the
127+ # GCC-style flags below would be rejected by cl.exe, so skip them on MSVC.
128+ if (NOT MSVC )
129+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
130+ set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG } -O0 -g" )
131+ elseif (CMAKE_BUILD_TYPE STREQUAL "Release" )
132+ # -flto + MinGW gcc + statically-linked antlr4_static produces
133+ # unresolved-reference errors at link time (LTO intermediate objects
134+ # can't see the .a's vtable thunks). -march=native is also a poor
135+ # default for CI binaries shipped to other machines. Keep both on
136+ # Linux/macOS where the optimization actually pays off.
137+ if (MINGW OR WIN32 )
138+ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE } -O3" )
139+ else ()
140+ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE } -O3 -march=native -flto" )
141+ endif ()
142+ elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
143+ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO } -O2 -g" )
144+ elseif (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" )
145+ set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL } -ffunction-sections -fdata-sections -Os" )
146+ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS } -Wl,--gc-sections" )
107147 endif ()
108- elseif (CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
109- set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO } -O2 -g" )
110- elseif (CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" )
111- set (CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL } -ffunction-sections -fdata-sections -Os" )
112- set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS } -Wl,--gc-sections" )
113148 endif ()
114149endif ()
115150message ("CMAKE DEBUG: CMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS } " )
@@ -120,11 +155,22 @@ option(ENABLE_ASAN "Enable Address Sanitizer" OFF)
120155if (ENABLE_ASAN)
121156 message ("Address Sanitizer is enabled." )
122157 if (MSVC )
158+ # MSVC ships AddressSanitizer; it requires Visual Studio 2019 16.9 or
159+ # newer (MSVC_VERSION >= 1928). Only the address sanitizer is available
160+ # (there is no UndefinedBehaviorSanitizer for MSVC).
123161 if (MSVC_VERSION LESS 1928)
124162 message (FATAL_ERROR
125163 "ENABLE_ASAN requires MSVC 19.28+ (Visual Studio 2019 16.9); "
126164 "detected MSVC_VERSION=${MSVC_VERSION } ." )
127165 endif ()
166+ # /fsanitize=address is incompatible with the /RTC* runtime checks that
167+ # CMake injects into Debug builds, and with incremental linking. Strip
168+ # /RTC* from the per-config flags and force non-incremental linking.
169+ #
170+ # ASan also needs debug info: /Zi (compile) + /DEBUG (link). Without it
171+ # MSVC emits warning C5072 ("ASAN enabled without debug information
172+ # emission"), which the bundled googletest build promotes to an error
173+ # via /WX in Release builds, and ASan reports lose symbol/line info.
128174 add_compile_options (/fsanitize=address /Zi )
129175 foreach (flagsVar
130176 CMAKE_C_FLAGS_DEBUG CMAKE_CXX_FLAGS_DEBUG
@@ -135,19 +181,6 @@ if (ENABLE_ASAN)
135181 elseif (NOT WIN32 )
136182 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } -fsanitize=address,undefined -fno-omit-frame-pointer" )
137183
138- # -flto + libstdc++ <regex> produces spurious ODR-violation reports
139- # under ASan (globals like __classnames / __collatenames in
140- # bits/regex.tcc show up once per LTO partition).
141- #
142- # -march=native lets gcc autovectorize tight byte-stride loops
143- # (e.g. Int64Packer::unpack_8values) into AVX2 32-byte gathers
144- # that overread by up to one SIMD lane past the end of the input
145- # buffer; the read sits inside ASan's redzone and ASan traps it
146- # as SEGV. The non-vectorized scalar code is correct, so just
147- # drop the aggressive flags whenever ASan is on.
148- string (REGEX REPLACE "(^| )-flto( |$)" " " CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE } " )
149- string (REGEX REPLACE "(^| )-march=native( |$)" " " CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE } " )
150-
151184 if (NOT APPLE )
152185 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS } -static-libasan" )
153186 set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS } -fsanitize=address,undefined -static-libasan -static-libubsan" )
@@ -198,10 +231,6 @@ if (ENABLE_ZLIB)
198231 add_definitions (-DENABLE_GZIP )
199232endif ()
200233
201- option (ENABLE_SIMD "Enable SIMD acceleration via SIMDe" ON )
202- message ("cmake using: ENABLE_SIMD=${ENABLE_SIMD} " )
203- set (ENABLE_SIMDE ${ENABLE_SIMD} CACHE BOOL "Enable SIMDe (SIMD Everywhere)" FORCE )
204-
205234option (ENABLE_THREADS "Enable multi-threaded read/write (requires pthreads)" ON )
206235message ("cmake using: ENABLE_THREADS=${ENABLE_THREADS} " )
207236
@@ -211,11 +240,11 @@ if (ENABLE_THREADS)
211240 link_libraries (Threads::Threads )
212241endif ()
213242
214- option (ENABLE_MEM_STAT "Enable per-module memory allocation statistics" ON )
215- message ("cmake using: ENABLE_MEM_STAT =${ENABLE_MEM_STAT } " )
243+ option (ENABLE_SIMDE "Enable SIMDe (SIMD Everywhere)" OFF )
244+ message ("cmake using: ENABLE_SIMDE =${ENABLE_SIMDE } " )
216245
217- if (ENABLE_MEM_STAT )
218- add_definitions (-DENABLE_MEM_STAT )
246+ if (ENABLE_SIMDE )
247+ add_definitions (-DENABLE_SIMDE )
219248endif ()
220249
221250# All libs will be stored here, including libtsfile, compress-encoding lib.
@@ -231,12 +260,15 @@ set(THIRD_PARTY_INCLUDE ${PROJECT_BINARY_DIR}/third_party)
231260
232261set (SAVED_CXX_FLAGS "${CMAKE_CXX_FLAGS } " )
233262if (MSVC )
263+ # MSVC does not provide a /std:c++11 flag; C++11 is its implicit baseline.
264+ # The lowest explicitly settable standard is /std:c++14. Without this flag,
265+ # the default varies by VS version (VS2017+ defaults to C++14 mode with some
266+ # C++17 extensions), so we pin it explicitly for reproducibility.
234267 set (CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} /W3 /utf-8 /EHsc /bigobj /Zc:__cplusplus /std:c++14" )
235268else ()
236269 set (CMAKE_CXX_FLAGS "$ENV{CXXFLAGS} -Wall -std=c++11" )
237270endif ()
238271add_subdirectory (third_party )
239- set (CMAKE_CXX_FLAGS "${SAVED_CXX_FLAGS} " )
240272
241273add_subdirectory (src )
242274if (BUILD_TEST)
@@ -248,11 +280,5 @@ else()
248280 message ("BUILD_TEST is OFF, skipping test directory" )
249281endif ()
250282
251- option (BUILD_EXAMPLES "Build examples (requires Arrow/Parquet)" OFF )
252- if (BUILD_EXAMPLES)
253- add_subdirectory (examples )
254- endif ()
283+ add_subdirectory (examples )
255284
256- if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR } /experiment/CMakeLists.txt" )
257- add_subdirectory (experiment )
258- endif ()
0 commit comments