gemini-code-assist[bot] commented on code in PR #153:
URL: https://github.com/apache/tvm-ffi/pull/153#discussion_r2437457618
##########
CMakeLists.txt:
##########
@@ -37,6 +37,13 @@ include(${CMAKE_CURRENT_LIST_DIR}/cmake/Utils/Library.cmake)
# linking
add_library(tvm_ffi_header INTERFACE)
target_compile_features(tvm_ffi_header INTERFACE cxx_std_17)
+
+if (CMAKE_C_BYTE_ORDER STREQUAL "BIG_ENDIAN")
+ target_compile_definitions(tvm_ffi_header INTERFACE
TVM_FFI_CMAKE_LITTLE_ENDIAN=0)
+elseif (CMAKE_C_BYTE_ORDER STREQUAL "LITTLE_ENDIAN")
+ target_compile_definitions(tvm_ffi_header INTERFACE
TVM_FFI_CMAKE_LITTLE_ENDIAN=1)
+endif ()
Review Comment:

The current `if/elseif` block is a bit repetitive. You can make this more
concise by using `string(COMPARE ...)` to set a boolean variable (`1` for true,
`0` for false) and then call `target_compile_definitions` only once. This
approach is more idiomatic for modern CMake and reduces code duplication,
improving maintainability. It relies on the fact that if `CMAKE_C_BYTE_ORDER`
is set, it will be either `LITTLE_ENDIAN` or `BIG_ENDIAN`.
```
if(CMAKE_C_BYTE_ORDER)
string(COMPARE EQUAL "${CMAKE_C_BYTE_ORDER}" "LITTLE_ENDIAN"
is_little_endian)
target_compile_definitions(tvm_ffi_header INTERFACE
TVM_FFI_CMAKE_LITTLE_ENDIAN=${is_little_endian})
endif()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]