[CMake] Executable depending on all source files

Eric Noulard eric.noulard at gmail.com
Sat Aug 25 14:01:46 EDT 2012


2012/8/25 Russell Wallace <russell.wallace at gmail.com>:
> On Sat, Aug 25, 2012 at 2:19 PM, Eric Noulard <eric.noulard at gmail.com> wrote:
>> Does your VCS (git, cvs, svn,...) do globbing for adding/removing files ?
>
> Git. And yes, of course it does.

No sorry, I wasn't clear enough
unless I'm wrong you can do:

git add blah*.c

but :
   1) If you add an extra blah-whatever.c file after the git command
       then git won't handle the file.

   2) When you manually suppress a file you still have to do
       git rm blah-whatever.c

   3) In my example, git is not doing the globbing, the shell does.
       I know you can ask git to handle a pattern of file (and not the shell)
       but this like FILE(GLOB ...) for cmake

My point is when file "appear" or "disappear" you have to *manually*
inform git about it. Updating the list of source from within a CMakeLists.txt
is exactly the same process.

>> What you 'could do' is to craft some scripts (CMake or else) that
>> may automagically update the extensive list of sources in your CMakeLists.txt.
>> This script may be launched by a CMake custom target of yours, e.g.
>> then you'll be able to do
>>
>> make up_src_list
>>
>> instead of editing the CMakeLists.txt manually,
>
> Sure, that would have been my fallback, treat CMakeLists.txt as object
> code and write a Python script to maintain it automatically. But
> adding an extra layer like that is strictly inferior to a solution
> that works within CMake.

You can write a CMake-script that create a FileList.cmake which
contains only a variable definition:
set(SOURCE_LIST blah.c toto.c)

then in your CMakeLists.txt you do

add_custom_target(GenSrcLst
                                 COMMAND ${CMAKE_COMMAND} -P YourScript.cmake)

include(FileList.cmake)
add_executable(YourExe ${SOURCE_LIST})

that way your CMakeLists.txt is almost as before and
you can find the way you want to re-generate FileList.cmake
**when needed** with a

make GenSrcLst

without considering the whole CMakeLists.txt an "object file".

All "within" CMake.

I still don't find it "necessary" but it should work without too
much manual  edition.

You will still need to git add / rm the files.
-- 
Erk
Le gouvernement représentatif n'est pas la démocratie --
http://www.le-message.org


More information about the CMake mailing list