技术经理说,可以用Cmake当中的add_custom_command,add_custom_target命令来使用。
我初次研究了下,add_custom_command应该用官方文档中说明的第二种形式:
The second signature adds a custom command to a target such as a library or executable. This is useful for performing an operation before or after building the target. The command becomes part of the target and will only execute when the target itself is built. If the target is already built, the command will not execute.
add_custom_command(TARGET target
PRE_BUILD | PRE_LINK | POST_BUILD
COMMAND command1 [ARGS] [args1...]
[COMMAND command2 [ARGS] [args2...] ...]
[WORKING_DIRECTORY dir]
[COMMENT comment] [VERBATIM])
This defines a new command that will be associated with building the specified target. When the command will happen is determined by which of the following is specified:
PRE_BUILD - run before all other dependencies
PRE_LINK - run after other dependencies
POST_BUILD - run after the target has been built
find_program()find_path()这些命令估计有用。
NSIS相关:
NSIS.exe是NSIS带图形界面的编译器,实质上MakeNSISW.exe(一个接口)调用了MakeNSIS.exe来编译你的NSIS脚本文件。所以可以使用MakeNSIS
的命令行方式来编译脚本文件。
以下是使用MakeNSIS.exe的官方文档:
NSIS installers are generated by using the 'MakeNSIS' program to compile a NSIS script (.NSI) into an installer executable. The NSIS development kit installer sets up your computer so that you can compile a .nsi file by simply right-clicking on it in explorer, and selecting 'compile'.
If you want to use MakeNSIS on the command line, the syntax of the makensis command is:
makensis [option | script.nsi | - [...]]
makensis /Ddef script.nsi
is not the same as makensis script.nsi /Ddef
.makensis checks a number of environment variables that tell it where to locate the things it needs in order to create installers. These variables include:
Basic usage:
makensis.exe myscript.nsi
Quiet mode:
makensis.exe /V1 myscript.nsi
Force compressor:
makensis.exe /X"SetCompressor /FINAL lzma" myscript.nsi
Change script behavior:
makensis.exe /DUSE_UPX /DVERSION=1.337 /DNO_IMAGES myscript.nsi
Parameters order:
makensis /XSection sectioncontents.nsi /XSectionEnd
****************************************************************************** 以下是一个CMakeLists.txt的实例
1 cmake_minimum_required(VERSION 2.8) 2 3 #set(CMAKE_C_COMPILER "D:\VS2008Release\VC\bin\amd64") 4 #set(CMAKE_CXX_COMPILER "D:\VS2008Release\VC\bin\amd64") 5 6 PROJECT(NSIS) 7 8 9 set( nsis_dir ${CMAKE_CURRENT_SOURCE_DIR}/NSIS) 10 add_custom_target(Setup ALL MakeNSIS.exe /V1 MyScript.nsi 11 COMMENT begin Setup buiding... 12 WORKING_DIRECTORY ${nsis_dir})
结论:
用add_custom_target()命令来实现此需求。