MantisBT - CMake
View Issue Details
0007835CMakeCMakepublic2008-10-20 16:112016-06-10 14:30
Eric NOULARD 
Bill Hoffman 
normalfeaturealways
closedmoved 
CMake-2-6 
 
0007835: Make it easier to add non-source (i.e. not compiled) file to a Visual Studio project
Currently if you want to add file to a Visual Studio project
you have to:

1) add the file to the source list of either
   add_executable
   add_library

2) Specify that the file is not to be compiled with:
   set_source_files_properties(thefile PROPERTIES HEADER_FILE_ONLY TRUE)


I would suggest an easier way to add "non compiled" source file to a project

Suggestion1) All files appearing as "InputFile" of configure_file cmake
             command should automatically show up in a "CONFIGURED_FILE"
             project, this project may not be "buildable" but it would
             ease the edition of this kind of "source files"

Suggestion2) We may add a ADD_EDITABLE command like
              add_editable(<name> editable1 editable2 ... editableN)
             which would create a non buildable (or doing nothing)
             project which will contains those "editable" files.

Note that the feature may be useful to other "IDE", XCode, Code::Blocks etc...
but I don't know that since I do not use those.
see former discussions on this issue:
http://www.cmake.org/pipermail/cmake/2008-October/024691.html [^]
http://www.cmake.org/pipermail/cmake/2008-October/024652.html [^]
http://www.cmake.org/pipermail/cmake/2008-October/024648.html [^]
http://www.cmake.org/pipermail/cmake/2008-June/022420.html [^]
http://www.cmake.org/pipermail/cmake/2008-June/022386.html [^]
... may be more
No tags attached.
Issue History
2008-10-20 16:11Eric NOULARDNew Issue
2009-01-08 15:58Bill HoffmanStatusnew => assigned
2009-01-08 15:58Bill HoffmanAssigned To => Bill Hoffman
2011-02-25 07:25Dorian ScholzNote Added: 0025578
2014-09-09 07:29ptxmacNote Added: 0036753
2014-11-21 07:28SepticInsectNote Added: 0037244
2014-11-21 11:04Nils GladitzNote Added: 0037247
2014-11-24 02:53SepticInsectNote Added: 0037256
2014-11-24 03:26Nils GladitzNote Added: 0037257
2014-11-24 03:29SepticInsectNote Added: 0037258
2014-11-24 03:33Nils GladitzNote Added: 0037260
2014-11-24 04:19SepticInsectNote Added: 0037261
2014-11-24 04:26Nils GladitzNote Added: 0037262
2014-11-24 04:34SepticInsectNote Added: 0037263
2014-11-24 04:37Nils GladitzNote Added: 0037264
2014-11-24 04:39SepticInsectNote Added: 0037265
2014-11-24 05:38SepticInsectNote Added: 0037266
2014-11-24 06:56SepticInsectNote Edited: 0037266bug_revision_view_page.php?bugnote_id=37266#r1626
2014-11-24 09:40Nils GladitzNote Added: 0037267
2016-06-09 07:37Mateusz LoskotNote Added: 0041151
2016-06-10 14:27Kitware RobotNote Added: 0041456
2016-06-10 14:27Kitware RobotStatusassigned => resolved
2016-06-10 14:27Kitware RobotResolutionopen => moved
2016-06-10 14:30Kitware RobotStatusresolved => closed

