Cmake in QtCreator: Source file not displayed in p

2019-09-06 17:58发布

问题:

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")