使用ant構建c++ 程序

          Posted on 2010-05-06 23:52 梧桐夜雨 閱讀(955) 評論(0)  編輯  收藏

          使用ant構建c++ 程序 需要先下載 cpptasks  為了一些附加的功能需要下載ant-contrib (http://ant-contrib.sourceforge.net/) ,安裝這兩個工具很簡單,只需要降cpptasks.jar 和antcontrib.jar 拷貝到ant_home/lib目錄底下即可  以下是一個例子,

          build_cpp.xml

          <?xml version="1.0"?>
          <project name="antcpp" default="test">
          <!-- 引入外部文件--> 
          <import file="build.inc"/>

          <taskdef resource="cpptasks.tasks"/>
          <typedef resource="cpptasks.types"/>
          <taskdef resource="net/sf/antcontrib/antcontrib.properties">
            
          <classpath>
              
          <pathelement location="/usr/share/java/ant-contrib.jar"/>
            
          </classpath>
          </taskdef>
           
          <property name="base.dir" value="."/>
          <property name="debug" value="true"/>
          <property name="compiler" value="gcc"/>
          <property name="src.dir" location="${base.dir}"/>
          <property name="samples.dir" location="${base.dir}/samples"/>
          <property name="build.dir" location="build"/>
          <property name="obj.dir" location="${build.dir}/obj"/>
          <property name="include.dir" location="${base.dir}/include"/>
          <property name="config.dir" location="${base.dir}/config"/>
          <property name="major" value="0"/>
          <property name="minor" value="9"/>
          <property name="build" value="8"/>
          <!-- specify api="unix" or api="win32" override platform default -->
          <property name="api" value="default"/>
           
          <!-- compiler flag define--> 
          <property name="CXX_DFLAGS" value="${DFLAGS} -DXML_ERRORS -DHAVE_CONFIG_H -DFOR_LT "/> 
          <property name="RIGHT_HOME" value="${CGI_HOME}/right"/> 
           
          <target name="usage">
                  
                  
          <echo message="Usage:"/>
                  
          <echo message="ant -f build_cpp.xml"/>
          </target>
           
          <target name="init">
                  
          <echo message="build init"/>
                  
          <mkdir dir="${build.dir}"/>
                  
          <mkdir dir="${obj.dir}"/>
                  
          <condition property="is-gcc">
                          
          <or>
                                  
          <equals arg1="${compiler}" arg2="gcc"/>
                                  
          <equals arg1="${compiler}" arg2="g++"/>
                          
          </or>
                  
          </condition>
                  
          <condition property="is-msvc">
                          
          <or>
                                  
          <equals arg1="${compiler}" arg2="msvc"/>
                          
          </or>
                  
          </condition>
                  
          <condition property="is-windows"><os family="windows"/></condition>
                  
          <condition property="is-win32">
                          
          <or>
                                  
          <equals arg1="${api}" arg2="win32"/>
                                  
          <and>
                                          
          <equals arg1="${api}" arg2="default"/>
                                          
          <isset property="is-windows"/>
                                  
          </and>
                          
          </or>
                  
          </condition>
                  
          <property environment="env"/>
                  
          <!--  in case not set in environment, use an insignificant value -->
                  
          <property name="env.LD_LIBRARY_PATH" value="."/>
           
          </target>
           
          <target name="clean">
                  
          <echo message="build clean all"/>
                  
          <delete dir="${build.dir}"/>
           
          </target>
           

          <target name="build-cpp" >
                 
          <basename property="test.name" file="${a123}" suffix="cpp"/>
                 
          <echo message="compile ${test.name}.cpp with ${compiler}"/>
                 
          <!--  preprocesses .ui and .h files, places generated files on obj.dir  -->
                  
          <cc subsystem="console"
                      objdir
          ="${obj.dir}"
                      debug
          ="${debug}"
                      outtype
          ="executable"
                      name
          ="${compiler}"
                      exceptions
          ="true"
                      rtti
          ="true"
                      optimize
          ="speed"
                      outfile
          ="${build.dir}/${test.name}.cgi"
                      
          >
                      
          <fileset dir="${src.dir}" includes="${test.name}.cpp"/>
           
                      
          <syslibset libs="z,m,cgicc,ghttp,ltapi${LTXML_VERSION},ltstd${LTXML_VERSION}"/>
                      
          <libset dir="${MYSQL_LIB}" libs="mysqlclient"/>
                      
          <libset dir="../../lib" libs="gspsright,myutil,db,share,webdev,xmlcpp,ini,net"/>
                      
          <compilerarg value="-O2"/>
                      
          <compilerarg value="-Wno-deprecated"/>
                      
          <defineset>
                          
          <define name="FOR_LT"/> 
                          
          <define name="HAVE_CONFIG_H"/>
                          
          <define name="XML_ERRORS"/>
                          
          <define name="SQLLOG"/> 
                          
          <define name="GSPS_HOME" value="&quot;${PUB_HOME}&quot;"/> 
                      
          </defineset>
                      
          <includepath location="${MYSQL_INC}"/>
                      
          <includepath location="/usr/local/include"/>
                      
          <includepath location="${LTXML_INC}"/>
                      
          <includepath location="${BOOST_HOME}"/>
                  
          </cc>
           
          </target>
           
          <target name="build-all" depends="init,setProperties">
              
          <echo message="The first five letters of the alphabet are:"/>
              
          <foreach param="a123" target="build-cpp">
                  
          <path>
                  
          <fileset dir="${src.dir}" includes="*.cpp"/>
                  
          </path>
              
          </foreach>
          </target> 

          <target name="test" depends="build-all" >
                  
          <exec dir="${build.dir}"
                        executable
          ="ls"
                        failonerror
          ="false">
                  
          </exec>
          </target>
          </project> 

          build_cpp.inc

          <project name="Const_variant" default="setProperties">
                  
          <taskdef resource="cpptasks.tasks"/>
                  
          <typedef resource="cpptasks.types"/>
                  
          <taskdef resource="net/sf/antcontrib/antcontrib.properties">
                          
          <classpath>
                                  
          <pathelement location="/usr/share/java/ant-contrib.jar"/>
                          
          </classpath>
                  
          </taskdef>
                  
          <property name="GSPS_HOME" value=""/>
                  
          <property name="PUB_HOME" value=""/>
                  
          <property name="APACHE_HOME" value=""/>
                  
          <property name="CGI_HOME" value="${APACHE_HOME}/cgi-bin/"/>
                  
          <property name="HTML_HOME" value="${APACHE_HOME}/htdocs/"/>
                  
          <property name="BIN_HOME" value="${PUB_HOME}/bin"/>
                  
          <property name="TMPL_HOME" value="${PUB_HOME}/tmpl"/>
                  
          <property name="DATA_HOME" value="${PUB_HOME}/data"/>
                  
          <property name="LIB_HOME" value="${PUB_HOME}/lib"/>
                  
          <property name="RPATH" value="${LIB_HOME}"/>
                  
          <property name="GDB_FLAGS" value="-O2"/>
                
                  
          <property name="DGSPS_HOME" value="-DGSPS_HOME=&quot;${PUB_HOME}&quot;"/>
                  
          <property name="DSQLLOG" value="-DSQLLOG"/>
                  
          <property name="MYSQL_HOME" value="/usr/local/mysql"/>
           
           
                  
          <property name="BOOST_HOME" value="${PUB_HOME}/supports/boost-1.30.2"/>  
                  
          <property name="PERL_INC" value=""/> 
                  
          <property name="QUEUE_LIBS" value="-lqdoctransapi -lqpageapi -lqsubjectapi -lqcolumnapi 
                                     -lqcrosspublishapi -lqautoadddocapi -lqpubapi -lqcgicallapi -lqcgicall 
                                                -lqemailcallapi -lqueue  -lqcreator -lurlencoder -lhttp"
          /> 
           
                  
          <property name="LTXML_VERSION" value="12"/> 
                  
          <property name="LTXML_INC" value="/usr/local/include/ltxml${LTXML_VERSION}"/>  
           
                  
          <property name="MYSQL_INC" value="${MYSQL_HOME}/include/mysql"/>
                  
          <property name="MYSQL_LIB" value="${MYSQL_HOME}/lib/mysql"/>
           
                  
          <!--
                                  <echo message="The OS is FreeBSD" />
                                  <property name="MYSQL_INC" value="${MYSQL_HOME}/include" />
                                  <property name="MYSQL_LIB" value="${MYSQL_HOME}/lib"/>
                          
          -->
           
                  
          <target name="setProperties">
                          
          <shellscript shell="sh" inputstring="Magick++-config --libs" outputproperty="MAGICK_LIBS"/>
                          
          <shellscript shell="sh" inputstring="uname" outputproperty="OS"/>
                          
          <shellscript shell="sh" inputstring="/usr/local/bin/perl -MConfig -e 'print $$Config{archlib}'"                        outputproperty="PERL_INC"/>
                          
          <shellscript shell="sh" inputstring="/usr/local/bin/perl -MExtUtils::Embed -e ccopts -e ldopts"                        outputproperty="PERL_LIBS"/>
                          
          <echo message="${MAGICK_LIBS}"/>
                          
          <echo message="${OS}"/> 
                          
          <echo message="${PERL_INC}"/> 
                          
          <echo message="${PERL_LIBS}"/> 
                  
          </target>
          </project>

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          posts - 9, comments - 0, trackbacks - 0, articles - 0

          Copyright © 梧桐夜雨

          主站蜘蛛池模板: 平武县| 齐齐哈尔市| 基隆市| 青浦区| 永年县| 凌源市| 犍为县| 伊川县| 谢通门县| 阿拉善盟| 台州市| 麻阳| 吉木乃县| 赞皇县| 奉节县| 乳山市| 荥经县| 屯昌县| 比如县| 双柏县| 平谷区| 陵水| 阿克陶县| 灵川县| 海盐县| 任丘市| 德昌县| 牙克石市| 大关县| 阳西县| 常州市| 台南市| 凤台县| 南部县| 邢台县| 大同县| 仪征市| 武冈市| 香格里拉县| 海宁市| 南丰县|