gemini-code-assist[bot] commented on code in PR #126: URL: https://github.com/apache/tvm-ffi/pull/126#discussion_r2432093716
########## cmake/config.cmake: ########## @@ -0,0 +1,26 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +set(CMAKE_BUILD_TYPE RelWithDebInfo) + +# Options +set(TVM_FFI_USE_LIBBACKTRACE ON) +set(TVM_FFI_USE_EXTRA_CXX_API ON) +set(TVM_FFI_BACKTRACE_ON_SEGFAULT ON) +set(TVM_FFI_ATTACH_DEBUG_SYMBOLS OFF) +set(TVM_FFI_BUILD_TESTS OFF) +set(TVM_FFI_BUILD_PYTHON_MODULE OFF) Review Comment:  Using `set()` without `CACHE` for these options creates normal variables that will override any values set on the command line (e.g., `-DTVM_FFI_BUILD_TESTS=ON`) or in the CMake cache. This behavior is contrary to standard CMake practice and can be confusing for users who expect command-line arguments to have the highest precedence. To fix this, you should define these as `CACHE` variables. Using `set(... CACHE ...)` without `FORCE` ensures that the value is only set if it's not already in the cache, thus respecting user-provided command-line options. ``` set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build") # Options set(TVM_FFI_USE_LIBBACKTRACE ON CACHE BOOL "Enable libbacktrace") set(TVM_FFI_USE_EXTRA_CXX_API ON CACHE BOOL "Enable extra CXX API in shared lib") set(TVM_FFI_BACKTRACE_ON_SEGFAULT ON CACHE BOOL "Set signal handler to print backtrace on segfault") set(TVM_FFI_ATTACH_DEBUG_SYMBOLS OFF CACHE BOOL "Attach debug symbols even in release mode") set(TVM_FFI_BUILD_TESTS OFF CACHE BOOL "Adding test targets.") set(TVM_FFI_BUILD_PYTHON_MODULE OFF CACHE BOOL "Adding python module.") ``` ########## CMakeLists.txt: ########## @@ -19,6 +19,20 @@ cmake_minimum_required(VERSION 3.18) project(tvm_ffi LANGUAGES CXX C) +# load the config.cmake file +if (EXISTS ${CMAKE_BINARY_DIR}/config.cmake) + message(STATUS "Config file: ${CMAKE_BINARY_DIR}/config.cmake") + include(${CMAKE_BINARY_DIR}/config.cmake) +elseif (EXISTS ${PROJECT_SOURCE_DIR}/config.cmake) + message(STATUS "Config file: ${PROJECT_SOURCE_DIR}/config.cmake") + include(${PROJECT_SOURCE_DIR}/config.cmake) +elseif (EXISTS ${PROJECT_SOURCE_DIR}/cmake/config.cmake) + message(STATUS "Config file: ${PROJECT_SOURCE_DIR}/cmake/config.cmake") + include(${PROJECT_SOURCE_DIR}/cmake/config.cmake) +else () + message(STATUS "No config.cmake found. Using the default config") +endif () Review Comment:  This `if/elseif` chain for finding `config.cmake` is a bit repetitive and can be simplified by using the `find_file` command. This is a more idiomatic and maintainable approach in modern CMake for searching for a file across multiple directories. ``` find_file(_tvm_ffi_config_file NAMES config.cmake PATHS ${CMAKE_BINARY_DIR} ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/cmake ) if(_tvm_ffi_config_file) message(STATUS "Config file: ${_tvm_ffi_config_file}") include(${_tvm_ffi_config_file}) else() message(STATUS "No config.cmake found. Using the default config") 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]
