fu 文件和 nc.c 文件。这种情况,就必须写成: SET(SRC_LIST “fu nc.c”),此外,你可以可以忽略掉
source 列表中的源文件后缀,比如可以写成 ADD_EXECUTABLE(t1 main),cmake 会自动的在本目
录查找 main.c 或者 main.cpp 等,当然,最好不要偷这个懒,以免这个目录确实存在一个 main.c 一个
main. 同时参数也可以使用分号来进行分割。
下面的例子也是合法的:
ADD_EXECUTABLE(t1 main.c t1.c)可以写成 ADD_EXECUTABLE(t1
main.c;t1.c).
我们只需要在编写 CMakeLists.txt 时注意形成统一的风格即可。
6,清理工程:
跟经典的 autotools 系列工具一样,运行:
make clean
即可对构建结果进行清理。
7,问题?问题!
“我尝试运行了 make distclean,这个指令一般用来清理构建过程中产生的中间文件的,如果要发布
代码,必然要清理掉所有的中间文件,但是为什么在 cmake 工程中这个命令是无效的?”
是的,cmake 并不支持 make distclean,关于这一点,官方是有明确解释的:因为 CMakeLists.txt
可以执行脚本并通过脚本生成一些临时文件,但是却没有办法来跟踪这些临时文件到底是哪些。因此,
没有办法提供一个可靠的 make distclean 方案。
Some build trees created with GNU autotools have a "make distclean" target that cleans the build
and also removes Makefiles and other parts of the generated build system. CMake does not generate
a "make distclean" target because CMakeLists.txt files can run scripts and arbitrary commands;
CMake has no way of tracking exactly which files are generated as part of running CMake.
Providing a distclean target would give users the false impression that it would work as expected.
(CMake does generate a "make clean" target to remove files generated by the compiler and linker.)
A "make distclean" target is only necessary if the user performs an in-source build. CMake supports
in-source builds, but we strongly encourage users to adopt the notion of an out-of-source build.
Using a build tree that is separate from the source tree will prevent CMake from generating any
files in the source tree. Because CMake does not change the source tree, there is no need for a
distclean target. One can start a fresh build by deleting the build tree or creating a separate build
tree.
同时,还有另外一个非常重要的提示,就是:我们刚才进行的是内部构建(in-source build),而 cmake
强烈推荐的是外部构建(out-of-source build)。
8,内部构建与外部构建:
上面的例子展示的是“内部构建”,相信看到生成的临时文件比您的代码文件还要多的时候,估计这辈
子你都不希望再使用内部构建:-D 举个简单的例子来说明外部构建,以编译 wxGTK 动态库和静态库为
例,在 Everest 中打包方式是这样的:
解开 wxGTK 后。
在其中建立 static 和 shared 目录。
进入 static 目录,运行../configure –enable-static;make 会在 static 目录生成 wxGTK 的静态库。
进入 shared 目录,运行../configure –enable-shared;make 就会在 shared 目录生成动态库。
评论0