大家好.
我有以下情况:我有一个CMake文件,该文件应该用来编译我的应用程序,该文件包括:
I have the following situation: I have a CMake file, which is supposed to compile my application, which consists of:
这是CMakeLists.txt(简体)
And here is the CMakeLists.txt (simplified)
cmake_minimum_required (VERSION 2.6) set (PROJECT sinfonifry) set (ECPPC /usr/local/bin/ecppc) set (WEB_COMPONENTS images menu css ) set(${PROJECT}_SOURCES "" CACHE INTERNAL ${PROJECT}_SOURCES ) foreach(comp ${WEB_COMPONENTS}) list(APPEND ${PROJECT}_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${comp}.cpp ) execute_process(COMMAND ${ECPPC} -o ${CMAKE_CURRENT_BINARY_DIR}/${comp}.cpp -v ${CMAKE_CURRENT_SOURCE_DIR}/${comp}.ecpp WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_QUIET ) endforeach() list(APPEND ${PROJECT}_SOURCES main.cpp ) add_executable(${PROJECT}_exe ${${PROJECT}_SOURCES}) target_link_libraries(${PROJECT}_exe cxxtools dl tntnet tntdb)现在,发生了什么:第一次(例如:生成构建目录,运行cmake-gui,选择Web组件,配置,生成,制作),CMake很好地执行了${ECPPC}命令.它在二进制目录中生成所需的CPP文件,并将它们链接在一起.
Now, what happens: for the very first time (ie: make the build directory, run cmake-gui, select web component, configure, generate, make) the CMake nicely executes the ${ECPPC} command, ie. it generates the required CPP files in the binary directory, and links them together.
过一会儿,很明显,在我工作的同时,我修改了一个组件文件(例如images.ecpp)并在生成目录中再次运行make.但是现在,CMake不会拾取ecpp文件的更改.我必须去cmake-gui,删除缓存,从零开始重新启动所有内容.这很累又很慢.
After a while, obviously while I work, I modify one of the component files (such as images.ecpp) and run make again in the build directory. But now, CMake does not pick up the changes of the ecpp files. I have to go to cmake-gui, delete cache, restart everything from zero. This is very tiresome and slow.
因此,有两个问题:
我告诉CMake跟踪images.ecpp的更改,并在${ECPPC}编译器发生更改时调用它吗?
Cand I tell CMake to track the changes of the images.ecpp and call the ${ECPPC} compiler on it if it changed?
如何make clean以便它也删除生成的cpp文件.
How can I make clean so that it also removes the generated cpp files.
谢谢你的时间,f.
推荐答案您要使用add_custom_command()而不是execute_process().看到这里: stackoverflow/a/2362222/4323
Instead of execute_process() you want to use add_custom_command(). See here: stackoverflow/a/2362222/4323
基本上,您告诉CMake OUTPUT(生成的文件名),COMMAND和DEPENDS(.ecpp文件名).这使它了解如何将源代码转换为必要的C ++生成的文件.然后,将生成的文件添加到某个目标,例如add_executable()或add_custom_command()依赖项(如果不需要编译,则更可能需要).
Basically you tell CMake the OUTPUT (the generated filename), COMMAND, and DEPENDS (the .ecpp filename). This makes it understand how to turn the source into the necessary C++ generated file. Then, add the generated file to some target, e.g. add_executable(), or to an add_custom_command() dependency (if it didn't need to be compiled you'd more likely need that).
更多推荐
关于生成文件的CMake
发布评论