<?xml version="1.0" encoding="UTF-8" ?>
<project name="winplay" default="build">
<target name="build">
<echo message="${bitoption}" />
<mkdir dir="build" />
<mkdir dir="build/obj" />
<cc name="g++" objdir="build/obj" debug="${debug}">
<fileset dir="src" includes="*.cpp" />
<compiler name="g++">
<compilerarg value="-std=c++11" />
<compilerarg value="-m32" />
</compiler>
</cc>
<condition property="debugoption" value="-g -O0" else="-O2">
<isset property="debug" />
</condition>
<fileset dir="build/obj" id="objects">
<include name="*.o" />
</fileset>
<pathconvert pathsep=" " property="objectslinker" refid="objects" />
<!-- Due to a bug in GppLinker.java in cpptasks.jar, we must exec g++ because GppLinker erroneously uses gcc, which breaks exception handling. -->
<exec command="g++ -std=c++11 -m32 -mwindows ${debugoption} -o build/winplay ${objectslinker}" failonerror="true" />
</target>
<target name="build-32" depends="build">
<property name="bitoption" value="-m32" />
</target>
<target name="build-64" depends="build">
<property name="bitoption" value="-m64" />
</target>
<target name="clean">
<delete dir="build" />
</target>
</project>
我试图让$ {bitoption}成为-m32或-m64,具体取决于我们是否调用了目标build-32或build-64。然后我将$ {bitoption}传递给编译器和链接器args,这样我就可以生成相应的exe。我做了一个简单的回声测试,看看是否正确设置了$ {bitoption},它似乎不起作用。我得到的只是:
Buildfile: E:\_dev\windows\MinGW\msys\home\windoze\projects\Winplay\build.xml
build:
[echo] ${bitoption}
[cc] 1 total files to be compiled.
[exec] The command attribute is deprecated.
[exec] Please use the executable attribute and nested arg elements.
build-64:
BUILD SUCCESSFUL
Total time: 1 second
答案 0 :(得分:2)
构建目标总是先运行,因为它是一个依赖项,所以$ {bitoption}还没有值。
你可以这样做:
<target name="build-32" depends="setup-32, build" />
<target name="build-64" depends="setup-64, build" />
<target name="setup-32">
<property name="bitoption" value="-m32" />
</target>
<target name="setup-64">
<property name="bitoption" value="-m64" />
</target>