2014-09-18 19 views
0

我有一個cmake項目,其中包含許多不同的目標。首先它構建一個用於處理一些數據文件的可執行文件(讓我們調用這個DataProcessor)。然後它用可執行文件處理這些數據文件。然後,構建第二個可執行文件(我們稱之爲MyApp),並與處理後的數據文件一起運行。策略CMP0026未設置:禁止使用LOCATION目標屬性

還有一個目標,它將所有已處理的數據文件和MyApp都捆綁到一個tar文件中,以便我們分發它們。

在我的CMakeLists.txt文件中,有我有以下行:

get_target_property(DATA_PROCESSOR_EXE DataProcessor LOCATION) 
get_target_property(MY_APP_EXE MyApp LOCATION) 

我需要這些在我CMakeLists文件運行各種其他命令。例如,DATA_PROCESSOR_EXE在自定義命令用於處理數據文件,就像這樣:

add_custom_command(
    OUTPUT ${DATA_OUT} 
    COMMAND ${DATA_PROCESSOR_EXE} -o ${DATA_OUT} ${DATA_IN} 
    DEPENDS DataProcessor) 

當我捆了一切我使用MyApp的位置,以及:

# Convert executable paths to relative paths. 
string(REPLACE "${CMAKE_SOURCE_DIR}/" "" MY_APP_EXE_RELATIVE 
     "${MY_APP_EXE}") 
string(REPLACE "${CMAKE_SOURCE_DIR}/" "" DATA_PROCESSOR_EXE_RELATIVE 
     "${DATA_PROCESSOR_EXE}") 

# The set of files and folders to export 
set(EXPORT_FILES 
    assets 
    src/rawdata 
    ${MY_APP_EXE_RELATIVE} 
    ${DATA_PROCESSOR_EXE_RELATIVE}) 

# Create a zipped tar of all the necessary files to run the game. 
add_custom_target(export 
    COMMAND cd ${CMAKE_SOURCE_DIR} && tar -czvf myapp.tar.gz ${EXPORT_FILES} 
    DEPENDS splat 
    WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/..) 

的問題是,試圖現在得到目標的位置特性將導致警告說法:

CMake Warning (dev) at CMakeLists.txt:86 (get_target_property): 
    Policy CMP0026 is not set: Disallow use of the LOCATION target property. 
    Run "cmake --help-policy CMP0026" for policy details. Use the cmake_policy 
    command to set the policy and suppress this warning. 

    The LOCATION property should not be read from target "DataProcessor". 
    Use the target name directly with add_custom_command, or use the generator 
    expression $<TARGET_FILE>, as appropriate. 

我不明白它是如何想我使用add_custome_command或意味着什麼由use the generator expression $<TARGET_FILE>

回答

1

add_custom_command瞭解目標名稱。您無需自己提取位置。

更換代碼一樣

add_custom_command(
    OUTPUT ${DATA_OUT} 
    COMMAND ${DATA_PROCESSOR_EXE} 

下面類似的代碼

add_custom_command(
    OUTPUT ${DATA_OUT} 
    COMMAND DataProcessor 

即使用目標的名字。

CMake在'configure time'上運行命令行代碼時,輸​​出可執行文件的最終位置是未知的。但是,add_custom_target可以被告知創建構建規則,其內容僅在生成時(配置時間後)已知。做到這一點的方法是使用生成器表達式。

http://www.cmake.org/cmake/help/v3.0/manual/cmake-generator-expressions.7.html#informational-expressions

使用$ < TARGET_FILE_DIR:MyApp的的>而不是$ {} MY_APP_EXE_RELATIVE在add_custom_target調用,例如。

+0

這似乎解決了我剛剛處理數據的第一種情況,但我無法弄清楚如何獲得調用tar的相對路徑,如果甚至可能的話。似乎我需要做一些字符串替換,據我所知,這是不支持的。 – Alex 2014-09-19 23:05:03