CMakeLists.txt proliferation problem

4 views
Skip to first unread message

Gabriela Gibson

unread,
Sep 9, 2015, 10:33:13 AM9/9/15
to CorinthiaTeam
I find the CMakeLists.txt in every directory an inconvenience.

So, I'm wondering if it would be more useful to have one file that lists everything in one place which is easier to edit and check; and then use a script to generate the required CMakeLists.txt in all the necessary locations from this file.

I also wonder why CMake doesn't do this in the first place.

Thoughts?

G

Gabriela Gibson

unread,
Sep 9, 2015, 1:35:21 PM9/9/15
to CorinthiaTeam
What I meant was this kind of tool, just to make life easier, and even if you don't use the recipe file, I plan to make a 'collection service' so you can just check one file and see where the squirrel has hidden that nut you're looking for:


#!/usr/bin/python
"""Handle Cmakelists.txt from one recipe."""

import getopt
import os
import re
import sys


def show_help():
"""Help message function."""
print "Cmake Sorter creates and places your CMakeLists.txts"
print " where they should go, all from one place."
print "\nOptions:"
print "-r recipe -- name of your recipe file."
print "-d dry-run -- show where all the files would go."
print "-c collect -- create a recipe file from existing CMakeLists.txt"


def load_in_file(inputfile):
"""Function to read file and return contents.

Input:
inputfile: Name of recipe file.
Output:
lines: array of lines
"""
lines = []
with open(inputfile, 'r') as the_file:
lines = the_file.readlines()
return lines

def collect_files_make_recipe_file():
"""Collect all the existing CMakeLists.txt files

Output: A recipe file containing all the contents of the
CMakeLists.txt in your existing project.

"""
pass

def get_list_of_cmake_files(input_text):
"""Gather all the directory names
Input:
input_text: Contents of recipe file as []
Output:
List of thruples as (path, line nr. start, line nr. end)
"""
pass


def show_dry_run(input_text):
"""List all the locations anticipated

Input:
input_text: Contents of recipe file as []

Output:
List of paths to stdout
List of paths to CMakeListsLocations.txt
"""
pass


def write_cmake_files(input_text, method):
"""Generate and list or write resulting CMakeLists.txt files

Input:
input_text: Contents of recipe file as []
Output:
create CMakeLists.txt in the desired locations from
given file contents.
"""
pass


def main(argv):
''' Read a CMake recipe from file and list or generate CMakeLists.txt '''

try:
opts, args = getopt.getopt(argv, "h:r:d:c",
["help", "recipe=", "dry-run","collect"])
except getopt.GetoptError:
show_help()
sys.exit(2)

for opt, arg in opts:
if opt in ("-h", "--help"):
show_help()
sys.exit()

elif opt in ("-r", "--recipe"):

input_text = load_in_file(arg)
if input_text == []:
print ("The file you specified could not be found " +
"or is not readable.\n")
sys.exit()
generate_cmake_files(input_text)

elif opt in ("-d", "--dry-run"):
input_text = load_in_file(arg)
if input_text == []:
print ("The file you specified could not be found " +
"or is not readable.\n")
sys.exit()
show_dry_run(input_text)
elif opt in ("-c", "--collect"):
collect_files_make_recipe_file()

sys.exit()


if __name__ == "__main__":
main(sys.argv[1:])

-------------------------------------------------------------------------------
Just needed a break from logger and all those CMakeLists.txt kind of got to me a bit. :-D

G

jan i

unread,
Sep 9, 2015, 3:03:13 PM9/9/15
to jan i, CorinthiaTeam


On Wednesday, September 9, 2015, jan i <ja...@apache.org> wrote:
I am highly against only having only having one cmake file...you could make the same case why have multiple directories.

For me the seperation is important, when I work on a CMAKE file, I know it only works on this particular subdir.

We also have conflicting settings, which would make 1 central cmake file unreadable.

Actually your case is a good example too...because if your cmake file creates problems, we comment the add_dir() out in the central one, and the rest works.

No thanks to 1 big file (small files, small problems)

rgds
jan 
 

Thoughts?

G

