@@ -153,7 +153,7 @@ include(GNUInstallDirs)
153153set (STRINGZILLA_INCLUDE_BUILD_DIR "${PROJECT_SOURCE_DIR} /include/" )
154154set (STRINGZILLA_INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_INCLUDEDIR} " )
155155
156- if (${ CMAKE_VERSION} VERSION_EQUAL 3.13 OR ${ CMAKE_VERSION} VERSION_GREATER 3.13)
156+ if (CMAKE_VERSION VERSION_EQUAL 3.13 OR CMAKE_VERSION VERSION_GREATER 3.13)
157157 include (CTest)
158158 enable_testing ()
159159endif ()
@@ -182,53 +182,52 @@ function (set_compiler_flags target cpp_standard target_arch compiler_id)
182182 endforeach ()
183183
184184 # Set the C++ standard
185- if (NOT ${ cpp_standard} STREQUAL "" )
186- if (${ compiler_id} STREQUAL "NVIDIA" )
185+ if (NOT cpp_standard STREQUAL "" )
186+ if (compiler_id STREQUAL "NVIDIA" )
187187 set_target_properties (${target} PROPERTIES CUDA_STANDARD ${cpp_standard} )
188- elseif (${ compiler_id} MATCHES "MSVC" )
189- # For MSVC, explicitly set the /std: flag
188+ elseif (compiler_id MATCHES "MSVC" )
189+ # For MSVC, explicitly set the /std: flag - don't set CXX_STANDARD property to avoid conflicts
190190 target_compile_options (${target} PRIVATE "/std:c++${cpp_standard} " )
191191 else ()
192192 set_target_properties (${target} PROPERTIES CXX_STANDARD ${cpp_standard} )
193193 endif ()
194194 endif ()
195195
196196 # Use the `/Zc:__cplusplus` flag to correctly define the `__cplusplus` macro in MSVC
197- if (${ compiler_id} MATCHES "MSVC" )
197+ if (compiler_id MATCHES "MSVC" )
198198 target_compile_options (${target} PRIVATE "/Zc:__cplusplus" )
199199 endif ()
200200
201201 # Make sure CUDA C++ allows calling `constexpr` from device code
202- if (${ compiler_id} STREQUAL "NVIDIA" )
202+ if (compiler_id STREQUAL "NVIDIA" )
203203 target_compile_options (${target} PRIVATE "--expt-relaxed-constexpr" )
204204 endif ()
205205
206206 # Maximum warnings level & warnings as error.
207207 #
208208 # MSVC uses numeric values: > 4068 for "unknown pragmas". > 4146 for "unary minus operator applied to unsigned type,
209209 # result still unsigned". We also specify `/utf-8` to properly UTF-8 symbols in tests.
210- if (${ compiler_id} STREQUAL "GNU" )
210+ if (compiler_id STREQUAL "GNU" )
211211 target_compile_options (
212212 ${target}
213213 PRIVATE
214214 "-Wall;-Wextra;-pedantic;-Werror;-Wfatal-errors;-Wno-unknown-pragmas;-Wno-cast-function-type;-Wno-unused-function"
215215 )
216216 target_compile_options (${target} PRIVATE "-Wno-cast-function-type;-Wno-unused-function" ) # ? Unique to GCC
217- elseif (${ compiler_id} STREQUAL "Clang" OR ${ compiler_id} STREQUAL "AppleClang" )
217+ elseif (compiler_id STREQUAL "Clang" OR compiler_id STREQUAL "AppleClang" )
218218 target_compile_options (${target} PRIVATE "-Wall;-Wextra;-pedantic;-Werror;-Wfatal-errors;-Wno-unknown-pragmas" )
219- elseif (${ compiler_id} MATCHES "MSVC" )
219+ elseif (compiler_id MATCHES "MSVC" )
220220 target_compile_options (
221221 ${target}
222- PRIVATE
223- "/Bt" # Display build timings
224- "/wd4068" # Disable warning: unknown pragma
225- "/wd4146" # Disable warning: unary minus operator applied to unsigned type
226- "/wd4996" # Disable warning: 'unsafe' functions like getenv, fopen (use _s variants)
227- "/wd4244" # Disable warning: conversion with possible loss of data (e.g., size_t to double)
228- "/utf-8" # Set source and execution character sets to UTF-8
229- "/WX" # Treat warnings as errors
222+ PRIVATE "/Bt" # Display build timings
223+ "/wd4068" # Disable warning: unknown pragma
224+ "/wd4146" # Disable warning: unary minus operator applied to unsigned type
225+ "/wd4996" # Disable warning: 'unsafe' functions like getenv, fopen (use _s variants)
226+ "/wd4244" # Disable warning: conversion with possible loss of data (e.g., size_t to double)
227+ "/utf-8" # Set source and execution character sets to UTF-8
228+ "/WX" # Treat warnings as errors
230229 )
231- elseif (${ compiler_id} STREQUAL "NVIDIA" )
230+ elseif (compiler_id STREQUAL "NVIDIA" )
232231 target_compile_options (
233232 ${target}
234233 PRIVATE
@@ -237,46 +236,44 @@ function (set_compiler_flags target cpp_standard target_arch compiler_id)
237236 endif ()
238237
239238 # Set optimization options for different compilers differently
240- if (${ compiler_id} MATCHES "MSVC" )
241- if (${ CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo " )
239+ if (compiler_id MATCHES "MSVC" )
240+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
242241 target_compile_options (${target} PRIVATE "/Od;/Zi" )
243242 if (NOT target_type STREQUAL "SHARED_LIBRARY" )
244243 target_compile_options (${target} PRIVATE "/RTC1" )
245244 endif ()
246- endif ()
247- if (${CMAKE_BUILD_TYPE} STREQUAL "Release" OR ${CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo" )
245+ elseif (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
248246 target_compile_options (${target} PRIVATE "/O2;/Zi" )
249247 endif ()
250248 elseif (
251- ${ compiler_id} STREQUAL "GNU"
252- OR ${ compiler_id} STREQUAL "Clang"
253- OR ${ compiler_id} STREQUAL "AppleClang"
249+ compiler_id STREQUAL "GNU"
250+ OR compiler_id STREQUAL "Clang"
251+ OR compiler_id STREQUAL "AppleClang"
254252 )
255- if (${ CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${ CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo" )
253+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
256254 target_compile_options (${target} PRIVATE "-O0;-g" )
257255 endif ()
258- if (${ CMAKE_BUILD_TYPE} STREQUAL "Release" OR ${ CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo" )
256+ if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
259257 target_compile_options (${target} PRIVATE "-O2" )
260258 endif ()
261- elseif (${ compiler_id} STREQUAL "NVIDIA" )
259+ elseif (compiler_id STREQUAL "NVIDIA" )
262260 target_compile_options (
263261 ${target} PRIVATE "-Xcompiler=-Wall" # All warnings (host)
264262 "-Xcompiler=-Wextra" # Extra warnings (host)
265263 )
266264
267- if (${ CMAKE_BUILD_TYPE} STREQUAL "Debug" OR ${ CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo" )
265+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
268266 target_compile_options (
269267 ${target}
270- PRIVATE "-G" # Device debug symbols
271- "-lineinfo" # Include source line info in PTX
268+ PRIVATE "-G" # Device debug symbols, which will add `-lineinfo` symbols to PTX
272269 "-no-compress" # No compression of debug info
273270 "-Xcompiler=-g" # Host debugging symbols explicitly
274271 "-Xcompiler=-fno-omit-frame-pointer" # Stack trace clarity
275272 "-Xcompiler=-fno-inline" # Prevent host inlining
276273 "-maxrregcount=0" # No register count limits
277274 )
278275 endif ()
279- if (${ CMAKE_BUILD_TYPE} STREQUAL "Release" OR ${ CMAKE_BUILD_TYPE} STREQUAL "RelWithDebInfo" )
276+ if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" )
280277 target_compile_options (
281278 ${target}
282279 PRIVATE "-O2" # Disable NVCC optimizations explicitly
@@ -293,7 +290,7 @@ function (set_compiler_flags target cpp_standard target_arch compiler_id)
293290 endif ()
294291
295292 # Avoid builtin functions where we know what we are doing.
296- if (${ compiler_id} MATCHES "MSVC" )
293+ if (compiler_id MATCHES "MSVC" )
297294 target_compile_options (${target} PRIVATE "/Oi-" )
298295 else ()
299296 target_compile_options (${target} PRIVATE "-fno-builtin-memcmp" )
@@ -306,14 +303,14 @@ function (set_compiler_flags target cpp_standard target_arch compiler_id)
306303 if ("${target_arch} " STREQUAL "" )
307304 # Only use the current system if we are not cross compiling
308305 if ((NOT CMAKE_CROSSCOMPILING ) OR (CMAKE_SYSTEM_PROCESSOR MATCHES CMAKE_HOST_SYSTEM_PROCESSOR ))
309- if (${ compiler_id} STREQUAL "NVIDIA" )
306+ if (compiler_id STREQUAL "NVIDIA" )
310307 # For NVCC, pass native flag to host compiler
311308 include (CheckCXXCompilerFlag)
312309 check_cxx_compiler_flag("-march=native" supports_march_native)
313310 if (supports_march_native)
314311 target_compile_options (${target} PRIVATE "-Xcompiler=-march=native" )
315312 endif ()
316- elseif (NOT (${ compiler_id} MATCHES "MSVC" ))
313+ elseif (NOT (compiler_id MATCHES "MSVC" ))
317314 include (CheckCXXCompilerFlag)
318315 check_cxx_compiler_flag("-march=native" supports_march_native)
319316 if (supports_march_native)
@@ -325,9 +322,9 @@ function (set_compiler_flags target cpp_standard target_arch compiler_id)
325322 endif ()
326323 endif ()
327324 else ()
328- if (${ compiler_id} MATCHES "MSVC" )
325+ if (compiler_id MATCHES "MSVC" )
329326 target_compile_options (${target} PRIVATE "/arch:${target_arch} " )
330- elseif (${ compiler_id} STREQUAL "NVIDIA" )
327+ elseif (compiler_id STREQUAL "NVIDIA" )
331328 # NVCC handles CPU architecture through host compiler flags
332329 target_compile_options (${target} PRIVATE "-Xcompiler=-march=${target_arch} " )
333330 else ()
@@ -348,10 +345,10 @@ function (set_compiler_flags target cpp_standard target_arch compiler_id)
348345 if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
349346 target_compile_definitions (${target} PRIVATE "SZ_DEBUG=1" )
350347 if (NOT target_type STREQUAL "SHARED_LIBRARY" )
351- if (${ compiler_id} MATCHES "MSVC" )
348+ if (compiler_id MATCHES "MSVC" )
352349 target_compile_options (${target} PRIVATE "/fsanitize=address;/fsanitize=leak" )
353350 target_link_options (${target} PRIVATE "/fsanitize=address;/fsanitize=leak" )
354- elseif (${ compiler_id} STREQUAL "NVIDIA" )
351+ elseif (compiler_id STREQUAL "NVIDIA" )
355352 # ! NVCC can't handle sanitizers?!
356353 # https://stackoverflow.com/questions/75590579/cuda-fails-to-initialise-when-address-sanitizer-is-enabled
357354 else ()
@@ -367,8 +364,9 @@ endfunction ()
367364function (define_launcher exec_name source cpp_standard target_arch)
368365 add_executable (${exec_name} )
369366 target_sources (${exec_name} PRIVATE ${source} )
370- # TODO: How do we constrain this scope?! set_source_files_properties(${source} TARGET_DIRECTORY ${exec_name}
371- # PROPERTIES LANGUAGE CXX)
367+ # TODO: How do we constrain this scope?!
368+ #
369+ # set_source_files_properties(${source} TARGET_DIRECTORY ${exec_name} PROPERTIES LANGUAGE CXX)
372370 set_compiler_flags(${exec_name} ${cpp_standard} "${target_arch} " "${CMAKE_CXX_COMPILER_ID} " )
373371 target_link_libraries (${exec_name} PRIVATE stringzilla_header)
374372 add_test (NAME ${exec_name} COMMAND ${exec_name} )
@@ -389,7 +387,7 @@ function (define_gpu_launcher exec_name source cuda_standard target_arch)
389387 add_test (NAME ${exec_name} COMMAND ${exec_name} )
390388endfunction ()
391389
392- if (${ STRINGZILLA_BUILD_BENCHMARK} )
390+ if (STRINGZILLA_BUILD_BENCHMARK)
393391 define_launcher(stringzilla_bench_find_cpp20 scripts/bench_find.cpp 20 "${STRINGZILLA_TARGET_ARCH} " )
394392 define_launcher(stringzilla_bench_sequence_cpp20 scripts/bench_sequence.cpp 20 "${STRINGZILLA_TARGET_ARCH} " )
395393 define_launcher(stringzilla_bench_token_cpp20 scripts/bench_token.cpp 20 "${STRINGZILLA_TARGET_ARCH} " )
@@ -413,7 +411,7 @@ if (${STRINGZILLA_BUILD_BENCHMARK})
413411 endif ()
414412endif ()
415413
416- if (${ STRINGZILLA_BUILD_TEST} )
414+ if (STRINGZILLA_BUILD_TEST)
417415 # Make sure that the compilation passes for different C++ standards!
418416 #
419417 # Keep in mind, MSVC only supports C++11 and newer.
@@ -462,14 +460,14 @@ if (${STRINGZILLA_BUILD_TEST})
462460 define_launcher(stringzilla_test_cpp20_serial scripts/test_stringzilla.cpp 20 "armv8-a" )
463461 define_launcher(stringzilla_test_cpp20_neon scripts/test_stringzilla.cpp 20 "armv8-a+simd" )
464462 # SVE is not supported on Apple Silicon, only compile on non-Darwin ARM platforms
465- if (NOT ${ CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
463+ if (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" )
466464 define_launcher(stringzilla_test_cpp20_sve scripts/test_stringzilla.cpp 20 "armv8.2-a+sve" )
467465 endif ()
468466 if (STRINGZILLA_BUILD_CUDA)
469467 define_gpu_launcher(stringzillas_test_cu20_serial scripts/test_stringzillas.cu 20 "armv8-a" )
470468 define_gpu_launcher(stringzillas_test_cu20_neon scripts/test_stringzillas.cu 20 "armv8-a+simd" )
471469 # SVE is not supported on Apple Silicon, only compile on non-Darwin ARM platforms
472- if (NOT ${ CMAKE_SYSTEM_NAME} MATCHES "Darwin" )
470+ if (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" )
473471 define_gpu_launcher(stringzillas_test_cu20_sve scripts/test_stringzillas.cu 20 "armv8.2-a+sve" )
474472 endif ()
475473 endif ()
@@ -483,7 +481,7 @@ target_include_directories(
483481 stringzilla_header INTERFACE $<BUILD_INTERFACE:${STRINGZILLA_INCLUDE_BUILD_DIR} > $<INSTALL_INTERFACE:include >
484482)
485483
486- if (${ STRINGZILLA_BUILD_SHARED} )
484+ if (STRINGZILLA_BUILD_SHARED)
487485
488486 function (define_shared target )
489487 add_library (${target} SHARED c/stringzilla.c)
@@ -536,7 +534,7 @@ if (${STRINGZILLA_BUILD_SHARED})
536534 # Try compiling a version without linking the LibC ! This is only for Linux, as on modern Arm-based MacOS machines !
537535 # We can't legally access Arm's "feature registers" without `sysctl` or `sysctlbyname`. Also exclude MSVC builds as
538536 # they have linker issues with bare builds.
539- if (NOT ${ CMAKE_SYSTEM_NAME} MATCHES "Darwin" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
537+ if (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin" AND NOT CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
540538 define_shared(stringzilla_bare)
541539 target_compile_definitions (stringzilla_bare PRIVATE "SZ_AVOID_LIBC=1" )
542540 target_compile_definitions (stringzilla_bare PRIVATE "SZ_OVERRIDE_LIBC=1" )
@@ -548,7 +546,7 @@ if (${STRINGZILLA_BUILD_SHARED})
548546 endif ()
549547endif ()
550548
551- if (${ STRINGZILLAS_BUILD_SHARED} )
549+ if (STRINGZILLAS_BUILD_SHARED)
552550 # StringZillas shared library targets for parallel string operations
553551 function (define_stringzillas_shared target source_file backend_flags)
554552 add_library (${target} SHARED ${source_file} )
0 commit comments