cmake_instrumentation

在版本 4.0 中新增。

注意

只有在透過 CMAKE_EXPERIMENTAL_INSTRUMENTATION gate 啟用儀器功能的實驗性支援時,此命令才可用。

啟用與 CMake Instrumentation API 互動。

這允許在專案層級設定儀器功能。

cmake_instrumentation(
  API_VERSION <version>
  DATA_VERSION <version>
  [HOOKS <hooks>...]
  [QUERIES <queries>...]
  [CALLBACK <callback>]
)

必須始終給定 API_VERSIONDATA_VERSION。目前,這兩個欄位唯一支援的值都是 1。 有關 API_VERSION 的詳細資訊,請參閱 API v1;有關 DATA_VERSION 的詳細資訊,請參閱 Data v1

每個可選關鍵字 HOOKSQUERIESCALLBACK 都對應於 v1 查詢檔案 的參數之一。 可以多次提供 CALLBACK 關鍵字以建立多個回呼。

每當調用 cmake_instrumentation 時,都會在 <build>/.cmake/instrumentation/v1/query/generated 中產生一個查詢檔案,以使用提供的參數啟用儀器功能。

範例

以下範例顯示命令的調用及其等效的 JSON 查詢檔案。

cmake_instrumentation(
  API_VERSION 1
  DATA_VERSION 1
  HOOKS postGenerate preCMakeBuild postCMakeBuild
  QUERIES staticSystemInformation dynamicSystemInformation
  CALLBACK ${CMAKE_COMMAND} -P /path/to/handle_data.cmake
  CALLBACK ${CMAKE_COMMAND} -P /path/to/handle_data_2.cmake
)
{
  "version": 1,
  "hooks": [
    "postGenerate", "preCMakeBuild", "postCMakeBuild"
  ],
  "queries": [
    "staticSystemInformation", "dynamicSystemInformation"
  ],
  "callbacks": [
    "/path/to/cmake -P /path/to/handle_data.cmake"
    "/path/to/cmake -P /path/to/handle_data_2.cmake"
  ]
}