关于生成文件的CMake

编程入门 行业动态 更新时间:2024-10-09 10:25:46
本文介绍了关于生成文件的CMake的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好.

我有以下情况:我有一个CMake文件,该文件应该用来编译我的应用程序,该文件包括:

I have the following situation: I have a CMake file, which is supposed to compile my application, which consists of:

  • 一个或多个cpp文件
  • 一些模板文件(ecpp),这些文件又被生成为cpp文件,这些文件被编译到应用程序中(它们在WEB_COMPONENTS中列出,因此对于每个组件,都有关联的文件以及将从中生成的.cpp.
  • one or more cpp files
  • some template files (ecpp), which on their turn are generated into cpp files, which are compiled into the application (they are listed below in the WEB_COMPONENTS so for each component there is the associated .ecpp file and the .cpp that will be generated from it).
  • 这是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

    本文发布于:2023-11-12 14:18:05,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1581721.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:文件   CMake

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!