--
You received this message because you are subscribed to the Google Groups "CorinthiaTeam" group.
To unsubscribe from this group and stop receiving emails from it, send an email to corinthiatea...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Sent from My iPad, sorry for any misspellings.


--
Sent from My iPad, sorry for any misspellings.

Gabriela Gibson

unread,
Sep 9, 2015, 3:12:56 PM9/9/15
to CorinthiaTeam, ja...@apache.org
On Wednesday, September 9, 2015 at 8:03:13 PM UTC+1, jan i wrote:
> On Wednesday, September 9, 2015, jan i <ja...@apache.org> wrote:
>
>
> On Wednesday, September 9, 2015, Gabriela Gibson <gabriel...@gmail.com> wrote:
> I find the CMakeLists.txt in every directory an inconvenience.
>
>
>
> So, I'm wondering if it would be more useful to have one file that lists everything in one place which is easier to edit and check; and then use a script to generate the required CMakeLists.txt in all the necessary locations from this file.
>
>
>
> I also wonder why CMake doesn't do this in the first place.
>
>
> I am highly against only having only having one cmake file...you could make the same case why have multiple directories.
>
>
> For me the seperation is important, when I work on a CMAKE file, I know it only works on this particular subdir.
>
>
> We also have conflicting settings, which would make 1 central cmake file unreadable.
>
>
> Actually your case is a good example too...because if your cmake file creates problems, we comment the add_dir() out in the central one, and the rest works.
>
>
> No thanks to 1 big file (small files, small problems)
>
>
> rgds
>
> jan  

Thank you for the input Jan,

I guess it's more suited to small projects or if you want to quickly set up something with a nice structure that uses a build and bin directory without getting lost in a jungle of CMakeList.txt files. (I am the lazy kind)

:)

G, who was bitten by Makefile and then got bit some more by Cmake last night

jan i

unread,
Sep 9, 2015, 3:36:16 PM9/9/15
to Gabriela Gibson, CorinthiaTeam, jan i
On 9 September 2015 at 21:12, Gabriela Gibson <gabriel...@gmail.com> wrote:
On Wednesday, September 9, 2015 at 8:03:13 PM UTC+1, jan i wrote:
> On Wednesday, September 9, 2015, jan i <ja...@apache.org> wrote:
>
>
> On Wednesday, September 9, 2015, Gabriela Gibson <gabriel...@gmail.com> wrote:
> I find the CMakeLists.txt in every directory an inconvenience.
>
>
>
> So, I'm wondering if it would be more useful to have one file that lists everything in one place which is easier to edit and check; and then use a script to generate the required CMakeLists.txt in all the necessary locations from this file.
>
>
>
> I also wonder why CMake doesn't do this in the first place.
>
>
> I am highly against only having only having one cmake file...you could make the same case why have multiple directories.
>
>
> For me the seperation is important, when I work on a CMAKE file, I know it only works on this particular subdir.
>
>
> We also have conflicting settings, which would make 1 central cmake file unreadable.
>
>
> Actually your case is a good example too...because if your cmake file creates problems, we comment the add_dir() out in the central one, and the rest works.
>
>
> No thanks to 1 big file (small files, small problems)
>
>
> rgds
>
> jan  

Thank you for the input Jan,

I guess it's more suited to small projects or if you want to quickly set up something with a nice structure that uses a build and bin directory without getting lost in a jungle of CMakeList.txt files.  (I am the lazy kind)

:)

G, who was bitten by Makefile and then got bit some more by Cmake last night

I am happy to help you with cmake, in corinthia it is fairly easy, because you do not need to touch the main cmake file, you can just copy a neighbour cmake file and change to your sources.

rgds
jan i.
 

Gabriela Gibson

unread,
Sep 9, 2015, 4:32:20 PM9/9/15
to jan i, CorinthiaTeam
Thanks,

much appreciated, but on this occasion it was a classic demonstration
of Mark Twain's famous quip:

"A man who carries a cat by the tail learns something he can learn in
no other way."

I can now set up any small project in a neat fashion with CMake :-)

G
--
Visit my Coding Diary: http://gabriela-gibson.blogspot.com/
Reply all
Reply to author
Forward
0 new messages