Cmake in QtCreator: Source file not displayed in project file tree view

强颜欢笑 提交于 2019-12-12 03:15:34

问题


I'm using CMake och QtCreator to write C code. I open my project by opening the CMakeLists.txt file on the top level. I see all the files in the project file tree view in QtCreator that are used to build executables or libraries like this:

add_library( my_lib file1.c )
add_executable( my_executable file2.c )

But I have one file that are used in precompilation for postgres like this:

set( MY_CMD "/usr/pgsql-9.3/bin/ecpg" )
set( MY_ARG "file3.pgc" )
add_custom_target( dummy_target ALL COMMAND ${MY_CMD} ${MY_ARG} WORKING_DIRECTORY ${MY_DIR} )

The file file3.pgc is not displayed in the project file tree view. How can I make QtCreator find that file?


回答1:


Add SOURCES option to add_custom_target (http://www.cmake.org/cmake/help/v3.0/command/add_custom_target.html):

add_custom_target(dummy_target ALL 
    COMMAND ${MY_CMD} ${MY_ARG} 
    WORKING_DIRECTORY ${MY_DIR} 
    SOURCES "${MY_DIR}/file3.pgc")


来源:https://stackoverflow.com/questions/27038988/cmake-in-qtcreator-source-file-not-displayed-in-project-file-tree-view

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!