出于调试目的,我可以访问
配置时间,其中CMake功能/宏已调用。 (我想通过我自己的组件的包装器函数自动注入这些信息,以跟踪缓存变量被覆盖的时间和位置。)
虽然1.似乎正在评估CMAKE_CURRENT_LIST_FILE,但我无法弄清楚如何实现2. CMAKE_CURRENT_LIST_LINE始终设置为实际放置的行,在我的情况下是包装函数内的行。
根据建议in the CMake bugtracker,我可以在调用者站点上执行此操作,并将[CMAKE_CURRENT_LIST_LINE] [3]作为附加参数。但是我想避免这种情况来隐藏“公共接口”中的调试逻辑。
表达我想要的最小工作示例:
的CMakeLists.txt :
cmake_minimum_required(VERSION 3.0)
include( myComponent )
# access via public interface
myComponentFunctionWrapperFunction( "CMakeLists.txt:5" )
myComponentFunctionWrapperMacro( "CMakeLists.txt:6" )
myComponentMacroWrapperFunction( "CMakeLists.txt:7" )
myComponentMacroWrapperMacro( "CMakeLists.txt:8" )
# direct access of the hidden interface
myComponentFunction( ${CMAKE_CURRENT_LIST_FILE} ${CMAKE_CURRENT_LIST_LINE} "CMakeLists.txt:11" )
myComponentFunction( ${CMAKE_CURRENT_LIST_FILE} ${CMAKE_CURRENT_LIST_LINE} "CMakeLists.txt:12" )
myComponentMacro( ${CMAKE_CURRENT_LIST_FILE} ${CMAKE_CURRENT_LIST_LINE} "CMakeLists.txt:13" )
myComponentMacro( ${CMAKE_CURRENT_LIST_FILE} ${CMAKE_CURRENT_LIST_LINE} "CMakeLists.txt:14" )
myComponent.cmake :
# the actual component
function( myComponentFunction CALLER CALLER_LINE DATA )
message( STATUS "myComponent.function( ${CALLER}, ${CALLER_LINE}, ${DATA} )" )
endfunction()
macro( myComponentMacro CALLER CALLER_LINE DATA )
message( STATUS "myComponent.macro( ${CALLER}, ${CALLER_LINE}, ${DATA} )" )
endmacro()
# the public interface for injecting debug info
function( myComponentFunctionWrapperFunction DATA )
myComponentFunction( ${CMAKE_CURRENT_LIST_FILE} ${CMAKE_CURRENT_LIST_LINE} ${DATA} )
endfunction()
macro( myComponentFunctionWrapperMacro DATA )
myComponentFunction( ${CMAKE_CURRENT_LIST_FILE} ${CMAKE_CURRENT_LIST_LINE} ${DATA} )
endmacro()
function( myComponentMacroWrapperFunction DATA )
myComponentMacro( ${CMAKE_CURRENT_LIST_FILE} ${CMAKE_CURRENT_LIST_LINE} ${DATA} )
endfunction()
macro( myComponentMacroWrapperMacro DATA )
myComponentMacro( ${CMAKE_CURRENT_LIST_FILE} ${CMAKE_CURRENT_LIST_LINE} ${DATA} )
endmacro()
执行:
$ cmake -D CMAKE_MODULE_PATH=`pwd` .
-- myComponent.function( <myPath>/CMakeLists.txt, 15, CMakeLists.txt:5 )
-- myComponent.function( <myPath>/CMakeLists.txt, 19, CMakeLists.txt:6 )
-- myComponent.macro( <myPath>/CMakeLists.txt, 23, CMakeLists.txt:7 )
-- myComponent.macro( <myPath>/CMakeLists.txt, 27, CMakeLists.txt:8 )
-- myComponent.function( <myPath>/CMakeLists.txt, 11, CMakeLists.txt:11 )
-- myComponent.function( <myPath>/CMakeLists.txt, 12, CMakeLists.txt:12 )
-- myComponent.macro( <myPath>/CMakeLists.txt, 13, CMakeLists.txt:13 )
-- myComponent.macro( <myPath>/CMakeLists.txt, 14, CMakeLists.txt:14 )
-- Configuring done
也许我可以以某种方式访问堆栈跟踪?如果您发出例如消息(警告...),则行号可用。但我想存储它们,而不仅仅是在终端上打印它们。 有什么想法吗?
答案 0 :(得分:0)
不确定这是否可行。
我想通过包装函数自动注入这些信息 我自己的组件跟踪缓存变量的时间和地点 重写)
您是否尝试过使用cmake和--trace(如果你有最近的CMake版本,甚至是--trace-expand)?这可能是实现目标的更好方式