Cmake调用NSIS(一个可执行文件,其实就是一个编译器)编译NSIS脚本问题研究

时间:2022-10-20 10:18:23

技术经理说,可以用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的官方文档:

3.1 MakeNSIS Usage

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 | - [...]]

3.1.1 Options

  • /LICENSE displays a keen license page.
  • The /V switch followed by a number between 0 and 4 will set the verbosity of output accordingly. 0=no output, 1=errors only, 2=warnings and errors, 3=info, warnings, and errors, 4=all output.
  • The /P switch followed by a number between 0 and 5 will set the priority of the compiler process accordingly. 0=idle, 1=below normal, 2=normal (default), 3=above normal, 4=high, 5=realtime.
  • The /O switch followed by a filename tells the compiler to print its log to that file (instead of the screen)
  • /PAUSE makes makensis pause before quitting, which is useful when executing directly from Windows.
  • /NOCONFIG disables inclusion of nsisconf.nsh. Without this parameter, installer defaults are set from nsisconf.nsh.
  • /CMDHELP prints basic usage information for command (if specified), or all commands (if command is not specified).
  • /HDRINFO prints out information on what options were used to compile makensis was compiled with.
  • /NOCD disables the current directory change to that of the .nsi file
  • Using the /D switch one or more times will add to symbols to the globally defined list (See !define).
  • Using the /X switch one or more times will execute the code you specify following it. Example: "/XAutoCloseWindow false"
  • Specifying a dash (-) for the script name will tell makensis to use the standard input as a source.

3.1.2 Notes

  • Parameters are processed by order. makensis /Ddef script.nsi is not the same as makensis script.nsi /Ddef.
  • If multiple scripts are specified, they are treated as one concatenated script.
  • On Windows 95, 98 and NT, below normal and above normal process priorities are not available. On those systems, below normal will actually set priority to idle and above normal will set to high.

3.1.3 Environment variables

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:

  • NSISDIR, NSISCONFDIR - Places where nsis data and config files are installed. NSISDIR alters the script variable ${NSISDIR}. See section 4.2.3 for more info.
  • APPDATA (on Windows) or HOME (on other platforms) - Location of the per-user configuration file.

3.1.4 Examples

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的实例
 cmake_minimum_required(VERSION 2.8)

 #set(CMAKE_C_COMPILER "D:\VS2008Release\VC\bin\amd64")
#set(CMAKE_CXX_COMPILER "D:\VS2008Release\VC\bin\amd64") PROJECT(NSIS) set( nsis_dir ${CMAKE_CURRENT_SOURCE_DIR}/NSIS)
add_custom_target(Setup ALL MakeNSIS.exe /V1 MyScript.nsi
COMMENT begin Setup buiding...
WORKING_DIRECTORY ${nsis_dir})
结论:
用add_custom_target()命令来实现此需求。

