2014-09-18 22 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