Notes
(0025578)
Dorian Scholz   
2011-02-25 07:25   
This does not only apply to VS, but also to other (if not all) IDE's.
I'm trying to get this to work on QtCreator.
(0036753)
ptxmac   
2014-09-09 07:29   
Is anyone working on this?
(0037244)
SepticInsect   
2014-11-21 07:28   
Is anyone working on this?
(0037247)
Nils Gladitz   
2014-11-21 11:04   
You can use add_custom_target(mytarget SOURCES src1 [src2...]) to add files without compile/build semantics.
(0037256)
SepticInsect   
2014-11-24 02:53   
But I'm using add_custom_command to precompile a pgc-file to a c-file. Then I use the c-file in add_library. But I want QtCreator to find my pgc-file.
(0037257)
Nils Gladitz   
2014-11-24 03:26   
@SepticInsect: For that something like add_custom_target(new-target-for-my-pgc-file SOURCES path/to/my/foo.pgc) should work as well.
(0037258)
SepticInsect   
2014-11-24 03:29   
I have tried add_custom_target but it doesn't work the first time I compile, when the c-file doesn't exist.
(0037260)
Nils Gladitz   
2014-11-24 03:33   
@SepticInsect: You might want to take the discussion to the user's mailing list.
The add_custom_target() call I suggested did not reference the c-file.
Can you elaborate?
(0037261)
SepticInsect   
2014-11-24 04:19   
Maby I misunderstood you. I thought you meant that I should replace my add_custom_command with an add_custom_target? Or did you mean that I should keep my add_custom_command and add add_custom_target(new-target-for-my-pgc-file SOURCES path/to/my/foo.pgc)? Isn't that an ugly solution? To add and add_custom_target just go get my pgc-file in QtCreator?
(0037262)
Nils Gladitz   
2014-11-24 04:26   
@SepticInsect: Yes, I meant an additional custom target (unless you already have an existing custom target which would be appropriate).

Since as far as I can tell there are no compile/build semantics associated with .pgc files you could just as well list it in your add_library() call.
(0037263)
SepticInsect   
2014-11-24 04:34   
Ok. If I do add_library(my_lib file1.c file2.pgc), cmake wouldn't care about file2.pgc and just build my_lib from file1.c?
(0037264)
Nils Gladitz   
2014-11-24 04:37   
@SepticInsect: CMake will assert file2.pgc exists and will add it to IDE file listings but will not influence the build beyond that (unless you define/enable a compiler which happens to use the .pgc suffix).
(0037265)
SepticInsect   
2014-11-24 04:39   
Ok. Thanks for all the help!
(0037266)
SepticInsect   
2014-11-24 05:38   
(edited on: 2014-11-24 06:56)
@ngladitz Is it wrong to add set_source_files_properties(file2.pgc PROPERTIES HEADER_FILE_ONLY TRUE) just to clarify that file2.pgc shall not be built into my_lib?

(0037267)
Nils Gladitz   
2014-11-24 09:40   
@SepticInsect: Sounds superfluous in this case but should not hurt either.
(0041151)
Mateusz Loskot   
2016-06-09 07:37   
For anyone who is still looking for the solution to attach non-sources to an IDE project, here is a possible utility:


# collect_info_files function
# Takes collect_info_files - list of non-source files to look for
# Returns INFO_FILES with all files found from the input list.
# Based on macro posted here
# http://lists.qt-project.org/pipermail/qt-creator/2012-August/001191.html [^]
function(collect_info_files)
    list(APPEND _all_found)
    foreach(_it ${ARGN})
        if(NOT IS_DIRECTORY ${_it})
            get_filename_component(_path ${_it} ABSOLUTE)
            if(EXISTS ${_path})
                list(APPEND _all_found ${_it})
                if(NOT ${_it} MATCHES "^/\\\\..*$;~$")
                    set_source_files_properties(${_it} PROPERTIES HEADER_FILE_ONLY TRUE)
                endif()
            endif()
        endif()
    endforeach()
    set(INFO_FILES ${_all_found} PARENT_SCOPE)
endfunction()


and here is the function usage:

# List all non-source code files (documents, configuration files, etc.)
set(other_files .gitignore .travis.yml appveyor.yml README.md)
# Collect all existing files and configure as non-sources.
collect_info_files(${other_files})
# Create dummy target/project for an IDE with documents attached
add_custom_target(docs SOURCES ${INFO_FILES})
(0041456)
Kitware Robot   
2016-06-10 14:27   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.