Cmake调用NSIS(一个可执行文件,其实就是一个编译器)编译NSIS脚本问题研究的更多相关文章

  1. java之如何实现调用启动一个可执行文件,exe

    /* * 运行可执行文件:.exe * 当要执行一个本地机器上的可执行文件时, * 可以使用java.lang包中的Runtime类,首先使用Runtime类,首先 * 使用Runtime类声明一个对 ...

  2. 第七周 linux如何装载和启动一个可执行文件

    潘恒 原创作品转载请注明出处 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.实验内容 1.预处理. ...

  3. 对 COM&plus; 组件进行了方法调用,但该组件有一个已被中止的或正在被中止的事务。 &lpar;异常来自 HRESULT&colon;0x8004E003&rpar;

    错误: 对 COM+ 组件进行了方法调用,但该组件有一个已被中止的或正在被中止的事务. (异常来自 HRESULT:0x8004E003)   解决办法: 程序连接的数据库换到本地.   具体原因没搞 ...

  4. 调用init方法 两种方式 一个是浏览器方法 一个是 xml中手工配置&lpar;load-on-startup&rpar;

    调用init方法 两种方式 一个是浏览器方法 一个是 xml中手工配置(load-on-startup)

  5. go语言笔记——go是有虚拟机runtime的,不然谁来做GC呢,总不会让用户自己来new和delete进行内存管理吧,还有反射!Go 的 runtime 嵌入到了每一个可执行文件当中

    2.7 Go 运行时(runtime) 尽管 Go 编译器产生的是本地可执行代码,这些代码仍旧运行在 Go 的 runtime(这部分的代码可以在 runtime 包中找到)当中.这个 runtime ...

  6. JS方式调用本地的可执行文件

    看到一个方法,有些用,先存下来,有用的时候再用. 前几天,在IE,FIREFOX中实现了用JS方式调用本地的可执行文件.地址:www.yihaomen.com/article/js/211.htm , ...

  7. C&plus;&plus;程序中调用其他exe可执行文件方法

    在编程过程中有个需求,点击某个按钮需要弹出系统的声音控制面板.在网上查了下代码中调用其他exe程序或者打开其他文件的方法. 自己借鉴网上的文章稍微总结下,加深下印象,也给方便自己用. 在代码中调用其他 ...

  8. ZeroMQ接口函数之 :zmq&lowbar;recvmsg – 从一个socket上接收一个消息帧

    ZeroMQ 官方地址 :http://api.zeromq.org/4-1:zmq-recvmsg zmq_recvmsg(3)         ØMQ Manual - ØMQ/4.1.0 Nam ...

  9. ZeroMQ接口函数之 :zmq&lowbar;sendmsg – 从一个socket上发送一个消息帧

    ZeroMQ 官方地址 :http://api.zeromq.org/4-1:zmq-sendmsg zmq_sendmsg(3)        ØMQ Manual - ØMQ/4.1.0 Name ...

随机推荐

  1. NodeJS 开篇 牛刀小试

    一.Node&NPM的安装与配置 下载:https://nodejs.org/en/ V4.2.x LTS(9.75MB)——长期支持版,成熟可靠 V5.x.x Stable(9.71MB)— ...

  2. Errors occurred during the build&period; Errors running builder &&num;39&semi;DeploymentBuilder&&num;39&semi; on project &&num;39&semi;项目名&&num;39&semi;

    问题描述: Errors occurred during the build. Errors running builder 'DeploymentBuilder' on project 'myf'. ...

  3. Java学习----集合函数

    1.List----有序的collection(序列) 与数组的不同:数据类型可以相同可以不同,数组的长度是预先定义好的,集合的长度也是预先定义好的,但是长度会随着元素的增加而增加 ArrayList ...

  4. javascript 定义类&lpar;转载&rpar;

    Javascript本身并不支持面向对象,它没有访问控制符,它没有定义类的关键字class,它没有支持继承的extend或冒号,它也没有用来支持虚函数的virtual,不过,Javascript是一门 ...

  5. nlp中文分词(jieba和pyltp)

    分词是中文自然语言处理的基础.目前常用的分词算法有 1.张华平博士的NShort中文分词算法. 2.基于条件随机场(CRF)的中文分词算法. 这两种算法的代表工具包分别是jieba分词系统和哈工大的L ...

  6. Hibernate的Cascade——级联操作

    在Hibernate中,针对持久化实体的配置文件中有Cascade这样一个属性,顾名思义就是级联,也就是说在操作当 前实体时,针对当前实体的操作会影响到相应配置的关联实体.比如针对当前实体进行保存操作 ...

  7. 卷积、矩阵乘积、高斯模糊滤波(降噪)、空域计算(2D卷积计算)、频域计算(FFT)的理解

    矩阵乘积:对应行列对应元素相乘的和组成新的矩阵 两个矩阵的乘法仅当第一个矩阵A的列数和另一个矩阵B的行数相等时才能定义.如A是m×n矩阵和B是n×p矩阵,它们的乘积C是一个m×p矩阵 并将此乘积记为: ...

  8. 获取linux服务进程号

    ps -ef | grep "服务名" | grep -v "grep" | awk '{print $2}' # ps -ef|grep "被查询的 ...

  9. ul点击li&comma;增加样式

    用户首次绑定后,需要选择一款头像 <!--imgList头像列表--><el-row class="regModel1"> <el-col :span ...

  10. jsp传中文乱码问题 encodeURIComponent()编码方法

    方法一: jQuery.ajax({            type:"POST",            url:"${ctx}/offer.do",     ...