8 from __future__
import with_statement
10 __version__ =
"$Revision: 795362 $"
11 __author__ =
"Will buttinger"
12 __doc__ =
"streamline and ease the creation of new cmake packages"
18 import PyUtils.acmdlib
as acmdlib
26 help=
"(fully qualified) name of the new package"
31 help=
'name of the author of this new package'
35 """create a new cmake package with sensible atlas-oriented defaults
38 $ acmd cmake new-pkg Control/MyContainer/NewPackage
42 full_pkg_name = args.pkgname
43 if full_pkg_name[0] ==
'/':
44 full_pkg_name = full_pkg_name[1:]
46 pkg_path = os.path.dirname(os.getcwd() +
"/" + full_pkg_name)
47 pkg_name = os.path.basename(full_pkg_name)
48 pkg_vers =
'%s-00-00-00' % pkg_name
49 author = os.path.expanduser(os.path.expandvars(args.author))
51 if os.path.exists(pkg_path+
"/"+pkg_name):
52 print(
"ERROR: %s package already exists" % full_pkg_name)
55 print(textwrap.dedent(
"""\
56 ::: creating package [%(full_pkg_name)s]...
57 ::: - pkg name: %(pkg_name)s
58 ::: - pkg version: %(pkg_vers)s
59 ::: - pkg path: %(pkg_path)s
60 ::: - author: %(author)s""" % locals()))
65 os.makedirs(pkg_path+
"/"+pkg_name+
"/"+pkg_name)
66 os.makedirs(pkg_path+
"/"+pkg_name+
"/src")
67 os.makedirs(pkg_path+
"/"+pkg_name+
"/share")
68 os.makedirs(pkg_path+
"/"+pkg_name+
"/python")
69 with open(pkg_path+
"/"+pkg_name+
"/python/__init__.py",
'w')
as f:
pass
70 os.makedirs(pkg_path+
"/"+pkg_name+
"/data")
71 with open(pkg_path+
"/"+pkg_name+
"/data/ExampleData",
'w')
as f: f.write(
"this file will be accessible through PathResolverFindDataFile(\""+pkg_name+
"/ExampleData\")")
72 os.makedirs(pkg_path+
"/"+pkg_name+
"/util")
73 os.makedirs(pkg_path+
"/"+pkg_name+
"/scripts")
75 print(
"ERROR while making directories for " % (pkg_path+
"/"+pkg_name+
"/src"))
79 with open(os.path.join(pkg_path+
"/"+pkg_name,
'CMakeLists.txt'),
'w')
as req:
80 print(textwrap.dedent(
"""\
81 ## automatically generated CMakeLists.txt file
84 atlas_subdir( %(pkg_name)s )
86 # Declare external dependencies ... default here is to include ROOT
87 find_package( ROOT COMPONENTS MathCore RIO Core Tree Hist )
89 # Declare public and private dependencies
90 # Public dependencies are anything that appears in the headers in public include dir
91 # Private is anything else
93 # An example is included
94 atlas_depends_on_subdirs(
98 # Control/AthAnalysisBaseComps
101 # Declare package as a library
102 # Note the convention that library names get "Lib" suffix
103 # Any package you add to dependencies above, you should add
104 # to LINK_LIBRARIES line below (see the example)
105 atlas_add_library( %(pkg_name)sLib src/*.cxx
106 PUBLIC_HEADERS %(pkg_name)s
107 INCLUDE_DIRS ${ROOT_INCLUDE_DIRS}
108 LINK_LIBRARIES ${ROOT_LIBRARIES}
109 #AthAnalysisBaseCompsLib
112 # if you add components (tools, algorithms) to this package
113 # uncomment the next lines
114 # atlas_add_component( %(pkg_name)s src/components/*.cxx
116 # LINK_LIBRARIES %(pkg_name)sLib
119 # if you add an application (exe) to this package
120 # declare it like this (note convention that apps live in util dir)
121 # atlas_add_executable( MyApp util/myApp.cxx
122 # LINK_LIBRARIES %(pkg_name)sLib
125 # Install python modules, joboptions, and share content
126 atlas_install_python_modules( python/*.py )
127 atlas_install_joboptions( share/*.py )
128 atlas_install_data( data/* )
129 # You can access your data from code using path resolver, e.g.
130 # PathResolverFindCalibFile("%(pkg_name)s/file.txt")
133 """%locals()),file=req)
136 with open(os.path.join(pkg_path+
"/"+pkg_name,
'version.cmake'),
'w')
as req:
137 print((
"%s-00-00-01" % pkg_name),file=req)
141 workDir = os.environ.get(
"WorkDir_DIR")
143 print(
"::: ERROR No WorkDir_DIR env var, did you forget to source the setup.sh script?")
144 print(
"::: ERROR Please do this and reconfigure cmake manually!")
146 print(
"::: INFO Reconfiguring cmake %s/../." % workDir)
147 res = subprocess.getstatusoutput(
'cmake %s/../.' % workDir)
149 print (
"::: WARNING reconfigure unsuccessful. Please reconfigure manually!")
152 print (
"::: creating package [%(full_pkg_name)s]... [done]" % locals())